Reading Xbee Data In Matlab

All things pertaining to wireless and RF links

Moderator: phalanx

Reading Xbee Data In Matlab

Postby elizabethbellb » Mon Feb 21, 2011 1:56 pm

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
eleventh_number=A(n(i)+11);
twelfth_number=A(n(i)+12);
valueA(i)= bitshift(eleventh_number,8) + twelfth_number;
end
%% Conversion into voltage, Very uncertain of this conversion
voltA=(1024.*valueA+600)./1200; % from NorthWesternU website

Any help would be greatly appreciated. I've searched for examples in Matlab to no avail. Thanks!
elizabethbellb
 
Posts: 12
Joined: Mon Feb 21, 2011 1:29 pm

Re: Reading Xbee Data In Matlab

Postby waltr » Mon Feb 21, 2011 4:37 pm

Post the raw data stream you receive on the PC's COM port.

Which XBee modules do you have? Series 1 or Series 2? Which Firmware are they running?

If you have Series 1 XBees did you connect a voltage to the Vref pin?
waltr
 
Posts: 2651
Joined: Tue Sep 08, 2009 12:07 pm
Location: Philadelphia, USA

Re: Reading Xbee Data In Matlab

Postby elizabethbellb » Mon Feb 21, 2011 5:49 pm

Series 1. XB24 10CD 802.15.4

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
A= 126 0 10 131 0 1 94 0 1 2 0 3 255 24 126 0 10 131 0 1 94 0 1 2 0 3 255 24 126 0 10 131 0 1 94 0 1 2 0 3 255 24 126 0 10 131 0 1 94 0 1 2 0 3 255 24 126 0 10 131 0 1 94 0 1 2 0 3 255 24 126 0 10 131 0 1 94 0 1 2 0 3 255 24 126 0 10 131 0 1 94 0 1 2 0 3 255 24 126 0

Thank you very much for your assistance!
elizabethbellb
 
Posts: 12
Joined: Mon Feb 21, 2011 1:29 pm

Re: Reading Xbee Data In Matlab

Postby waltr » Mon Feb 21, 2011 6:27 pm

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.
waltr
 
Posts: 2651
Joined: Tue Sep 08, 2009 12:07 pm
Location: Philadelphia, USA

Re: Reading Xbee Data In Matlab

Postby elizabethbellb » Wed Feb 23, 2011 9:18 am

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.

Now for a 0.5V input (Sweeper to Ground) A= 0 1 94 0 1 2 0 1 219 62 126 0 126 0 10 131 0 1 94 0 1 2 0 0 158 124 126 0 10 131 0 1 94 0 1 2 0 0 157 125 126 0 10 131 0 1 94 0 1 2 0 0 157 125 126 0 10 131 0 1 94 0 1 2 0 0 158 124 126 0 10 131 0 1 94 0 1 2 0 0 158 124 126 0 10 131 0 1 94 0 1 2 0 0 157 125 126 0 10 131

Also this still isn't changing with changes to the input voltage. Maybe now it is a parsing issue? Any thoughts?
elizabethbellb
 
Posts: 12
Joined: Mon Feb 21, 2011 1:29 pm

Re: Reading Xbee Data In Matlab

Postby waltr » Wed Feb 23, 2011 10:52 am

Ok, give me some time to work out the decoding of the raw data. I should be able to get this done later today or tonight.
waltr
 
Posts: 2651
Joined: Tue Sep 08, 2009 12:07 pm
Location: Philadelphia, USA

Re: Reading Xbee Data In Matlab

Postby waltr » Wed Feb 23, 2011 9:41 pm

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:

Code: Select all
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.
Extract the data.

Hope that helps
waltr
 
Posts: 2651
Joined: Tue Sep 08, 2009 12:07 pm
Location: Philadelphia, USA

Re: Reading Xbee Data In Matlab

Postby elizabethbellb » Mon Jul 18, 2011 6:35 am

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.

s = serial('COM3');
fopen(s);
%% Running Test
i=1;
while i<100;
A=fread(s, 100);
n1=find(A==126);
%for i=1:length(n1)
ValA1=A(n1(1)+11);
ValA2=A(n1(1)+12);
Value=ValA1*255+ValA2
volt=Value/312.94 % calculated with a calibration
i=i+1;
end

Thank you for your help.
elizabethbellb
 
Posts: 12
Joined: Mon Feb 21, 2011 1:29 pm

Re: Reading Xbee Data In Matlab

Postby Reni » Wed Jan 25, 2012 1:44 am

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!!!!
Reni
 
Posts: 1
Joined: Wed Jan 25, 2012 1:34 am


Return to Wireless/RF

Who is online

Users browsing this forum: No registered users and 3 guests