Go Down

Topic: Arduino and xbee question? (Read 380 times) previous topic - next topic

Rico_Bravo

My sender Arduino code: mySerialprintln(86);

Receiver Arduino code:

#include <AFSoftSerial.h>

int LEDpin = 5;
byte incomingByte;
char request[5];
AFSoftSerial mySerial = AFSoftSerial(2, 3);

void setup() {
pinMode(LEDpin,OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println("Chip 2 online");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}

void loop() // run over and over again
{
if (mySerial.available()) {
Serial.print((char)mySerial.read());
incomingByte = mySerial.read();
Serial.println(incomingByte);
request[0] = incomingByte;
Serial.print(request[0]);

}

if (Serial.available()) {
mySerial.print((char)Serial.read());
}
delay(50);

if(request[0] == '8')
{
digitalWrite(LEDpin,HIGH);
delay(1000);
digitalWrite(LEDpin,LOW);
}
}

Ok, when I Serial.print(request[0]); it reads 6??? I am loosing the 8 somewhere can someone help little old me???? I would like request[0] to equal 8 and request[1] to equal 6 the values I sent from sender arduino.

Thanks
Rico



mikalhart

Rico,

Your code never stores incoming data anywhere except in request[0].  The only place that the request array is ever changed is in this line:

Code: [Select]
request[0] = incomingByte;

This causes both the '8' and the '6' (and any other incoming bytes) to be stored in request[0] and never request[1].

Mikal

Go Up