IOIO Users,

I want to asking about my SPI code, when program is running, the led on 
board is on, and the graphic is running(   command: *redraw();*   ), but 
seems something wrong about my data SPI ( array: *response_ReadData[3], 
**response_ReadData[4], 
**response_ReadData[5]* on *public void loop()* ) because that array is 
constant value, on my design must be not constant value. Beside that the SS 
pin is high when i check using multimeter,  please check this code:

package com.saaddin.dataacquisition;
> import java.math.BigInteger;
> import java.text.DecimalFormat;
> import java.util.Random;
> import java.util.logging.Logger;
>
> import ioio.lib.api.AnalogInput;
> import ioio.lib.api.DigitalOutput;
> import ioio.lib.api.SpiMaster;
> import ioio.lib.api.SpiMaster.Rate;
> import ioio.lib.api.DigitalInput;
> import ioio.lib.api.DigitalInput.Spec.Mode;
> import ioio.lib.api.exception.ConnectionLostException;
> import ioio.lib.util.AbstractIOIOActivity;
>
> import com.androidplot.xy.BoundaryMode;
> import com.androidplot.xy.LineAndPointFormatter;
> import com.androidplot.xy.XYPlot;
> import com.androidplot.xy.XYStepMode;
> import com.saaddin.dataacquisition.R;
>
> import android.graphics.Color;
> import android.os.Bundle;
> import android.view.View;
> import android.view.Window;
> import android.view.View.OnClickListener;
> import android.widget.SeekBar;
> import android.widget.TextView;


