I have an XBEE S1 connection set up and running this code on my arduino:
#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX
SoftwareSerial CO2(5,6);
void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
XBee.begin(9600);
CO2.begin(9600);
}
void loop()
{
CO2.println("%");
delay(50);
if (CO2.available())
{
char newChar = CO2.read();
XBee.write(newChar);
}
}
It runs great for the first few transmissions of the command % but then does this:
% 020.15
% 020.15
% 020.15
% 020.15
% 020.15
% 020.15
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[/code
If I remove the delay I just get junk characters, if I increase it I still get the same error of just getting %%%%%%. How can I make it send a command, receive the answer and display it?
if form a D Pin - your CO2 reader is spec-ed for 33mA, top max limit for a pin on your adruino is 40mA and you should try to never get too close... Would suggest to power separately your CO2 reader (also the doc mentions Startup inrush current 50 mS @ 60 mA peaks --> that's quite a draw as well for your arduino)
same for your Xbee by the way, if I remember they can draw 50mA @ 3.3v.. too much for an arduino D pin
Otherwise your CO2 reader has 2Hz measurement interval, so you should poll it only every 500ms max - may be that's the pb
J-M-L:
Is that from a Digital pin or the power pin?
if form a D Pin - your CO2 reader is spec-ed for 33mA, top max limit for a pin on your adruino is 40mA and you should try to never get too close... Would suggest to power separately your CO2 reader (also the doc mentions Startup inrush current 50 mS @ 60 mA peaks --> that's quite a draw as well for your arduino)
same for your Xbee by the way, if I remember they can draw 50mA @ 3.3v.. too much for an arduino D pin
Otherwise your CO2 reader has 2Hz measurement interval, so you should poll it only every 500ms max - may be that's the pb
The power pin, the one next to the 5v and grounds on the analog side of the arduino board.
It has a 20Hz measurement sorry I linked the wrong one: