Data transmission via XBee
hi guys,
i want read analog senor datas , send them wirelessly on xbee computer.
my setup:
transmitter:
arduino nano (powerd battery), reads 2 sensors (later want expand 6 sensors), , send them via xbee series 1, baudrate: 57600. transmitter code:
receiver:
arduino mega, reads serial1 (connected xbee) , print values serial monitor. i'm using code found in post paul s in forum. code made receive data 1 sensor. extended 2 sensors. code:
my problem:
the code works fine, if incomming value not higher 999. if 1000 1023, first sensor value displayed correctly, second 1 high...it seems there kind of overflow...
this copy serial monitor:
sensor0 = 874
sensor1 = 879 --> perfect
sensor0 = 1012
sensor1 = 7396 --> wrong
any ideas? there logical mistake in receiving code?
i want read analog senor datas , send them wirelessly on xbee computer.
my setup:
transmitter:
arduino nano (powerd battery), reads 2 sensors (later want expand 6 sensors), , send them via xbee series 1, baudrate: 57600. transmitter code:
code: [select]
void setup() {
serial.begin(57600);
}
void loop() {
int sensor0 = analogread(a0);
int sensor1 = analogread(a1);
serial.print("<");
serial.print(sensor0);
serial.print("/");
serial.print(sensor1);
serial.print(">");
delay(10);
}
receiver:
arduino mega, reads serial1 (connected xbee) , print values serial monitor. i'm using code found in post paul s in forum. code made receive data 1 sensor. extended 2 sensors. code:
code: [select]
void setup() {
serial.begin(57600);
serial1.begin(57600);
}
char indata[2][5];
int zeile;
int spalte;
boolean started = false;
boolean ended = false;
void loop()
{
while(serial1.available() > 0)
{
char achar = serial1.read();
if(achar == '<')
{
started = true;
zeile = 0;
spalte = 0;
indata[spalte][zeile] = '\0';
}
else if(achar == '>')
{
ended = true;
}
else if(started)
{
if(achar != '/')
{
indata[spalte][zeile] = achar;
zeile++;
indata[spalte][zeile] = '\0';
}
if(achar == '/')
{
zeile = 0;
spalte++;
indata[spalte][zeile] = '\0';
}
}
}
if(started && ended)
{
// convert string integer
char spalte0[4] = {indata[0][0], indata[0][1], indata[0][2], indata[0][3]};
unsigned int sensor0 = atoi(spalte0);
char spalte1[4] = {indata[1][0], indata[1][1], indata[1][2], indata[1][3]};
unsigned int sensor1 = atoi(spalte1);
// use value
serial.print("sensor0 = ");
serial.println(sensor0);
serial.print("sensor1 = ");
serial.println(sensor1);
// ready next time
started = false;
ended = false;
zeile = 0;
spalte = 0;
indata[spalte][zeile] = '\0';
}
}
my problem:
the code works fine, if incomming value not higher 999. if 1000 1023, first sensor value displayed correctly, second 1 high...it seems there kind of overflow...
this copy serial monitor:
sensor0 = 874
sensor1 = 879 --> perfect
sensor0 = 1012
sensor1 = 7396 --> wrong
any ideas? there logical mistake in receiving code?
Arduino Forum > Using Arduino > Project Guidance > Data transmission via XBee
arduino
Comments
Post a Comment