Go Down

Topic: Arduino Xbee SoftwareSerial (Read 826 times) previous topic - next topic

usermatthew

Nov 17, 2019, 06:11 pm Last Edit: Nov 17, 2019, 06:28 pm by usermatthew
This is a way of sending Xbee commands using SoftwarSerial. It may not be the best, but the command can be changed according to needs.

  • Using the Xctu Software put the coordinator xbee in APT mode with escapes.
  • Put the other in transparent mode
  • Make a Remote AT command using the frame generator.
  • Use the MAC address as the 64 Bit address
  • Enter other information per instruntion required ie. D1  0x04
  • Copy HEX generated for code.
  • In Arduino IDE create a byte array using the hex code.



The byte array should look like this.

Code: [Select]
byte ledOn[] = {0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x7D, 0x33, 0xA2, 0x00, 0x41, 0x92, 0xE8, 0x4C, 0xFF, 0xFE, 0x02, 0x44, 0x31, 0x05, 0xB2};

Make each byte of the command a different piece of the array.
The last 4 elements can be changed to the desired command.
use an ASCII to HEX table to generate the elements.
the checksum is different depending on the mode the xbee is in.
Use this link to generate the checksum xbee Checksum Datasheet page

using the software serial send the following command

Code: [Select]
xbee.write(ledOn,sizeOf(ledOn));


In the following code I am using an Arduino Uno and a Xbee pro s3b
Code: [Select]
#include <SoftwareSerial.h>

SoftwareSerial xbee(4, 5); //(RX,TX)
byte off[] = {0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x7D, 0x33, 0xA2, 0x00, 0x041, 0x92, 0xE8, 0x4C, 0xFF, 0xFE, 0x02, 0x44, 0x31, 0x04, 0xB3};
byte on[] = {0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x7D, 0x33, 0xA2, 0x00, 0x41, 0x92, 0xE8, 0x4C, 0xFF, 0xFE, 0x02, 0x44, 0x31, 0x05, 0xB2};
#define swi 7
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  xbee.begin(9600);
  pinMode(swi, INPUT);
  // xbee.write("7E 00 10 17 01 00 7D 33 A2 00 41 92 E8 4C FF FE 02 44 31 04 B3");
}

void loop() {
  // put your main code here, to run repeatedly:

  if (digitalRead(swi) == LOW) {
    xbee.write(off, sizeof(off));
    Serial.println("OFF");
  }
  if (digitalRead(swi) == HIGH) {
    xbee.write(on, sizeof(on));

    Serial.println("ON");
  }
  delay(200);
}

Go Up