Hey everyone. I've been having a problem for a few days now and can't seem to figure out what's going on. My goal is this: a wiichuck will send data to my Arduino Micro and send it over the serial1 port to an Xbee in the following format "x,y,button1,button2" example "123,223,0,0". I can read the data just fine from the serial port. I can read it fine when I plug my second Xbee into my computer and view the data over the serial port. The problem comes up when I plug the second Xbee into my Arduino Uno. I'm trying to use parseInt to read the values sent from the micro. The data is being received and I can assign them to an array, what happens is the data is not in the right place when I print the values to the serial port. Values will shift position when I monitor them from the Uno, like: "0,123,233,0" then "0,0,123,233".
I don't think the issue is that I'm printing to the serial while trying to read from it as well, since when I try to use the values to control motors and remove the serial printing, it don't work correctly. Is there a better way to pass the data over the serial ports than using parseInt? The Xbee's are Series1. Eventually I want to send more data over to the Uno and possibly even send data back and forth between the two.
Data transmiter
#include "Wire.h"
#include "WiiChuck.h"
WiiChuck chuck = WiiChuck();
int x, y, zButton, cButton;
void setup()
{
Serial1.begin(19200);
chuck.begin();
}
void loop()
{
chuck.update();
x = map(chuck.readJoyX(),-100,109,0,255);
y = map(chuck.readJoyY(),-111,102,0,255);
if (x < 0)
{
x = 0;
}
else if(y < 0)
{
y = 0;
}
if (chuck.buttonZ)
{
zButton = 1;
}
else
{
zButton = 0;
}
if (chuck.buttonC)
{
cButton = 1;
}
else
{
cButton = 0;
}
Serial1.print(x);
Serial1.print(",");
Serial1.print(y);
Serial1.print(",");
Serial1.print(zButton);
Serial1.print(",");
Serial1.print(cButton);
Serial1.print(",");
Serial1.println();
}
Receiver
void loop()
{
if (Serial.available())
{
for(fieldIndex = 0; fieldIndex < 4; fieldIndex++)
{
values[fieldIndex] = Serial.parseInt();
}
for(int i=0; i < fieldIndex; i++)
{
Serial.print(values[i]);
Serial.print(", ");
}
}
}