Go Down

Topic: Xbee coordinator with sensor and arduino talking to router with led? (Read 1 time) previous topic - next topic

breegeek

Hi!

I have been going through the Wireless Sensors Network book and have tried taking the "romantic light sensor" chapter and trying to make it work with my project. It's somewhat the reverse of the model illustrated in there, but I borrowed a lot of the code....

What I am trying to do: I have a photoresistor connected to an arduino (analog input 0) with a xbee radio. I want the values from that photoresistor to be sent to the second xbee, which has no microcontroller, to light an LED. Basically, when xbee A sees light, I want xbee B to turn on an LED. Seems simple enough?

Right now, I have the arduino/sensor connected xbee set as a Coordinator in the API mode and the MCU-free xbee/LED set as an AT Router.

It isn't working. Does the sensor need to be the router? Do they both need to be in API mode? Or AT mode? What can I do to make the two xbees talk?
Maybe my code is broken?
Code: [Select]
#define VERSION "1.02"

int LED = 11;
int debugLED = 13;
int analogValue = A0;
int remoteIndicator = false; // keeps track of the desired remote on/off state
int lastRemoteIndicator = false; // record of prior remote state
unsigned long lastSent = 0; // records last time the remote was re-set to keep it in sync

void setup() {
  pinMode(analogValue,INPUT);
  pinMode(debugLED,OUTPUT);
  Serial.begin(9600);
}

void loop() {
      int analogHigh = analogRead(analogValue);
      int analogLow = analogRead(analogValue);
      analogValue =  analogLow + (analogHigh * 256);
 
  if (analogValue > 0 && analogValue <= 50) {
    Serial.print(0x7E, BYTE); // start byte
    Serial.print(0x0, BYTE); // high part of length (always zero)
    Serial.print(0x10, BYTE); // low part of length (the number of bytes that follow, not including checksum)
    Serial.print(0x17, BYTE); // 0x17 is a remote AT command
    Serial.print(0x0, BYTE); // frame id set to zero for no reply
    // ID of recipient, or use 0xFFFF for broadcast
    Serial.print(00, BYTE);
    Serial.print(00, BYTE);
    Serial.print(00, BYTE);
    Serial.print(00, BYTE);
    Serial.print(00, BYTE);
    Serial.print(00, BYTE);
    Serial.print(0xFF, BYTE); // 0xFF for broadcast
    Serial.print(0xFF, BYTE); // 0xFF for broadcast
    // 16 bit of recipient or 0xFFFE if unknown
    Serial.print(0xFF, BYTE);
    Serial.print(0xFE, BYTE);
    Serial.print(0x02, BYTE); // 0x02 to apply changes immediately on remote
    // command name in ASCII characters
    Serial.print('D', BYTE);
    Serial.print('0', BYTE);
    // command data in as many bytes as needed
    Serial.print(4, BYTE);
    // checksum is all bytes after length bytes
    long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '1' + value;
    Serial.print( 0xFF - ( sum & 0xFF) , BYTE ); // calculate the proper checksum
    delay(10); // safety pause to avoid overwhelming the serial port (if this function is not implemented properly)

  }
  if (analogValue > 50) {
    Serial.print(0x7E, BYTE); // start byte
    Serial.print(0x0, BYTE); // high part of length (always zero)
    Serial.print(0x10, BYTE); // low part of length (the number of bytes that follow, not including checksum)
    Serial.print(0x17, BYTE); // 0x17 is a remote AT command
    Serial.print(0x0, BYTE); // frame id set to zero for no reply
    // ID of recipient, or use 0xFFFF for broadcast
    Serial.print(00, BYTE);
    Serial.print(00, BYTE);
    Serial.print(00, BYTE);
    Serial.print(00, BYTE);
    Serial.print(00, BYTE);
    Serial.print(00, BYTE);
    Serial.print(0xFF, BYTE); // 0xFF for broadcast
    Serial.print(0xFF, BYTE); // 0xFF for broadcast
    // 16 bit of recipient or 0xFFFE if unknown
    Serial.print(0xFF, BYTE);
    Serial.print(0xFE, BYTE);
    Serial.print(0x02, BYTE); // 0x02 to apply changes immediately on remote
    // command name in ASCII characters
    Serial.print('D', BYTE);
    Serial.print('0', BYTE);
    // command data in as many bytes as needed
    Serial.print(5, BYTE);
    // checksum is all bytes after length bytes
    long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '1' + value;
    Serial.print( 0xFF - ( sum & 0xFF) , BYTE ); // calculate the proper checksum
    delay(10); // safety pause to avoid overwhelming the serial port (if this function is not implemented properly)

  }
}



Please help, I've been pulling my hair out for days!!!


Pauly

I am going through this book as well.
I currently have a coordinator in API mode and router in AT mode, with a photocell sensor on analog pin 1.
This seems to work ok, however, make sure you have a large enough resistor on the photocell.

I also have a temperature sensor on analog 0 and when I had a smaller resistor, the photocell would saturate when it was dark and change the temperature reading.
Also note, I have been using the XBee library examples, which you don't seem to be.

What exactly is not working?

breegeek

The serial read out in the arduino program shows a constant repetition of "d0 q~". But the router plugged into the USB explorer for example seems to output nothing to xctu terminal for example.

The router doesnt light the led ever. So, nothing seems to be working :(

Oh yeah I have a 10k resistor on the photocell

Pauly

Without seeing how you have the router radio wired or configured, all I can really say is start over.
I would start bey getting the doorbell example working.
I would add the 3 leds to your router for debugging as shown on page 80.

Once the doorbell example works, replace the buzzer with an LED.  When that works, replace the button with the solar cell.

breegeek

The doorbell example needs two arduinos though. My trouble is that I want only one mcu involved and it has to be with the sensor and xbee.

My router right now has only 3 pins going. Pow, grnd, and dout0.
The coordinator is just powered and talking to the arduino.

Any thoughts? Is it an API/at thing? So lost!!!

Thanks in advance

breegeek

NEVERMIND! I GOT IT WORKING!

dunno how, but I programmed and re-programmed the router a couple dozen times with the exact same parameters, and then it worked.

Perhaps it was my arduino code...

Go Up