public class MainActivity extends AbstractIOIOActivity implements 
> OnClickListener {
>
>     private final int ANALOG_SENSOR_PIN = 40;
>     
>     static final int misoPin = 35;
>         static final int mosiPin = 36;
>         static final int clkPin =37;
>         int ssPin = 6;
>         int[] ssPins = new int[] { 6 };
>     
>     private TextView mValueTextView;
>     private SeekBar mValueSeekBar;
>     
>     
>     private XYPlot dynamicPlot; 
>     SampleDynamicSeries series1 = new SampleDynamicSeries(50);  
>     Random random = new Random(); 
>     
>     
>     
>     @Override
>     public void onCreate(Bundle savedInstanceState) 
>     {
>         super.onCreate(savedInstanceState);
>         requestWindowFeature(Window.FEATURE_NO_TITLE);
>         setContentView(R.layout.activity_main);
>         findViewById(R.id.dynamicPlot).setOnClickListener(this);
>         setupGraph();        
>         dynamicPlot.redraw();
>         
>         
>         mValueTextView = (TextView) findViewById(R.id.tvValue);
>         mValueSeekBar = (SeekBar) findViewById(R.id.sbValue);
>
>         enableUi(false);
>         
>     }
>
>     class IOIOThread extends AbstractIOIOActivity.IOIOThread /*implements 
> OnClickListener*/
>     {
>         private AnalogInput mInput;
>         
>         /** The on-board LED. */
>         private DigitalOutput led_;
>         private DigitalOutput PDWN_RESET;  

        private DigitalOutput START;            
>         
>         
>        
>         private XYPlot dynamicPlot; 
>         SampleDynamicSeries series1 = new SampleDynamicSeries(50);  
>         Random random = new Random(); 
>         
>       
>         private SpiMaster spi;
>               
>               
>           
>               
>               byte request_SDATAC = (byte)0x11;                    
>               
>               byte write_CONFIG3 = (byte)0x43;                    

              byte jumlah_register_CONFIG3 = (byte)0x00;     
>               byte request_CONFIG3 = (byte)0xC0;                
>               
>               byte write_CONFIG1 = (byte)0x41;                      
>
             byte jumlah_register_CONFIG1 = (byte)0x00;       
>               byte request_CONFIG1 = (byte)0x86;                
>               byte write_CONFIG2 = (byte)0x42;                    
>               byte jumlah_register_CONFIG2 = (byte)0x00;           
>               byte request_CONFIG2_default = (byte)0x00;            

              byte request_CONFIG2_testsignal = (byte)0x10;       
>               byte write_CH1SET = (byte)0x45;                        

              byte jumlah_register_CH1SET = (byte)0x00;         
>               byte request_CH1SET_inputshort = (byte)0x01;    
>               byte request_CH1SET_testsignal = (byte)0x05;    
>               byte request_CH1SET_normalinput = (byte)0x10;               
>               byte request_RDATAC = (byte)0x10;                   
>               
>               byte request_RDATA = (byte)0x12;                    
>               
>               byte request_delay = (byte)0x00;       
>               
>               byte[] request_StopRead = new byte[]{ request_SDATAC, 
> request_delay, request_delay, request_delay, request_delay};    
>               byte[] response_StopRead = new byte[0];    
>               //mensetting internal voltage reference
>               byte[] request_Vref = new byte[]{ write_CONFIG3, 
> jumlah_register_CONFIG3, request_CONFIG3 };    
>               byte[] response_Vref = new byte[0];
>               
>               
>               
>               //high resolution with 500sps
>               byte[] request_HighRes = new byte[]{ write_CONFIG1, 
> jumlah_register_CONFIG1, request_CONFIG1 };    
>               byte[] response_HighRes = new byte[0];
>               //setting default pada config2
>               byte[] request_default_CONFIG2 = new byte[]{ write_CONFIG2, 
> jumlah_register_CONFIG2, request_CONFIG2_default };    
>               byte[] response_default_CONFIG2 = new byte[0];
>               
>               byte[] request_CH1Short = new byte[]{ write_CH1SET, 
> jumlah_register_CH1SET, request_CH1SET_inputshort };    
>               byte[] response_CH1Short = new byte[0];
>                   
>               
>               
>               byte[] request_ReadData = new byte[]{ request_RDATA };    
>               byte[] response_ReadData = new byte[27];
>               
>               byte[] request_TestSignal = new byte[]{ write_CONFIG2, 
> jumlah_register_CONFIG2, request_CONFIG2_testsignal, write_CH1SET, 
> jumlah_register_CH1SET, request_CH1SET_testsignal };    
>               byte[] response_TestSignal = new byte[0];
>               
>           
>               byte[] request_CH1_input_gain1 = new byte[]{ write_CH1SET, 
> jumlah_register_CH1SET, request_CH1SET_normalinput };    
>               byte[] response_CH1_input_gain1 = new byte[0];
>
>         @Override
>         public void setup() throws ConnectionLostException, 
> InterruptedException     
>         {        
>             
>         try {
>             led_ = ioio_.openDigitalOutput(0, false);  
>             
>             PDWN_RESET = ioio_.openDigitalOutput(14, true);       
>              spi = ioio_.openSpiMaster(new DigitalInput.Spec(misoPin,
>                         Mode.PULL_UP), new DigitalOutput.Spec(mosiPin),
>                         new DigitalOutput.Spec(clkPin),
>                         new DigitalOutput.Spec[] { new 
> DigitalOutput.Spec(ssPin) },
>                         new SpiMaster.Config(Rate.RATE_1M, true, true));
>             
>             
>             spi.writeRead( 0, request_StopRead, request_StopRead.length, 
> 5, response_StopRead, response_StopRead.length);    
>             spi.writeRead( 0, request_Vref, request_Vref.length, 3, 
> response_Vref, response_Vref.length);
>             
>             spi.writeRead( 0, request_HighRes, request_HighRes.length, 3, 
> response_HighRes, response_HighRes.length);
>             spi.writeRead( 0, request_default_CONFIG2, 
> request_default_CONFIG2.length, 3, response_default_CONFIG2, 
> response_default_CONFIG2.length);
>             
>             spi.writeRead( 0, request_CH1Short, request_CH1Short.length, 
> 3, response_CH1Short, response_CH1Short.length);  
>             
>             
>             START = ioio_.openDigitalOutput(13, true);
>             
>             spi.writeRead( 0, request_StopRead, request_StopRead.length, 
> 5, response_StopRead, response_StopRead.length);
>             spi.writeRead( 0, request_TestSignal, 
> request_TestSignal.length, 6, response_TestSignal, 
> response_TestSignal.length);
>             
>             
>             
>             mInput = ioio_.openAnalogInput(ANALOG_SENSOR_PIN);
>             enableUi(true);
>             
>             
>             
>             } catch (ConnectionLostException e) {
>                 enableUi(false);
>                 throw e;
>             }
>         }
>
>         @Override
>         public void loop() throws ConnectionLostException 
>         {    
>             
>             try {
>                 
>                 
>             
>                 spi.writeRead( 0, request_ReadData, 
> request_ReadData.length, 28, response_ReadData, response_ReadData.length);
>                 
>                 int datahigh     =     ((int)response_ReadData[3] << 16); 
>    
>                 int datamed     =     ((int)response_ReadData[4] << 
> 8);     
>                 int datalow     =     ((int)response_ReadData[5]);        
>     
>                 int datatot        =   datahigh + datamed + datalow;    
>                      
>                 float ganteng = (float) ((2.4/8388607)*datatot);
>     
>                 
>                 final float reading = mInput.read();
>             
>                 int gantengseekbar = (int) ganteng;
>                 setSeekBar((int) (gantengseekbar));           
>             
>                 setText(Float.toString(ganteng));            
>                 addNumberAndRemoveFirst(ganteng);    
>                 setupGraph();        
>                 redraw();                
>
                sleep(10);
>             } catch (InterruptedException e) {
>                 ioio_.disconnect();
>             } catch (ConnectionLostException e) {
>                 enableUi(false);
>                 throw e;
>             }
>         }
>             
>         
>     }
>
>     @Override
>     protected AbstractIOIOActivity.IOIOThread createIOIOThread() {
>         return new IOIOThread();
>     }
>
>     private void enableUi(final boolean enable) {
>         runOnUiThread(new Runnable() {
>             @Override
>             public void run() {
>                 mValueSeekBar.setEnabled(enable);
>             }
>         });
>     }
>     
>     
>
>     private void setSeekBar(final int value) {
>         runOnUiThread(new Runnable() {
>             @Override
>             public void run() {
>                 mValueSeekBar.setProgress(value);
>             }
>         });
>     }
>
>     private void setText(final String str) {
>         runOnUiThread(new Runnable() {
>             @Override
>             public void run() {
>                 mValueTextView.setText(str);
>             }
>         });
>     }
>     
>     private void addNumberAndRemoveFirst(final float nilai) {
>         runOnUiThread(new Runnable() {
>             @Override
>             public void run() {
>                 series1.addNumberAndRemoveFirst(nilai);
>             }
>         });
>     }
>     
>     private void redraw() {
>         runOnUiThread(new Runnable() {
>             @Override
>             public void run() {
>                 dynamicPlot.redraw();
>             }
>         });
>     }
>     
>
>     private void setupGraph() 
>     {
>         
>         dynamicPlot = (XYPlot) findViewById(R.id.dynamicPlot);
>         // only display whole numbers in domain labels
>         dynamicPlot.getGraphWidget().setDomainValueFormat(new 
> DecimalFormat("0"));
>
>         dynamicPlot.addSeries(series1, new 
> LineAndPointFormatter(Color.rgb(0, 0, 0), null, Color.rgb(0, 80, 0)));
>         // create a series using a formatter with some transparency 
> applied:
>         LineAndPointFormatter f1 = new LineAndPointFormatter(Color.rgb(0, 
> 0,200), null, Color.rgb(0, 0, 80));
>         f1.getFillPaint().setAlpha(220);
>         dynamicPlot.setGridPadding(5, 0, 5, 0);
>
>         dynamicPlot.setDomainStepMode(XYStepMode.SUBDIVIDE);
>         dynamicPlot.setDomainStepValue(series1.size());
>
>         // thin out domain/range tick labels so they don't overlap each 
> other:
>         dynamicPlot.setTicksPerDomainLabel(5);
>         dynamicPlot.setTicksPerRangeLabel(3);
>         dynamicPlot.disableAllMarkup();
>
>         // freeze the range boundaries:
>         dynamicPlot.setRangeBoundaries(-100, 100, BoundaryMode.FIXED);
>         
>     }
>     
>
>     
>     @Override
>     public void onClick(View v) 
>     {
>         Logger.getAnonymousLogger().info("Added one");
>         series1.addNumberAndRemoveFirst(10f * (random.nextFloat() - .5f));
>         dynamicPlot.redraw();
>     }
>
>     
>     
>     
> } 
>

 

 
Thanks

Saaddin
 

-- 
You received this message because you are subscribed to the Google Groups 
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to