Hi ioio users, Ytai ,...need your science again ; )

I've not found some precise info about this kind of topic...So I create new 
one.
I'm trying to understand the way of doing TWI between ioio and arduino uno.

I use an arduino as a slave for driving 2 sensors.

>From these two sensors, I've get 2 vars 
float *voltage_value*
unsigned long *lowpulseoccupancy*;
And I simply need to get those values back on my android program.


So, in the ioio android program :

In the setup(), I need to declare the twi master  

        twi = ioio_.openTwiMaster(1, TwiMaster.Rate.RATE_100KHz, false);

The "1" means that  I'm using the SDA1 (pin1) and SCL1(pin2).
The rate means the bit rate of exchange... I think for arduino it doesn't 
matter.
The false, for use the standard voltage 3.3V
 
Then in the loop I need to use it with first declare a request and response 
as byte[]
I don't know if I cannot use the request parameter and replace it by 
null...cause I don't need to send something but just retrieve data. Right ?

            request = new byte[] { 0x01 };    ??? I don't know the mean of 
creating a byte array in request...
            response = new byte[8];
            if (twi.writeRead(arduino_id, false, request, request.length, 
response, response.length)) {
                for (int i = 0; i < 8; i++) {
                    System.out.println(response[i]);
                }
            }

I've connected the ioio SDA1 and SCL1 to arduino pins near aref pin.
Normally these arduino pins are the dedicated ones for arduino layout R3.

And I do not forget to add pull up resistors to 3.3Vcc


Into the arduino program : (with importing the Wire library )

void setup(){
  Serial.begin(9600);
  Wire.begin(123);                            // arduino_id = 123 and means 
that its a slave in the twi protocol.
  Wire.onRequest(requestEvent);    // register event fct
  Wire.onReceive(receiveEvent);
}

void receiveEvent(int i)
{
  Serial.println("RECEIVE !!!");
  Wire.write( the float or long I need )    //voltage_value 
and lowpulseoccupancy
}

or

void requestEvent()
{
  Serial.println("REQUEST !!!");
  Wire.write( the float or long I need )      //voltage_value 
and lowpulseoccupancy
}

I've added the two function event to see what's happening in serial 
monitor...
Cause, normally, I suppose that at each new request from the ioio twi and 
using the right arduino slave address,
the arduino will launch one of these event function...But for now...nothing 
is printed. Grrr..
I suppose the onRequest will be handled cause I don't pass any parameter 
with twimaster. But I'm not sure.

Also I don't know if the arduino_id address is in a correct format...
I've seen some web forums mentioning either   Wire.begin( in hexadecimal ) 
 or  Wire.begin (integer format )

So...for a beginner ...Twi is not really easy... 
If you could enlightened my mind of how to use twi correctly with ioio and 
arduino...

Or give me a tutorial somewhere...cause I didn't find precise examples of 
this...

Thanks for help again.
Lo.





-- 
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