I've been trying to get my XBEEs to communicate with each other and nothing seems to be going right.
I've tried several tutorials and videos but I think i'm doing something wrong.
I have:
2- XBee Series 1 1mw
1 - Arduino Mega 1280
1 - analog temp sensor
I'm trying to read a temp sensor through DI0 and send the info to my base station which is the arduino and another xbee. They are connected through TX/RX.
I've changed the PANID, MY, DL, all to match. I set DI0 to ADC and connected VRef, GND, +Vcc
This is the output that I'm getting through the serial monitor
7E 00 0A 83 00 00 38 00 01 02 00 03 F6 48
Temp: 0
7E 00 0A 83 00 00 38 00 01 00 00 00 00 43
Temp: 0
7E 00 0A 83 00 00 38 00 01 00 00 00 00 43
Temp: 0
7E 00 0A 83 00 00 38 00 01 00 00 00 00 43
Temp: 0
7E 00 0A 83 00 00 38 00 01 00 00 00 00 43
Temp: 0
7E 00 0A 83 00 00 38 00 01 00 00 00 00 43
Temp: 0
7E 00 0A 83 00 00 38 00 01 00 00 00 00 43
Temp: 0
7E 00 0A 83 00 00 38 00 01 00 00 00 00 43
Temp: 0
Nothing seems to change when i introduce hot or cold air.
// Wireless Temp Sensor Project
// http://nootropicdesign.com/projectlab/2009/11/01/wireless-temperature-sensor/
// SRG - deleted the code that displays the temp on LCD display
// ilium007 - modified code to support TMP36 10mV/degree Celsius sensor with 500mv zero degree offset value.
#define NUM_DIGITAL_SAMPLES 12
#define NUM_ANALOG_SAMPLES 4
int tempC; //Temp in C
int packet[32];
int digitalSamples[NUM_DIGITAL_SAMPLES];
int analogSamples[NUM_ANALOG_SAMPLES];
void setup()
{
Serial.begin(9600);
}
void loop() {
readPacket();
}
void readPacket() {
if (Serial.available() > 0) {
int b = Serial.read();
if (b == 0x7E) {
packet[0] = b;
packet[1] = readByte();
packet[2] = readByte();
int dataLength = (packet[1] << 8) | packet[2];
for(int i=1;i<=dataLength;i++) {
packet[2+i] = readByte();
}
int apiID = packet[3];
packet[3+dataLength] = readByte(); // checksum
printPacket(dataLength+4);
if (apiID == 0x92) {
int analogSampleIndex = 19;
int digitalChannelMask = (packet[16] << 8) | packet[17];
if (digitalChannelMask > 0) {
int d = (packet[19] << 8) | packet[20];
for(int i=0;i < NUM_DIGITAL_SAMPLES;i++) {
digitalSamples[i] = ((d >> i) & 1);
}
analogSampleIndex = 21;
}
int analogChannelMask = packet[18];
for(int i=0;i<4;i++) {
if ((analogChannelMask >> i) & 1) {
analogSamples[i] = (packet[analogSampleIndex] << 8) | packet[analogSampleIndex+1];
analogSampleIndex += 2;
} else {
analogSamples[i] = -1;
}
}
}
}
int reading = analogSamples[1]; // pin 19 [0] is pin 20
// convert reading to millivolts
float v = ((float)reading / 1023.0) * 1200.0;
// convert to Celcius. 10mv per Celcius degree with 500mV offset at 0 celcius
float c = (v - 500.0) / 10.0;
// round to nearest int
tempC = (int)(c + 0.5);
Serial.print("Temp: ");
Serial.println(tempC);
}
}
void printPacket(int l) {
for(int i=0;i < l;i++) {
if (packet[i] < 0xF) {
// print leading zero for single digit values
Serial.print(0);
}
Serial.print(packet[i], HEX);
Serial.print(" ");
}
Serial.println("");
}
int readByte() {
while (true) {
if (Serial.available() > 0) {
return Serial.read();
}
}
}
I know the code works because someone else is using it. I think my problems are coming from the settings on the Xbees.
Help?