XBee analog pins?

Glancing over the XBee docs, I see that there are 6 analog input pins. Is it a reasonable idea to connect analog sensors such as a thermocouple or a light sensor directly to these pings?

If so, how are these pins read on the other end? Can I take momentary samples of these constant analog inputs via the serial interface on the receiving end?

Thanks!

The XBee manual describes the data format used with the ADC. You’ll get a three-byte header, in which the first byte indicates how many samples will be sent, and the second and third bytes are bit flags telling you which analog and digital channels are active.

Then you’ll get some number of bytes representing the data. You’ll first get two bytes that tell you which of the digital channels are high and which are low. Then for each active ADC channel you’ll get two bytes: MSB and LSB of the corresponding channel’s analog voltage.

For example, you might receive these data:

Header bytes (3)

00000110 00000010 00001010 = 6 samples, ADC 1 on, DIO 1 and 3 on

Sample bytes (24: 6 sets of 2 bytes representing the status of the digital lines, followed by 2 bytes representing each of the ADC samples)

00000000 00001010 00000000 00011011 = 27 ← value of the sample

00000000 00001010 00000000 00011000 = 24

00000000 00001010 00000000 00011001 = 25

00000000 00001010 00000000 00011010 = 26

00000000 00001010 00000000 00011010 = 26

00000000 00001010 00000000 00011000 = 24

I recorded these using a light meter to provide analog input.

What I have not figured out is why after the header and data, I consistently receive 9 additional bytes. Still working on that part.

It is also possible to use I/O line passing, and in fact this sounds closer to what you’re asking about. I haven’t tried it yet, but the manual says that you can use the analog input to the AD0 pin to change a PWM value sent out pin PWM0 of a receiving XBee module. Presumably AD1 will control PWM1 as well, giving you two lines of analog line passing.

In short, you can either have a digital value on the receiving end, or an analog one, whichever works better for you. There are more lines available for transmitting the ADC values as digital values, though.

Thank you, that is very helpful information. It looks like I need to have a good sit-down with that manual.

Will using these pins as analog drain the battery any faster, or is the value only polled on demand?

isnoop:
Thank you, that is very helpful information. It looks like I need to have a good sit-down with that manual.

Will using these pins as analog drain the battery any faster, or is the value only polled on demand?

I couldn’t tell you about that - sorry.

In the example I posted, notice that I explicitly asked for 6 samples at a time to be sent. You can adjust that value to pretty much whatever works for your application. You might be able to affect battery life by adjusting how many samples are collected before transmission.

I know you’re asking about polling of the analog inputs. That is definitely done between transmissions, and I believe at a steady rate not influenced by the transmissions. You can adjust the sample rate using the IR parameter. There also is a “Force Sample” command (IS):

“The IS command is used to force a read of all enabled DIO/ADC lines. The data is returned through the UART.”

(I wonder when people who write documentation will learn that the word “data” is plural)

Anyway, using that, you should be able to conserve battery power by only sampling when you ask for a sample. It looks like it samples and then transmits immediately, which is exactly what you’d want. You can probably put it into sleep mode them until the next sample - but I haven’t done any of that myself so far. As far as I can see, the data collected in a Forced Sample are (yes, “are”, not “is”) returned in the same format I described above.