Home/Support/Support Forum/not getting feedback light on "Romantic Light sensor project

not getting feedback light on "Romantic Light sensor project

0 votes
I'm a newbie at xbee radios and learning from a book called "Wireless Sensor Networks" by Robert Faludi. In that book one of the projects is called "Romantic Light Sensor with feedback". I've was able to get the project to turn on the light at the coordinator end on the arduino but can't seem to get the feedback light to work on the remote. I have not been able to find anyway to troubleshoot whether the remote module is getting the right signal back from the coordinator and therefore am stuck. I don't want to proceed further in that book until I can figure out how to determine whether the remote unit is getting the proper signal. I have programmed the Router (remote zigbee) twice to double check that it was getting the proper settings to begin with and apparently it is since the AD1 pin is low when it fires up. I'd appreciate any help on this. Thanks

I'm pasting the code that I'm running below:

/*
* *********ROMANCE LIGHT SENSOR WITH FEEDBACK********
* detects whether your lighting is
* setting the right mood and shows
* you the results on the sensor module
* USES PREVIOUSLY PAIRED XBEE ZB RADIOS
* by Rob Faludi http://faludi.com
*/

/*
*** CONFIGURATION ***

SENDER: (REMOTE SENSOR RADIO)
ATID3456 (PAN ID)
ATDH -> set to SH of partner radio
ATDL -> set to SL of partner radio
ATJV1 -> rejoin with coordinator on startup
ATD02 pin 0 in analog in mode with a photo resistor (don’t forget the voltage divider circuit–resistor to ground is good)
ATD14 pin 1 in digital output (default low) mode with an LED from that pin to ground
ATIR64 sample rate 100 millisecs (hex 64)

* THE LOCAL RADIO _MUST_ BE IN API MODE *

RECEIVER: (LOCAL RADIO)
ATID3456 (PAN ID)
ATDH -> set to SH of partner radio
ATDL -> set to SL of partner radio

*/

#define VERSION “1.01″

int LED = 11;
int analogValue = 0;
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(LED,OUTPUT);
Serial.begin(9600);
}

void loop() {
// make sure everything we need is in the buffer
if (Serial.available() >= 23) {
// look for the start byte
if (Serial.read() == 0x7E) {
// read the variables that we’re not using out of the buffer
// (includes two more for the digital pin report)
for (int i = 0; i<20; i++) {
byte discard = Serial.read();
}
int analogHigh = Serial.read();
int analogLow = Serial.read();
analogValue = analogLow + (analogHigh * 256);
}
}

// darkness is too creepy for romance
if (analogValue > 0 && analogValue <= 350) {
digitalWrite(LED, LOW);
remoteIndicator = false;
}
// medium light is the perfect mood for romance
if (analogValue > 350 && analogValue <= 750) {
digitalWrite(LED, HIGH);
remoteIndicator = true;
}
// bright light kills the romantic mood
if (analogValue > 750 && analogValue <= 1023) {
digitalWrite(LED, LOW);
remoteIndicator = false;
}

// set the indicator immediately when there’s a state change
if (remoteIndicator != lastRemoteIndicator) {
if (remoteIndicator==false) setRemoteState(0x4);
if (remoteIndicator==true) setRemoteState(0x5);
lastRemoteIndicator = remoteIndicator;
}

// re-set the indicator occasionally in case it’s out of sync
//if (millis() – lastSent > 10000 ) {
if (millis() - lastSent > 10000 ) {
if (remoteIndicator==false) setRemoteState(0x4);
if (remoteIndicator==true) setRemoteState(0x5);
lastSent = millis();
}

}

void setRemoteState(int value) { // pass either a 0×4 or and 0×5 to turn the pin on or off
//Serial.print(0x7E, BYTE); // start byte
Serial.write((byte)0x7E); // start byte // same as above but retype manually, copying code may have cause issues
//Serial.print(0x0, BYTE); // high part of length (always zero)
Serial.write((byte)0x0); // high part of length (always zero)
//Serial.print(0x10, BYTE); // low part of length (the number of bytes that follow, not including checksum)
Serial.write((byte)0x10);
//Serial.print(0x17, BYTE); // 0×17 is a remote AT command
Serial.write((byte)0x17);
//Serial.print(0x0, BYTE); // frame id set to zero for no reply
Serial.write((byte)0x0);

// ID of recipient, or use 0xFFFF for broadcast
//Serial.print(00, BYTE); //ORIG code that errored out when compiling
Serial.write((byte)00);
Serial.write((byte)00);
Serial.write((byte)00);
Serial.write((byte)00);
Serial.write((byte)00);
Serial.write((byte)00);
Serial.write((byte)0xFF); // 0xFF for broadcast
Serial.write((byte)0xFF); // 0xFF for broadcast
// 16 bit of recipient or 0xFFFE if unknown
Serial.write((byte)0xFF);
Serial.write((byte)0xFF);
Serial.write((byte)0x02);// 0×02 to apply changes immediately on remote
// command name in ASCII characters
//Serial.print('D', BYTE);
//Serial.print('1', BYTE);
Serial.write((byte)'D');
Serial.write((byte)'1');
// command data in as many bytes as needed
//Serial.print(value, BYTE);
Serial.write((byte)value);
// checksum is all bytes after length bytes
long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '1' + value;
//Serial.write
//Serial.print(0xFF - (sum & 0xFF), BYTE ); // calculate the proper checksum
Serial.write(0xFF - (byte)(sum & 0xFF));
delay(10); // safety pause to avoid overwhelming the serial port (if this function is not implemented properly)

}
asked Jan 18, 2016 in RF Solutions and XBee by clfdigi New to the Community (2 points)

Please log in or register to answer this question.

2 Answers

0 votes
Have you tried checking on Rob's web site for the answer?
answered Jan 20, 2016 by mvut Veteran of the Digi Community (11,302 points)
0 votes
I have searched his site as well as digi and just plain googled it and was not able to find an answer to either how to see how I could monitor what is being sent to remote or what is being received at remote. Maybe that's not possible, Maybe I don't know enough about the zigbee API to ask the right question(s). I did find, during some research, that the arduino code given in the book would not compile until I Modified the lines of code that had Serial.print to a Serial.write in them.
e.g. a "//Serial.print(00, BYTE);" to a "Serial.write((byte)00);". Maybe that was some difference in arduino IDE that changed since the book was written but that same code showed up on most of the research I was finding except one I ran across with the answer for that issue. I was wondering if that could that be part of the problem?
answered Jan 21, 2016 by clfdigi New to the Community (2 points)
I don't know.  What I would suggest is checking with the Author or with Arduino direct.

Otherwise I would take a step back and just work with the radios direct in transparent mode sending data. Then adjust one to API mode leaving the other in transparent mode so you can see the interactions between the two.
Sorry, I haven't been able to work on project for awhile but your suggestion of checking with the author is a good one. I didn't even think that the author might be reachable but I see he has a website especially since this book was written in 2011. He should be able to explain the difference in the code as well as hopefully why the modified code is not working.    I'll see if I can make contact.  thanks.
...