Steps:
- Connect coordinator with XCTU
- Connect the 2 end devices to make sure they are on the network
- Then remove them, you don't need them connected to work
- Open the console tab and select open.
- Send a tx frame from the coordinator to each end device. Use the TX 16 bit command to send a message and check the receive signal to see that they're communicating. Create a frame and change the destination address to 5678 for the first sensor/arduino. You should look for SUCCESS in the return message. Then switch the destination address to 8901 to test the second sensor/arduino.
- I connected a switch to pin 13 on each arduino and then used the code below to start the arduino measuring and sending data from the sensor. The button is either OFF or ON (0 or 1). The arduino code waits for the signal on pin 13 to change to 1 and then starts measuring and transmitting. The delay is 1 second.
- Here's a link to the coordinator reading the signals sent by both sensors https://youtu.be/uk8pG1J7uwA
Here's the arduino code:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <XBee.h>
XBee xbee = XBee();
unsigned long start = millis();
const int buttonPin = 13;
const int outputHigh =12;
int buttonState = 0;
// allocate two bytes for to hold a 10-bit analog reading
uint8_t payload[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
// 16-bit addressing for Series 1: Enter address of remote XBee, typically the coordinator
Tx16Request tx = Tx16Request(0x1234, payload, sizeof(payload));
TxStatusResponse txStatus = TxStatusResponse();
//initialize BNo055
Adafruit_BNO055 bno = Adafruit_BNO055();
int x = 0;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(outputHigh, OUTPUT);
digitalWrite(outputHigh,HIGH);
xbee.setSerial(Serial); //MAKE SURE to move the UART switch to UART when running the program. Switch to DLine when uploading program.
/* Initialise the BNO055 sensor */
if(!bno.begin())
{
/* There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while(1);
}
}
void loop() {
union flintbyte { //this is a C construct to convert float to 4 bytes
float ff; //to gain access to bytes of float
unsigned int ii; //to gain access to bytes of int
unsigned char cc[4]; //as many as needed to cover the largest other element
} fib;
// start transmitting after a startup delay. Note: this will rollover to 0 eventually so not best way to handle
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
imu::Vector<3> acc = bno.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
fib.ff=euler.x();
payload[3] = fib.cc[3];
payload[2] = fib.cc[2];
payload[1] = fib.cc[2];
payload[0] = fib.cc[0];
xbee.send(tx);
}
// after sending a tx request, we expect a status response
// wait up to 5 seconds for the status response
if (xbee.readPacket(5000)) {
// got a response!
// should be a znet tx status
if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE) {
xbee.getResponse().getTxStatusResponse(txStatus);
// get the delivery status, the fifth byte
if (txStatus.getStatus() == SUCCESS) {
// success. time to celebrate
}
}
} else if (xbee.getResponse().isError()) {
//nss.print("Error reading packet. Error code: ");
//nss.println(xbee.getResponse().getErrorCode());
// or flash error led
}
delay(1000);
}