Hi everyone!
I am trying to send data over an xbee using the softwareserial library, but it doesn't seem to be working properly.
have an arduino uno connected to some temperature/pressure sensors, and this same arduino is also connected to an Xbee (series 1). This collects data that it then transmits every 5 seconds.
On the receiving end, I have a PC connected to another arduino uno, which is also connected to an Xbee (series 1).
Firstly, I know that both xbees are configured correctly and that they are talking to each other correctly (all the tests went well). I think my issue is with the sketch I am loading on the receiving end, and hence, my posting and humble request for help
When I connect the xbee to the regular rx(0) and tx(1) ports in the arduino and I use this sketch (lets call it sketch #1), I get the correct data in the serial output:
4/12/2013 1:11:14 unix_time: 1365729074 Humidity1_%: NA Temp1_C: NA Temp2_C: NA Atm_Press1_mbars: NA Light_level: NA Humidity2_%: 56.30 Temp3_C: 29.00 Temp4_C: 31.02 Atm_Press2_mbars: 1012.48
4/12/2013 1:11:19 unix_time: 1365729079 Humidity1_%: NA Temp1_C: NA Temp2_C: NA Atm_Press1_mbars: NA Light_level: NA Humidity2_%: 56.30 Temp3_C: 29.00 Temp4_C: 31.01 Atm_Press2_mbars: 1012.50
4/12/2013 1:11:25 unix_time: 1365729085 Humidity1_%: NA Temp1_C: NA Temp2_C: NA Atm_Press1_mbars: NA Light_level: NA Humidity2_%: 56.30 Temp3_C: 29.00 Temp4_C: 30.96 Atm_Press2_mbars: 1012.41
etc etc.
/*
Simple arduino code to receive data via xbee
*/
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
Serial.write(incomingByte);
Serial.print("");
}
}
However... when I connect the xbee to virtual ports using SoftwareSerial (digital pins 2 and 3 in the arduino) and I use this sketch (lets call it sketch #2), the serial output I get is not correct towards the end of each line:
4/12/2013 1:14:8 unix_time: 1365729248 Humidity1_%: NA Temp1_C: NA Temp2_C: NA Atm_Press1_mbars: NA Light_level: NA Humidity2_%: 56.30 Temp3_C: 29.00 Temp4_C: 31.24AmPes_br:11.1
4/12/2013 1:14:14 unix_time: 1365729254 Humidity1_%: NA Temp1_C: NA Temp2_C: NA Atm_Press1_mbars: NA Light_level: NA Humidity2_%: 56.30 Temp3_C: 29.00 Temp4_C: 31.26AmPes_br:11.6
4/12/2013 1:14:20 unix_time: 1365729260 Humidity1_%: NA Temp1_C: NA Temp2_C: NA Atm_Press1_mbars: NA Light_level: NA Humidity2_%: 56.30 Temp3_C: 29.00 Temp4_C: 31.26AmPes_br:11.5
etc etc...
/*
arduino code using softwareserial to receive data via xbee
*/
#include <SoftwareSerial.h>
SoftwareSerial portOne(2, 3); // RX, TX
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
portOne.begin(9600);
}
void loop() {
// see if there's incoming serial data:
if (portOne.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = portOne.read();
Serial.write(incomingByte);
Serial.print("");
}
}
Does anyone know what the issue could be? How come it works well when I use the standard 0/1 pins, but not well when I use the 2/3 pins?
Any thoughts would be super appreciated...
Thanks!!