Question about I2C Communication

Hello everyone.
I wanted to see if someone here knows how to set up I2C to connect to an Arduino.
Right now we’ve been able to write to the Arduino, but we have not found a way to read from it.
If anyone can help us, we’d appreciate it.

In what way is the I2C Read function failing to work for you?

RoboRIO can’t read from the Arduino.
I tried switching between on-board and the MXP pins, but no luck so far

To have a good chance of figuring out what might be wrong, we’ll need a whole lot more information about your system. Tell us what you’re doing, exactly what you expect to happen, and exactly what happens instead. Be as specific and as detailed as possible. Don’t summarize or leave out anything you might not think is important. Better to give us too much than too little.

Seeing your code would help. Seeing a picture of your wiring would be good too.

What we’re trying to do is control a LED strip with an Arduino. The RoboRIO will send the Arduino an RGB value which will then be used to control the LED strip. At certain points controlled by us, the RoboRIO will “ask” the Arduino what it current RGB values are. This last bit is what we’ve been having trouble with, because the Arduino gets the message from the RIO, but when it sends the RGB values back the RIO doesn’t read them. This is the receive code inside LabVIEW:
ImageUploadedByTapatalk1422564178.563284.jpg
Note that we know the current address is 0, that was just for testing purposes.

At the moment I can’t take a picture of the wiring.

ImageUploadedByTapatalk1422564178.563284.jpg


ImageUploadedByTapatalk1422564178.563284.jpg

Would help to see your Arduino code as well.

This is our current Arduino code:



#include 



void setup()

{

  Wire.begin(2); // join i2c bus (address optional for master)

}



byte x = 0;



void loop()

{

  Wire.write(x);              // sends one byte  

  x++;

  delay(500);

}


Where did you get that Arduino code? The examples I have seen for an Arduino I2C “slave” use the Wire.onRequest() method to register an event handler that sends the data.

We took a “Master write” example from the
Arduino website and modified it a bit.
I hadn’t thought about onRequest(). Maybe that’s our mistake?

The roboRIO is the master. You need to use a “slave” example as your guide.

Right, I didn’t think about that before… I’ll test it tomorrow and see what happens. Thanks for your help

Thanks for your help, we got I2C working.

Can you share your LabVIEW write I2c code as well?