My team is working on a project that involves the digital sidecar sending information over I2C to an Arduino Uno (R2, if it matters). 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.
Would this code work? All I need to do is have the Arduino receive one byte of information at a time. I want the Arduino configured as master and the sidecar configured as slave.
Code:
#include <Wire.h>//I2C library for Arduino
int d = 999; //arbitrary int used for state change stuff
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
delay(1000);
}
void loop() {
Wire.requestFrom(1, 1); //Request data from slave device (the sidecar)
while(Wire.available()) {
int dat = Wire.read();
if (dat == 0) {
if (d != 0) {
//runs once every time state changes to 0
d = 0;
}
//runs repeatedly while state is 0
}
if (dat == 1) {
if (d != 1) {
//runs once every time state changes to 1
d = 1;
}
//runs repeatedly while state is 1
}
if (dat == 2) {
if (d != 2) {
//runs once every time state changes to 2
d = 2;
}
//runs repeatedly while state is 2
}
if (dat == 3) {
if (d != 3) {
//runs once every time state changes to 2
d = 3;
}
//runs repeatedly while state is 2
}
}
}