i have 2 arduino one coordinator in API and one router in Api. watching the serial screen of the router appear strange characters when the code reachs the xbee.send() method
Could anyone tell me why are these characters appear?
Here is the source code of the router:
const int dimout=11;
const int ldr=A0;
const int relay=4;
float sensorValue=0,pwmValue1=0,pwmValue2=0;
float Volt,Lux,Difference;
float VDifference,d=2;
uint8_t SData[4];
XBee xbee=XBee();
XBeeResponse response=XBeeResponse();
ZBRxResponse zbRx=ZBRxResponse();
XBeeAddress64 rmtAddress=XBeeAddress64(0x0013a200,0x040b33b0c);
ZBTxRequest zbTx=ZBTxRequest(rmtAddress,SData,sizeof(SData));
int state=1;
long previousTime=0;
unsigned long start=0;
long timeStep=180000;// 15 lepta
long interval=2000*60*60;//2 wres
union{
float f;
byte b[4];
}command,LuxValue;
void setup(){
Serial.begin(9600);
xbee.setSerial(Serial);
pinMode(dimout,OUTPUT);
pinMode(relay,OUTPUT);
pinMode(ldr,INPUT);
}
void loop(){
if(xbee.readPacket(5000))
{
if(xbee.getResponse().getApiId()==ZB_RX_RESPONSE){
xbee.getResponse().getZBRxResponse(zbRx);
Serial.println("I received an RX packet");
if (zbRx.getOption() == ZB_PACKET_ACKNOWLEDGED){
Serial.println("Packet acknowledged");
}
else{
Serial.println("Packet not acknowledged");
}
Serial.println("The received Data length is");
Serial.println(zbRx.getDataLength(),DEC);
for(int i=0;i1){
for(int i=0;itimeStep){
Serial.println("Automatic Control");
sensorValue=analogRead(ldr);
Serial.println("sensor value=");
Serial.println(sensorValue);
Volt=(5*sensorValue)/1023;
Lux=13.449*exp(1.0055*Volt)/pow(d,2);//pali o tupos ths sunarthshs
Difference=command.f-Lux;
if(Difference>0){
digitalWrite(relay,LOW);
VDifference= (log(Difference)-log(13.449))/1.0055;// antestrammenos o tupos ths sunarthshs ga na dinei volt
pwmValue1=(VDifference*255)/5;
pwmValue2=constrain(pwmValue1,0,255);
analogWrite(dimout,pwmValue2);
}
else{
digitalWrite(relay,HIGH);
}
Serial.print("The amount of light at your workspace is:");
Serial.print(Lux);
LuxValue.f=Lux;
SData[0]=LuxValue.b[0];
SData[1]=LuxValue.b[1];
SData[2]=LuxValue.b[2];
SData[3]=LuxValue.b[3];
xbee.send(zbTx);
}
From the looks of it, you are trying to read ASCII data instead of Hex data. From the quick search I did, there are several answers on Arduino’s support forum site for how to do this.
Actually this is just a test code. I’ve tried many different things to try to solve it, but none have succeeded.
Things that i’ve tried:
Different sets of Baud Rates;
Different sending methods (Serial.write, Serial.print(,HEX), Serial.print(,BIN));
Change the coordinator;
Change the transmitter;
Change the explorer;
Change the coordinator AND the transmitter;
About the Arduino forums, i did a search too but found nothing that helps. Yes, there are many topics with the same problem being reported, but none of them propose a solution that solves the problem at the end.
Hm, didn’t saw any useful information on those links. I’m not sending any ASCII value beyond the additional characters in that range (127).
Well, as said in the earlier comment i’ve already tried multiple ways of sending data, with both Serial.write and Serial.print.
The thing is, when i receive the data through the FTDI cable everything goes perfect. But when i send the data through the XBee those strange characters are added. I do receive the correct information and i’m able to understand it, but it’s together with those undesired characters.
Thanks for your help and time looking for those links btw. But that doesn’t seems the same situation i’m experiencing.
The characters you are referring to are Hex values because the XBee is in API mode. Try taking it out of API mode and you will not see the characters you are referring to.
Indeed the characters are gone when i don’t use API mode. So there is no way to get rid of those characters? I mean, if i use API mode those characters will be there no matter what?
Yes they will be there as you are seeing the ASCII representation of the Hex API packet. You will need to talk to your processor support to find out how to view the data in Hex instead of ASCII if you want to use API mode and to be able to view the RAW Hex API frame.
Many thanks mvut. I was confused about API mode, but now with your answers and taking some time to think about it i manage to understand what’s going on.
But i have another question now. XBee receives RF data over the serial port in ASCII encoding. But that’s not good at all for me because in this way the length of data i wanna transmit is duplicated. Let me try to explain better.
If want to send a value over the serial with the XBee, for example 255 decimal. It’s the same as FF hexadecimal and has a length of 1 byte. If i send this over the serial port and view the result in XCTU i get an ASCII encoding of the “FF” as 46 46 (hex code). This way one byte of information (FF) turned into two bytes because of the ASCII interpretation of 1 byte/character.
There is any way to transmit information without using ASCII encoding?
That is not the radio doing this. If you want to send Hex data using XCTU to verify everything is working, you need to use the Send packet function and Hex option. Then put in your 0xFF data field. You will see that this will then do what you wanted.