I am working on a project intended to send 3 bits of data to control an RGB LED wirelessly over XBee.
Due to my application, I do need the transmitting Xbee to be an API to make sure the data is correct on the end points. Thus I need to send a 16bit address frame to it .
In XCTU I can create a frame using the tool. I can also copy and paste that frame into arduino, and then send that frame across. And my Xbee end node receiver works great. This is all well and good if the same value was sent. But it is not. Bit 9,10 and 11 will change depending on the value that gets set it’s way. And thus, the Checksum will need to change to do it’s job.
My question is about the calculations on the Checksum. I have been googling/binging/yahoo searching for the past week now, and have yet to find any solid answer on how to calculate a checksum in simple words.
Can you assist, or direct me into some explanation on how to calculate a checksum? It seams simple, but I can’t seam to understand or grasp what is going on in the complex examples.
Sourced from this forum post:
http://forum.arduino.cc/index.php?topic=119463.0
*/
#include <SoftwareSerial.h>
SoftwareSerial XBee(2, 3); // RX, TX
// needs to be a 0x00 number. use Find/Replace. replace space with ", 0x"
byte hello[] = {0x7e, 0x00, 0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0xe3}; // Broadcasts to all
byte first[] = {0x7E, 0x00, 0x08, 0x01, 0x03, 0xFF, 0xFF, 0x00, 0x37, 0x38, 0x39, 0x55};
byte frameOne[] = {0x7E, 0x00, 0x0D, 0x01, 0x01, 0xFF, 0xFF, 0x00, 0x2D, 0x46, 0x72, 0x61, 0x6D, 0x65, 0x30, 0x30, 0x87};
int Xbee_loop_count;
void setup()
{
Serial.begin(9600);
XBee.begin(19200);
}
void loop() {
Xbee_loop_count++;
//after various trials serial.print(Router_on,20); kept causing the overloaded ambiguous error
//Serial.write(Router_on,20); does it with no problems
//the 20 tells the compiler how long the array is
//Thank you PaulS from the Arduino forum for helping with this
XBee.write(hello, 20);
XBee.write(frameOne, 17);
XBee.write(first,12);
XBee.write(first,12);
delay(1);
//Serial.println(Xbee_loop_count);
}
/*
Send 16 bit data.
Would look like this:
012 = 7E 00 08 01 01 FF FF 00 30 31 32 6C
345 = 7E 00 08 01 02 FF FF 00 33 34 35 63
789 = 7E 00 08 01 03 FF FF 00 37 38 39 55
Byte 1 = Start
Byte 2 = Most significant bit (always 00)
Byte 3 = Least significant bit = Count of bits after this bit. (LSB). Aka. Bytes 4 through 12 = 8 bits = 0x08.
Byte 4 = Type of Request. 0x00 = 64bit Tx. 0x01 = 16bit Tx // See XCTU's Frame Builder. Frame Type drop down for list.
Byte 5 = Frame ID // Transmit Unit doesn't really care. But if your receiver wants to receive data asynchronous. (say read 5 before 2, after 3) Then you would use this ID.
Byte 6 = Address MSB (FF = broadcast)
Byte 7 = Address LSB (FF = Broadcast)
Byte 8 = option
Byte 9, 10, 11 = Data
Byte 12 = Checksum
*/
Examples of data that would be sent out:
Purple value = 990099 = 7E 00 0B 01 01 FF FF 00 39 39 30 30 39 39 BB
Haft red = 550000 = 7E 00 0B 01 01 FF FF 00 35 35 30 30 30 30 D5
Green value = 009900 = 7E 00 0B 01 01 FF FF 00 30 30 39 39 30 30 CD