2

I need to be able to see the level of a voltage over a gpio input pin. Is it possible to read the voltage level in python, and if so, how?

I've tried to google it and I've looked at the GPIO python documentation but no luck so far. What I'm working with is a receiver outputting small voltages in the range of 0.15-0.25, where higher means the throttle stick has been moved up, so I need to be able to get the voltage and then run some code if it hits a threshold.

2
  • You say you "need to be able to see the level of a voltage" then "run some code if it hits a threshold". You have not defined your task. There are many ways of reading an analog input (all requiring external hardware) depending on precision and accuracy required. If you want to detect if an input has exceeded a threshold there are also many solutions, some requiring minimal hardware.
    – Milliways
    Aug 11, 2015 at 13:12
  • Does this answer your question? Pi Zero W and Light Sensor with LDR Jan 24, 2021 at 15:03

2 Answers 2

5

All the Pi's gpios are digital, they read as 0 or 1 depending on whether they are connected to a low or high voltage.

To read an analogue (continuously varying) value such as a voltage you need an ADC (Analogoue to Digital Converter).

You connect the varying voltage to the ADC and the ADC to the Pi. The connection to the Pi is typically made using the Pi's in-built SPI or I2C link.

That will allow you to read the analogue value on the Pi.

Look at ADCs such as the MCP3008.

1

The MCP3008 Family is good start. You can find a lot of useful descriptions in this book: Make: Sensors: A Hands-On Primer for Monitoring the Real World with Arduino and Raspberry Pi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.