Pages: [1]   Go Down
Author Topic: Arduino and xbee question?  (Read 323 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

Austin, TX USA
Offline Offline
God Member
*****
Karma: 4
Posts: 997
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

Pages: [1]   Go Up
Jump to: