Int w = 0 //arbitrary integer used in debug sequence. Int d = 999 //arbitrary integer used in debug sequence. Int i = 0 //arbitrary integer used in the pattern generation. Public static byte dataReceived] = //arrays make everything better If you have (find) any errors, let me know and I will try to fix them. Omitting a ground wire between the two will cause the communication to fail. Finally, you need to have at least 3 wires between the cRIO and the Arduino for the Clock, Data, and Ground. The Arduino code, however, is a complete sketch and “should” work out of the box.
It only has pieces that can be added into your own code and prints out error messages if the communication fails. Finally, the Arduino code uses an I2C address of 2, while the cRIO uses an address of 4. ‘C’ and Labview users shouldn’t see this problem. The next version of WPILib will correct this. This is due to how the library combines the “bytes” into "int"s prior to sending and JAVA interprets all bytes as signed. Second, there is a bug in the JAVA version of the I2C library that could corrupt data sent to the Arduino if any of the bytes are greater than 127. This method of splitting the write and read into two parts should always work. There is a fix for this, but I have not had the chance to test it out. This is because there is a bug in the Arduino wire library that sends a “STOP” after the first part of the transaction even though it is setup as a SLAVE. A couple of items to note… A write/read transaction is never performed in the same function call. This sample includes both a read and a write example with the Arduino code handling both. Hopefully not so severe that you can’t make it work relatively easily. There shouldn’t be any syntax errors, but by extracting and making a sample program, I may have introduced some other problem. First off, while the format is similar to what we use on the robot, I can not test this out to ensure there are no errors as I do not have the hardware available. Sorry for it being a little longer than I intended. OK, here is some sample code that should allow you to communicate between an Arduino and the cRIO. runs once every time state changes to 2 runs once every time state changes to 1 runs once every time state changes to 0 Wire.requestFrom(1, 1) //Request data from slave device (the sidecar) Wire.begin() // join i2c bus (address optional for master) Int d = 999 //arbitrary int used for state change stuff I want the Arduino configured as master and the sidecar configured as slave. Would this code work? All I need to do is have the Arduino receive one byte of information at a time. Is this possible, and how can it be done? I know nothing of LabView (which is what my team uses to program the robot) but I know quite a bit of arduino C. My team is working on a project that involves the digital sidecar sending information over I2C to an Arduino Uno (R2, if it matters).