Hi
I'm new to Arduino and I hace an issue with serial read.
I have a PC program (boblight) that sends to Arduino via a serial port {R,G,B} hex values. Portmon shows the following data being sent to Arduino (every second it sends three bytes):
Second 1: 00 EC 2A
Second 2: EB 12 0F
Second 3: FD 01 0D
Second 4: 14 8A EC
I wrote a program in Arduino to get the above {R,G,B} values and process them.
Essentially the Arduino program is
unsigned char RGB[3];
void setup() {
// Init serial communications
}
void loop()
{
if (Serial.available() >= 3) {
for (int i = 0; i < 3; ++i)
{ RGB[i] = Serial.read(); }
// Do something with RGB[0], RGB[1], RGB[2]
}
}
So I hope that RGB[0], RGB[1] and RGB[2] store the integer values sent from the PC in the same sent order.
But what I really seem to get is that the order of the received bytes is misplaced. For example, when the PC sends {EB, 12, 0F}, the above Arduino program gets {0F, EB, 12}.
Obviously I can teak the indexes and make it work as expected, but I can't understand why RGB[0], RGB[1] and RGB[2] have wrong values.
Any ideas why this is happening?
Toni