1

I have an arduino mega and an uno, mega has an xbee s2c as coordinator and uno an xbee s2c as router, both in AT ( transparent ) mode. When I send integers from uno with Serial.write() coordinator receives just fine, but when i try float, negative numbers and chars, i get still integers but as I found out sending chars it is in ASCII. I tried Serial.print() but no result. Is there a way to send a negative float from one xbee to the other in AT mode?

Coordinator code

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial1.begin(9600);
  Serial.println("Comersing test!");
}

void loop() {
  if(Serial1.available()>0){
         Serial.print(Serial1.read());
    }
}`

UNO code

#include <SoftwareSerial.h>
 SoftwareSerial xbSerial(8, 7); // RX, TX
void setup() {
  xbSerial.begin(9600);
  xbSerial.write("First data sent!");

}
int x=4;
void loop() {
  // put your main code here, to run repeatedly:
      xbSerial.write(x);
      x++;
      delay(1000);
      delay(1000);
      delay(1000);
}

if I change x in Uno to float, negative or char, I get weird values.

1
  • If you can send ASCII and you have control over both ends of the data then you could send the numbers as text strings (not very efficient). If the number have a limited range i.e. -127 -> +127 then you could send 0 when you wanted to transmit -127, 1 for -126, etc. Commented Feb 15, 2017 at 8:56

1 Answer 1

-1

XBee cannot send negative integers, as it is working in hexadecimal and it has range between 0-255

1
  • 2
    I'm afraid that's not true, if it was then no computer would be able to represent negative numbers. It all depends on the encoding. Commented Feb 15, 2017 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.