How to read analog data from GPIO, Android-things
Asked Answered
S

3

7

Tried to read analog data from gpio, but only see a way which returns signal strength as LOW or HIGH (boolean). Couldn't find any solution in the documentation and in code references. Is it even possible for now?

Steading answered 27/12, 2016 at 9:53 Comment(5)
Can specify which pins are you using and paste your code?Fermata
For example BCM13 (Rpi 3), but there is no code, just can't find how to read from there with non boolean valueSteading
I added interesting blogpost to my original answer, showing how to build your own ADC module for Android Things (the author of the post included Android library to use it). You might find that useful.Fermata
Covering my issue: you can connect Arduino if you have one to the RPI and use analog input/ouput translated via UART, made an article regarding that: article linkSteading
Awesome! Will try that tomorrow!Fermata
F
3

Raspberry Pi 3 doesn't have analog-to-digital converter so you can only get boolean values (high/low) from its GPIO. So in order to get analog data you need to use external ADC module in your project.

EDIT: I found this interesting blogpost showing how to measure analog input on Android Things.

Fermata answered 27/12, 2016 at 12:46 Comment(0)
S
1

For Raspberry Pi you will need to use an analog-to-digital converter such as the ADS1115.

Selhorst answered 27/12, 2016 at 19:55 Comment(3)
What about boards, such as the Edison with Arduino breakout, that do have analog input pins?Firm
The Intel Edison has 6 analog inputs (pins A0-A5) and 6 analog (PWM) outputs (pins ~3,~ 5,~ 6, ~9, ~10, ~11). In order to read a sensor from an analog input take a look at this: developer.android.com/things/sdk/drivers/sensors.html. To use the analog outputs check out: developer.android.com/things/sdk/pio/pwm.htmlSelhorst
Actually the Edison with the Arduino breakout has a built in ADC that currently isn't supported by Android Things per code.google.com/p/android/issues/detail?id=230568 So right now you can only write drivers for digital input sensors, not analog.Firm
F
1

If you're still looking, I wrote a class and sample for the Adafruit MCP3008 ADC

https://github.com/PaulTR/AndroidThingsMCP3008ADC

Firm answered 20/3, 2017 at 5:27 Comment(2)
Hi Paul,with TMP36, channel 0 read is giving reading 257, I think which is incorrect as per my room temperature, I just used your code for MCP3008 with same pin configurations. Any suggestions what may be wrong?Trouveur
@MahendraChhimwal If that's the direct reading, you probably need to convert it to a temperature. You'll probably want (value - 50) / 10, which should give you 20.7C, which is about 70F.Firm

© 2022 - 2024 — McMap. All rights reserved.