rezcue
March 9, 2021, 4:26pm
#1
Hello guys,
im trying to send data from my arudino to my Router XBeeS2C (API 2).
Sensor->Arduino->XbeeRouter->XbeeCoor
The problem now is that it wont send any data.
Can someone hlpe me out and point out what im doing wrong here?
Pinconnection:
Xbee Tx —> 4
Xbee Rx —>5
The code:
#include <SoftwareSerial.h>
#include <HCSR04.h>
SoftwareSerial mySerial(4,5); // TX, RX
int triggerPin = 13;
int echoPin = 12;
UltraSonicDistanceSensor distanceSensor(triggerPin, echoPin);
void setup () {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop () {
// Every 500 miliseconds, do a measurement using the sensor and print the distance in centimeters.
int distance = distanceSensor.measureDistanceCm();
Serial.println(distance);
int ch = 0x3FB + distance;
byte checksum = ch;
checksum = 0xFF - checksum;
//0013A20041C38580
byte data = {0x7E,0x00,0x0F,0x10,0x01,0x00,0x13,0xA2,0x00,0x41,0xC3,0x85,0x80,0xFF,0xFE,0x00,0x00,distance,checksum};
mySerial.write(data,19);
delay(1000);
}
source → ZigBee based Wireless Sensor Network using XBee S2C Module - YouTube
mikb55
March 9, 2021, 5:28pm
#2
Compare your packet against the same thing generated using the XCTU packet builder.
Why not use Andrew Rapp's library made for S2 in API mode?
rezcue
March 9, 2021, 6:24pm
#3
Im trying out the stuff. I have ZERO exp in this.
But good idea ill it out.
rezcue
March 9, 2021, 9:15pm
#4
Hey.
@mikb55 thank u very much for your help. That idea gave me some hope to work on this.
I change the code to my setup.
#include <SoftwareSerial.h>
#include <HCSR04.h>
SoftwareSerial mySerial(4,2); // TX, RX —> Xbee RX → Ardu Tx (4) | Xbee TX —>Ardu RX
int triggerPin = 13;
int echoPin = 12;
UltraSonicDistanceSensor distanceSensor(triggerPin, echoPin);
void setup () {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop () {
// Every 500 miliseconds, do a measurement using the sensor and print the distance in centimeters.
int distance = distanceSensor.measureDistanceCm();
Serial.println(distance);
int ch = 0x4CC + distance;
byte CS = ch;
CS = 0xFF - CS;
//0013A20041C38580
byte data = {0x7E,0x00,0x0F,0x10,0x01,0x00,0x13,0xA2,0x00,0x41,0xC3,0x85,0x80,0xFF,0xFE,0x00,0x00,distance,CS};
mySerial.write(data,19);
delay(3500);
}
i had to change the calculation of the checksum and my Boudrate on my XBEE was not 9600.
now it works and i get the HEX value to my coor ;).
system
closed
July 7, 2021, 9:16pm
#5
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.