Home/Support/Support Forum/Xbee Returning a Byte?

Xbee Returning a Byte?

0 votes
Hello!

I am working on a project that uses a force sensitive resistor and I am running into an issue with the analog values I am reading. From my understanding, the values should range from 0-1023 because I have a 10 bit ADC. However, as I apply more pressure, the sensor resets at about 260 and I am not sure why. I am printing the analog reading to the serial port in Arduino and I can see the value steadily rise as I apply more force but once it hits about 260, the reading goes back to 0 and continues to count up again. I am guessing that somehow I am using a data type of a byte.

I am using XBee's to send the analog value wirelessly and I get the values through the command rx16.getData(). I was wondering if this command returns a byte which would be the source of my issue.

Does anyone have any experience with this or know what would cause this issue? Thank you!


Code:
#include <XBee.h>
#include <SoftwareSerial.h>
#include <AltSoftSerial.h>
#include <SPI.h>
#include <SD.h>
//import the xbee, software serial, SPI, and SD card libraries

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
Rx16IoSampleResponse rx16 = Rx16IoSampleResponse();

//define the two pins used for data transmission
//Dout on the XBee goes to pin 2 and Din goes to pin 3
#define ssRX 2
#define ssTX 3
SoftwareSerial lcd(ssRX, ssTX);
AltSoftSerial xbeeserial;

//variables for each of the four sensor values, the SD card, and the button
float data = 0;
float data2 = 0;
float data3=0;
float data4=0;
float front=0;
float back=0;
const int button1Pin = 4; // pushbutton 1 pin
int button1State;
const int chipSelect = 10;

void setup() {
// Set up the pushbutton and sd card pins:
pinMode(button1Pin, INPUT);
pinMode(chipSelect, OUTPUT);
// start serial
Serial.begin(9600);
// and the software serial port
lcd.begin(9600);
// now that they are started, hook the XBee into
// Software Serial
xbeeserial.begin(9600); //new
xbee.setSerial(xbeeserial);
lcd.print(" ");
Serial.println("starting up!");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}

void loop() {
xbee.readPacket();
//Serial.println("test");
if (xbee.getResponse().isAvailable()) {
// got something
Serial.println();
Serial.print("Frame Type is ");
Serial.println(xbee.getResponse().getApiId(), HEX);

if (xbee.getResponse().getApiId() == RX_16_IO_RESPONSE) {
xbee.getResponse().getRx16IoSampleResponse(rx16);
//prints the analog values from each of the sensors
data = rx16.getData(4);
data2=rx16.getData(6);
data3=rx16.getData(8);
data4=rx16.getData(10);
//data=data*3.0/265.0;
//data2=data2*3.0/265.0;
//data3=data3*3.0/265.0;
//data4=data4*3.0/265.0;
front=data + data2;
back=data3+data4;
float sensorVoltageF = front * (3.0 / 1023.0);
float sensorVoltageB= back* (3.0/1023.0);
//double voltage2Pound = 6.8723*sensorVoltage*sensorVoltage*sensorVoltage - 3.7445*sensorVoltage*sensorVoltage + 7.1943*sensorVoltage - .2046;
if (front != 0){
lcd.print("Frnt(lbs): ");
lcd.println(front);
} else if (back != 0){
lcd.print("Back(lbs): ");
lcd.println(back);
}
else{
lcd.println("No Force ");
}
String dataString = "";
dataString += String(sensorVoltageF);
Serial.println(data);
Serial.println(data2);
Serial.println(data3);
Serial.println(data4);
//dataString += " ";
//dataString += String(sensorVoltageB);

button1State = digitalRead(button1Pin);
if (button1State == HIGH){
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("DATALOG.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening DATALOG.txt");
}
}
}

else if (xbee.getResponse().isError()) {
Serial.print("Error reading packet. Error code: ");
Serial.println(xbee.getResponse().getErrorCode());
}
}
}
asked Dec 10, 2019 in RF Solutions and XBee by nabatta New to the Community (0 points)

Please log in or register to answer this question.

2 Answers

0 votes
No the frame does not issue a byte that would cause that.
answered Dec 12, 2019 by mvut Veteran of the Digi Community (15,108 points)
0 votes
May be you can first use XCTU's Console tab to manually read incoming IO frames. This way you can figure out if issue is with code or with your setup.

If latter is true, then you may replace force sensitive resister with variable voltage supply to check if Digi XBee is performing ADC job correctly.
answered Dec 13, 2019 by asgm Veteran of the Digi Community (1,499 points)
...