Electronic – directly read an analog sensor data from the Xbee’s ADC

adcraspberry piuartxbee

I've posted this on the main StackOverflow and was suggested to post this here:

By rule of thumb, I've searched at least 10 different sources for my question before coming here.

My question is: if I have a Raspberry Pi that is connected via UART communication to an Xbee with a connected analog sensor (say IR distance sensor), can I read the sensor data directly from the Xbee on the UART communication?

The only sources I can find only address an Xbee collecting the sensor data and then sending it over the RF signal to another Xbee. None of the sources seem to explicitly address the Xbee acting as an ADC for my Raspberry Pi target.

Best Answer

To read analog (or digital) pins (ie. your sensor data) via the local serial port, send the appropriate D0, D1, D2, D3 command.

Example (Transparent Mode):
Snd: <guard>+++<guard>
Rec: OK
Snd: ATD0<cr>
Rec: 42 ( the data )

For API mode, wrap the Dx command in an AT frame.