Sending multiple bytes via Xbees

Hello,

I want to transmit wireless a 4 digit number from one arduino to another by using two Xbees.

At the moment I can send one byte at a time. i.e. send a one digit number. However if I want to send a 3 digit number, it gets all screwed up on the receiver end.

Does anyone know of any simple tricks to over come this? Or even point me in the direction of a suitable tutorial.

Thank You.

Send a "start of packet" marker and an "end of packet" marker so that the device on the other end knows exactly what you're sending it.

I am using XBee AT Mode. Is this possible to do without reverting to API mode?

Basically I want to send a number like 693 from one device to another.

At the moment it comes out on my receiver device as:

54
57
51

I can work fine if only sending a 1 digit number as I can convert the decimal number back to a symbol. But I don't know how to manage a 3 digit number. Ideally I want this to come out on my receiver as the intended 693.

Simple delimited serial test code that might be tweaked for use on both arduinos.

//zoomkat 3-5-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
// CR/LF could also be a delimiter
//send on, or off, from the serial monitor to operate LED

int ledPin = 13;
String readString;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT); 
  Serial.println("serial LED on/off test with , delimiter"); // so I can keep track
}

void loop() {

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      Serial.println(readString); //prints string to serial port out
      //do stuff with the captured readString
      if(readString.indexOf("on") >=0)
      {
        digitalWrite(ledPin, HIGH);
        Serial.println("LED ON");
      }
      if(readString.indexOf("off") >=0)
      {
        digitalWrite(ledPin, LOW);
        Serial.println("LED OFF");
      }       
      readString=""; //clears variable for new input
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

Good day,

It seems we are stuck in the same position, my klast test showed some pretty good results and wanted to share.

If anyone can help continue this sketch and help that would be sweet. So far only 1 analog signal is transfer, I suspect that by enabling another pin on xbee to pass the other signal that all should work…

\cheers

this is for serie 1 xbees

Transmitter xbee settings

ATRE
ATMY1234
ATDL5678
ATDH0
ATID0
ATD02
ATIR64
ATWR

Receiver xbee settings:

ATRE
ATMY5678
ATDL1234
ATDH0
ATID0
ATWR

/*
XBeeAnalogReceiveSeries1
Read an analog value from an XBee API frame and set the brightness
of an LED accordingly.
*/

#include <Servo.h>

int servoVal;      
int servoVal2;


Servo ST1, ST2; 


void setup() {

  // Servo
  ST1.attach( 6, 1000, 2000);
  ST2.attach(5, 1000, 2000);  
  
Serial.begin(9600);
configureRadio(); // check the return value if you need error handling
}

boolean configureRadio() {
// put the radio in command mode:
Serial.flush();
Serial.print("+++");
delay(100);
String ok_response = "OK\r"; // the response we expect.
// Read the text of the response into the response variable
String response = String("");
while (response.length() < ok_response.length()) {
if (Serial.available() > 0) {
response += (char) Serial.read();
}
}
// If we got the right response, configure the radio and return true.
if (response.equals(ok_response)) {
Serial.print("ATAP1\r"); // Enter API mode
delay(100);
Serial.print("ATCN\r"); // back to data mode
return true;
} else {
return false; // This indicates the response was incorrect.
}
}
void loop() {
  

  
  
  if (Serial.available() >= 14) { // Wait until we have a mouthful of data
if (Serial.read() == 0x7E) { // Start delimiter of a frame
// Skip over the bytes in the API frame we don't care about
for (int i = 0; i < 10; i++) {
Serial.read();
}
// The next two bytes are the high and low bytes of the sensor reading
int analogHigh = Serial.read();
int analogLow = Serial.read();

int analogValue = analogLow + (analogHigh * 181);
servoVal = map(analogValue, 0, 1023, 0, 180);     // scale it to use it with the servo (result  between 0 and 180)
 
ST1.write(servoVal);                    	  	 // sets the servo position according to the scaled value  
}
}
}

One trick I used when sending a three digit number like controlling a servo remotely by a pot, is to first map the servo value so you have a number between 0 and 180. Add 100 to this value, now you will always have a 3 digit number. Send the value to the receiver. Subtract 100. This will give you your servo value.

Dave

bogey:
... I can convert the decimal number back to a symbol. But I don't know how to manage a 3 digit number. Ideally I want this to come out on my receiver as the intended 693.

parse your number
into 3 digits
[using modulo %]

int parseNumber;
byte ten_e2;
byte ten_e1;
byte ten_e0;

Example with parseNumber = 842)
digit_ten_e2 = parseNumber / 100; // 8
digit_ten_e1 = (parseNumber % 100) / 10; // (45/10 = 4)
digit_ten_e0 = (parseNumber % 100) % 10; // 45 % 10 = 5

Example with parseNumber = 3)
digit_ten_e2 = parseNumber / 100; // 0
digit_ten_e1 = (parseNumber % 100) / 10; // 3 / 10 = 0
digit_ten_e0 = (parseNumber % 100) % 10; // 3 % 3 = 3

Example with parseNumber = 86)
digit_ten_e2 = parseNumber / 100; // 0
digit_ten_e1 = (parseNumber % 100) / 10; // 86 / 10 = 8
digit_ten_e0 = (parseNumber % 100) % 10; // 86 % 10 = 6

Transmit digit_ten_e2, digit_ten_e1, digit_ten_e0, as 3 bytes.

The Receive routine should restore the original number --
reconstruct = (digit_ten_e2 * 100) + (digit_ten_e1 * 10) + digit_ten_e0