I am a bit of a newbie at this so my apologies if I am doing something exceptionally silly.
I am trying to transmit a single ADC channel (a potentiometer) of data between my two xbee modules. One is on an USB explorer the other just a regular board.
I have configured my xbees fine, can open the serial channel in Matlab and get a steady signal through. Using this code:
s = serial(‘COM3’);
fopen(s);
A=fread(s, 100);
However, I tried to parse the A variable as follows and I get 1023 always for valueA despite known changes (measured with a multimeter) in the input voltage from 2V down to as low as 0.1 V. I tried switching to a different input channel and still have the same problem.
n=find(A==126); % find data chunk header
for i=1:length(n) % compensation for change in bit format btwn xbee and computer
The lack of reference voltage would certainly be a problem. However, I don’t see one on the xbee explorer regulator board. On the regulator board the 14th pin is labeled Dout. I tried the same procedure with that pin grounded and nothing changed. I am using the board’s 3.3V output and ground for the two ends of the potentiometer.
Output with 0.1 V between the measured ADC pin and ground
Ok, you do need to apply a reference voltage to the XBee. Look at the XBee Document #90000982B that is downloadable from Digi Int’s web site.
Table 1-02 shows to XBee pin-out, Pin 14 of the XBee is Vref.
One is on an USB explorer the other just a regular board.
Exactly which SparkFun board is being used as the “regular board”? Is it the Regulated Explorer or just the Breakout board?
Either way find which pad is connected to the XBee’s pin 14 and apply 3.3V (see Table 1-04 for the ADC voltage specs).
If there isn’t any voltage applied the the Vref pin (Vref = 0V) then any voltage on an ADC input would convert to a Full-scale reading or 1023. So, you may have been doing the data parsing and conversion correctly.
Xbee explorer regulator board. I misunderstood the pin numbering on the board now I have taken the RES pin (xbee pin 14) to 3.3V. Thank you for you help with that. Unfortunately, I’m still having trouble.
Ok, I got your data decoded. It is an API Frame of type 0x83 (search the XBee doc).
I first convert the decimal values to hex since this is how data is shown in the XBee doc and some of the data fields represent which pins are active with a bit. So one API frame in decimal then hex is:
126 0 10 131 0 1 94 0 1 2 0 0 158 124
7E 00 0A 83 00 01 5E 00 01 02 00 00 9E 7C
Next I start decoding the frame a byte at a time. Find the Type 0x83 and look up the decode for that which references API frame type 0x81. The full decode is:
byte# dec hex bytes description
1 126 7E start
2 & 3 0 10 00 0A length
4 131 83 API Frame type
5 & 6 0 1 00 01 16 bit address
7 94 5E RSSI
8 & 9 0 1 00 Options
10 1 01 # samples
11&12 2 0 02 00 Channel Ind: A1 only
13&14 0 158 00 9E Analog ADU:
15 124 7C Checksum
Dig through the XBee doc until you understand each item.
Now the ADC value is 158 decimal so the voltage is:
V = 3.3V * 158/1023 = 0.509V
Which is what you measured on the XBee input pin.
The way I have done API frame receiving (an got from Digi docs) is to bring one full API frame in from the input buffer.
Calculate and compare the checksums.
Decode the frame type to process the remainer of the frame contants differently.
Sorry it took me so long to reply to this. This code works well for me, although 312.94 does not seem like a standard system value. Sadly my main issue was only reading a single value off the system at a time. The first value read sometimes has issues.
Hello!!I have ceated a PID line follower and now I want to access the data of the motors by wireless xigbee using matlab!!i found the topic helpful to a great xtent but not exactly getting how will I modify my code!!I have written the line follower code in C!!! can ne 1 help me!! :roll:
Those who have solved dere problem kindly help me!!the robot supports AVR platform!!For oder queries plz ask me so that I can solve my problem!!!