I'm not familiar enough with the Arduino library to be sure, but the fact that you're writing from both handlers is probably wrong. Apparently, you're receive handler should Wire.read() as many bytes as the argument specifies, and you should do writes only from the request handler. Also, how are you formatting your output when writing?
There's no problem to have a receive-only transaction on the IOIO side, just specify null, 0 as the write buffer. Some tips on debugging: 1. Try to get your hands on a logic analyzer or oscilloscope. This will aid in debugging a lot because you'd be able to tell which side of the wire (IOIO / Arduino) is not behaving as you expect. 2. Since you control both ends of the wire, why did you choose I2C? You might as well use a unidirectional serial link (UART), where the Arduino just periodically publishes the readings for the IOIO to read. On Sat, Aug 1, 2015 at 4:29 PM, Lo <[email protected]> wrote: > 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. > -- 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.
