Wednesday, July 09, 2008

Sensors and the XBee

First and foremost the sensor you have to be using must use a serial protocol. I2C and SPL and others will not work. They might if you play with the API mode, but honestly I have no idea since I have not gotten a chance to use the API mode yet. That being said I shall continue. The Xbee Series 1 has 7 AD ports or analog data in. These are pins 11 and 15 through 20. Please refer to the manual for the number since they are NOT in numeric order. Plug the sensors in to the appropriate analog in. Also make sure your VREF (voltage reference: pin 14) is connected to the power. The power must be the same power that is powering your sensors (this should be around 3.3V). Using XCtu makes configuration easy so I recommend it.

You need to set the pin to the ADC mode because its default is to completely disable the pin all together. ATD* (for example using AD0 you would type ATD0) must be set to 2. Other values are used for a multitude of things so consult the manual.

Set your sample rate with the ATIR (values 0 to FFFF in milliseconds). Choose this on the speed you need and how much data you can cram down the serial port before causing problems. The less lag and high the baud rate the lower this value can be.

Set your sample number with the ATIT (values 0 to FF). Do NOT set this to one. Multiple values are good for buffering and smoothing out the sensor data.

Once the other values for the XBee are set get read to parse. (Network, who is sending to whom etc.)

XBees send their values in a certain fashion. Remember that most of the data is sent by least significant bit and most significant bit. So you will have to translate that into your code to get the actual value. I will explain later.

ZBees send their data as such:
Bits 1: This is the start bit. Value should be 126.
Bits 2-3: MSB and LSB of the packet size
Bit 4: API ID
Bits 5-6: MSB and LSB of the sender's address
Bit 7: RSSI This is the signal strength. Good for triangulating things
Bit 8: Broadcast Options
Bit 9: The number of Samples to follow
Bits 10-11: MSB and LSB for the active channels
Bits: 12-13+: From then on it is the MSB and LSB of the data sent
Last bit will have a value of 10 this is the end bit.

Two translate the two bits of data into one is simple. Multiply the MSB bit by 256 and then add the least significant bit. That will be the value of the sensor reading.

0 Comments:

Post a Comment

<< Home