I have 2 series 2 XB24-ZB XBee radios with one set in AT mode as a router and one in API mode as a coordinator connected to an Uno and an LCD screen. I am also using the XBee library and modifying one of the examples.
The router is sending analog data from pins 0 & 1 and this seems to work fine four or five times, then I start getting error 3 and sometimes error 1. Sometimes at this point I still get a valid reading, but mostly once I get an error, I only then get errors. Resetting my Arduino makes it work fine again, until I get an error.
I had the router in sleep mode, but thinking the 2 radios were getting out of sync I disabled sleep mode.
I still get the errors. How do I know what error 1 and error 3 are and what should I look at to correct this?
Thanks.
/**
* Copyright (c) 2009 Andrew Rapp. All rights reserved.
*
* This file is part of XBee-Arduino.
*
* XBee-Arduino is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XBee-Arduino is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBee-Arduino. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LiquidCrystal.h>
#include <XBee.h>
const int sensorMin = 0;
const int sensorMax = 1023;
int farenheit=0;
int x=0;
/*
This example is for Series 2 (ZigBee) XBee Radios only
Receives I/O samples from a remote radio.
The remote radio must have IR > 0 and at least one digital or analog input enabled.
The XBee coordinator should be connected to the Arduino.
*/
XBee xbee = XBee();
ZBRxIoSampleResponse ioSample = ZBRxIoSampleResponse();
XBeeAddress64 test = XBeeAddress64();
String sun = "Cloudy";
int humid=0;
int z=0;
int y=0;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte newChar[8] = {
B00000,
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000
};
void setup() {
xbee.begin(9600);
lcd.begin(20, 4);
lcd.createChar(0, newChar);
int data=0;
home();
}
void loop() {
xbee.readPacket();
if (y==0)
{
lcd.setCursor(0,0);
lcd.print("Reading data");
}
readPack();
if (xbee.getResponse().isAvailable()) {
gotPack();
if (xbee.getResponse().getApiId() == ZB_IO_SAMPLE_RESPONSE) {
xbee.getResponse().getZBRxIoSampleResponse(ioSample);
//lcd.clear();
if (ioSample.containsAnalog()) {
for (int i = 0; i <= 4; i++) {
// print something
}
}
calcTemp();
calcSun();
calcHumid();
showData();
delay(2000);
}
else {
lcd.clear();
lcd.setCursor(0, 0 );
lcd.print("Expected I/O Sample");
lcd.setCursor(0, 1 );
lcd.print(", but got ");
lcd.print(xbee.getResponse().getApiId(), DEC);
delay(1000);
}
}
else if (xbee.getResponse().isError()) {
gotError();
}
}
void calcTemp()
{
float temperatureCelsius = (ioSample.getAnalog(0)/1023.0*1.2*3.0*100)-273.15;
round(temperatureCelsius);
farenheit =( temperatureCelsius* 9/5 + 32);
}
void calcSun(){
int range = map(ioSample.getAnalog(1), sensorMin, sensorMax, 0, 5);
switch (range) {
case 0:
sun = "Very Sunny ";
break;
case 1:
sun = "Sunny ";
break;
case 2:
sun = "Partly sunny ";
break;
case 3:
sun = "Partly cloudy";
break;
case 4:
sun = "Cloudy ";
break;
case 5:
sun = "Night time ";
break;
}
}
void calcHumid()
{
//humid = (ioSample.getAnalog(3))
}
void showData(){
// lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp: " );
lcd.print(farenheit);
lcd.write(0);
lcd.print(" F " );
lcd.setCursor(0, 1);
lcd.print("Sunlight lvl: " );
lcd.print(ioSample.getAnalog(1));
lcd.setCursor(0, 2);
lcd.print(sun);
lcd.setCursor(0, 3);
lcd.print("Humidity: " );
lcd.print(humid);
lcd.print("%" );
delay(3000);
/*
lcd.clear();
lcd.print("Wind: " );
lcd.print(wind);
lcd.setCursor(0, 1);
lcd.print("Rain: " );
lcd.print(rain);
delay(2500);
*/
}
void home(){
lcd.clear();
lcd.print("Weather Station Bot");
lcd.setCursor(0, 1);
lcd.print("Arduino & Xbee");
lcd.setCursor(0, 2);
lcd.print("Powered Weather");
lcd.setCursor(0, 3);
lcd.print("Station 2011");
delay(3000);
lcd.clear();
}
void readPack(){
for (int i=0; i < 3; i++)
{
x=17+i;
lcd.setCursor(x, 0);
lcd.print("-");
delay(200);
}
delay(100);
for (int i=0; i < 3; i++)
{
x=19-i;
lcd.setCursor(x, 0);
lcd.print(" ");
delay(200);
}
delay(100);
for (int i=0; i < 3; i++)
{
x=17+i;
lcd.setCursor(x, 0);
lcd.print("-");
delay(200);
}
}
void gotPack(){
lcd.setCursor(19, 0);
lcd.print("+");
y=1;
lcd.setCursor(18, 0);
lcd.print(" ");
delay(200);
lcd.setCursor(17, 0);
lcd.print(" ");
delay(100);
}
void gotError(){
lcd.setCursor(18, 0);
lcd.print(xbee.getResponse().getErrorCode(), DEC);
lcd.print("!");
lcd.setCursor(17, 0);
lcd.print(" ");
delay(700);
}