Monday, October 10, 2016

sending two signals - XCTU

Two xbees are transmitting the accelerometer data from the BNO055 sensor connected to 2 arduinos.

Steps:

  1. Connect coordinator with XCTU
  2. Connect the 2 end devices to make sure they are on the network
  3. Then remove them, you don't need them connected to work
  4. Open the console  tab and select open.
  5. 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.
  6. 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.
  7. 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);
}

Sunday, June 26, 2016

Info on number conversions - SUCCESS updated!

Update:   The m file from the Matlab file exchange works!!!
The function is hexsingle2num.h

Here's what I typed:
hexsingle2num('401c0000')
It returned the correct answer 2.4375

To test:  I believe the api frame sends the bytes as 00 00 1C 40

So, the bytes need to be switched to put it into the new function.


Here's a really good explanation by Jack Christensen - scroll down to his second entry.
http://forum.arduino.cc/index.php?topic=211723.0

Here's a good converter that gives the same values as the BNO055 sensor and the library and the use of the C union struct.
http://www.h-schmidt.net/FloatConverter/IEEE754.html


Info on number conversions

Here's a really good explanation by Jack Christensen - scroll down to his second entry.
http://forum.arduino.cc/index.php?topic=211723.0

Here's a good converter that gives the same values as the BNO055 sensor and the library and the use of the C union struct.
http://www.h-schmidt.net/FloatConverter/IEEE754.html


Monday, June 20, 2016

Similar projects


Reference to hip, knee, ankle!
http://www.mathworks.com/matlabcentral/answers/144385-storing-arduino-serial-data-to-cell-array


Two BNO055, two xbees, two arduinos sending data to coordinator


This works!

Each arduino has code from this blog post: http://xbeematlabsiena.blogspot.com/2016/06/txbno055-arduino-code-success.html.  The name of the file is Tx_BNO055_Success_6_20_16.ino

The api packets are received by the coordinator as seen in the XCTU software.

Configuration settings are important!!!
One xbee was transmitting really fast and the other was really slow.  I wasn't sure if it was a difference in boards:  arduino uno, spark fun shield, or xbee.  I saved the xctu configuration file for my fast xbee and loaded it onto the slow xbee.  Voila - it started transmitting faster.

I'm not sure what change to the settings makes the xbee transmit faster.  It could be IC = 10 or IA = FFFFFFFF



Xbee CTU profile files

Coordinator

file name:  Coord_config_xctu_profile.xml
<?xml version="1.0" encoding="UTF-8"?>

<data>
  <profile>
    <description_file>xb24_15_4_10ed.xml</description_file>
    <settings>
      <setting command="CH">C</setting>
      <setting command="ID">3332</setting>
      <setting command="DH">0</setting>
      <setting command="DL">FFFF</setting>
      <setting command="MY">1234</setting>
      <setting command="MM">0</setting>
      <setting command="RR">0</setting>
      <setting command="RN">0</setting>
      <setting command="NT">19</setting>
      <setting command="NO">0</setting>
      <setting command="CE">1</setting>
      <setting command="SC">1FFE</setting>
      <setting command="SD">4</setting>
      <setting command="A1">0</setting>
      <setting command="A2">0</setting>
      <setting command="EE">0</setting>
      <setting command="KY"></setting>
      <setting command="NI">0x20COORDINATOR</setting>
      <setting command="PL">4</setting>
      <setting command="CA">2C</setting>
      <setting command="SM">0</setting>
      <setting command="ST">1388</setting>
      <setting command="SP">0</setting>
      <setting command="DP">3E8</setting>
      <setting command="SO">0</setting>
      <setting command="BD">3</setting>
      <setting command="NB">0</setting>
      <setting command="RO">3</setting>
      <setting command="AP">2</setting>
      <setting command="D8">0</setting>
      <setting command="D7">1</setting>
      <setting command="D6">0</setting>
      <setting command="D5">1</setting>
      <setting command="D4">0</setting>
      <setting command="D3">0</setting>
      <setting command="D2">0</setting>
      <setting command="D1">0</setting>
      <setting command="D0">0</setting>
      <setting command="PR">FF</setting>
      <setting command="IU">1</setting>
      <setting command="IT">1</setting>
      <setting command="IC">0</setting>
      <setting command="IR">0</setting>
      <setting command="P0">1</setting>
      <setting command="P1">0</setting>
      <setting command="PT">FF</setting>
      <setting command="RP">28</setting>
      <setting command="IA">FFFFFFFFFFFFFFFF</setting>
      <setting command="T0">FF</setting>
      <setting command="T1">FF</setting>
      <setting command="T2">FF</setting>
      <setting command="T3">FF</setting>
      <setting command="T4">FF</setting>
      <setting command="T5">FF</setting>
      <setting command="T6">FF</setting>
      <setting command="T7">FF</setting>
      <setting command="DD">10000</setting>
      <setting command="CT">64</setting>
      <setting command="GT">3E8</setting>
      <setting command="CC">2B</setting>
    </settings>
  </profile>
</data>
-----------------------------------------

End Device

file name:  End_device_config_xctu_profile.xml

<?xml version="1.0" encoding="UTF-8"?>

<data>
  <profile>
    <description_file>xb24_15_4_10ed.xml</description_file>
    <settings>
      <setting command="CH">C</setting>
      <setting command="ID">3332</setting>
      <setting command="DH">0</setting>
      <setting command="DL">1234</setting>
      <setting command="MY">5678</setting>
      <setting command="MM">0</setting>
      <setting command="RR">0</setting>
      <setting command="RN">0</setting>
      <setting command="NT">19</setting>
      <setting command="NO">0</setting>
      <setting command="CE">0</setting>
      <setting command="SC">1FFE</setting>
      <setting command="SD">4</setting>
      <setting command="A1">0</setting>
      <setting command="A2">0</setting>
      <setting command="EE">0</setting>
      <setting command="KY"></setting>
      <setting command="NI">0x20SENSOR</setting>
      <setting command="PL">4</setting>
      <setting command="CA">2C</setting>
      <setting command="SM">0</setting>
      <setting command="ST">1388</setting>
      <setting command="SP">0</setting>
      <setting command="DP">3E8</setting>
      <setting command="SO">0</setting>
      <setting command="BD">3</setting>
      <setting command="NB">0</setting>
      <setting command="RO">3</setting>
      <setting command="AP">2</setting>
      <setting command="D8">0</setting>
      <setting command="D7">1</setting>
      <setting command="D6">0</setting>
      <setting command="D5">1</setting>
      <setting command="D4">3</setting>
      <setting command="D3">0</setting>
      <setting command="D2">0</setting>
      <setting command="D1">0</setting>
      <setting command="D0">0</setting>
      <setting command="PR">FF</setting>
      <setting command="IU">1</setting>
      <setting command="IT">1</setting>
      <setting command="IC">10</setting>
      <setting command="IR">0</setting>
      <setting command="P0">1</setting>
      <setting command="P1">0</setting>
      <setting command="PT">FF</setting>
      <setting command="RP">28</setting>
      <setting command="IA">FFFFFFFFFFFFFFFF</setting>
      <setting command="T0">FF</setting>
      <setting command="T1">FF</setting>
      <setting command="T2">FF</setting>
      <setting command="T3">FF</setting>
      <setting command="T4">FF</setting>
      <setting command="T5">FF</setting>
      <setting command="T6">FF</setting>
      <setting command="T7">FF</setting>
      <setting command="DD">10000</setting>
      <setting command="CT">64</setting>
      <setting command="GT">3E8</setting>
      <setting command="CC">2B</setting>
    </settings>
  </profile>
</data>