4 Ways To Get Raspberry Pi To Read Multiple Analog Input Sensors!

Saturday, May 28, 2016

Unlike the Beaglebone Black, which has endless analog inputs/outputs, all 17 GPIO pins on the Raspberry Pi are digital pins. The good news is that there are a few ways to convert analog signal to digital so the Raspberry Pi can read multiple analog input sensors:

1) Via I2C or SPI interface chips
One way of getting the Raspberry GPIO pins to read analog sensor inputs is via I2C or SPI interface chips such as the ones found on the RasPiO Analog Zero board, ADC Pi Plus board, DFRobot 18-Bit ADC board and JeeLabs Analog Plug board, which are Analog to Digital converter boards that use the MCP3008 and MCP3424 chips.
The ADC Pi Plus, DFRobot and JeeLabs ADC boards use the MCP3424 chip, which provides four differential analog inputs for Raspberry Pi via I2C bus interface as well as configurable sampling rates and resolutions. All the way from 240 samples per second (12-bits resolution) to 60 samples per second (14-bits resolution), 15 samples per second (16-bits resolution) and 3.75 samples per second (18-bits resolution).

RasPiO Analog Zero board uses the MCP3008 chip and can connect to any 40-pin Raspberry Pi, as well as Raspberry Pi Zero and older 26-pin Raspberry Pi (with the aid of a Downgrade GPIO Ribbon Cable)
Using a ready made ADC board such as the ones mentioned above would definitely be the easiest way out to perform analog sampling with your Raspberry Pi. The better option for Raspberry Pi analog signalling would probably be the RasPiO Analog Zero board because it does not require any software installation to get the board reading 8 Sensors at once on the Raspberry Pi, plus the Analog Zero board features a 54-pin prototyping area and GPIO breakouts with plenty of power and ground connections where you can put additional components.
2) Resistor–Capacitor (RC) Charging Circuit
Hooking up an RC circuit to the Raspberry Pi is another way to get analog values from the Raspberry Pi by connecting analog sensors to one GPIO pin of the Raspberry Pi. Then, you place a resistor and capacitor in series on a breadboard and connect the breakout wires to PIN1 (3.3V) and PIN6 (Ground) of the Raspberry Pi to create an event where the GPIO pin goes from LOW to HIGH to register a reading. This is done by discharging the capacitor (by setting the GPIO pin LOW as an output) and then, setting the GPIO pin as in input to allow the capacitor to charge to at least 2 volts so the GPIO pin will register HIGH. Here is visually how the Resistor–Capacitor (RC) circuit method works:

3) Analog-to-Digital Converter Integrated Circuit
This third way is similar to the RC charging circuit method above, but it integrates an Analog to digital converter (ADC) chip in the circuit, allowing the Raspberry Pi to be able to read multiple analog signals. To create an ADC integrated circuit that can read multiple sensor inputs all you need is a breadboard, breadboard breakout wires, 10K ohm resistor and a 1uF capacitor, as well as an Analogue-to-digital converter (ADC) like the MCP3008 chip or similar chip that is pin compatible and uses the SPI protocol for successful data communication between the ADC and the Raspberry Pi.
The MCP3008 chip is great to use because it only requires four GPIO pins on the Raspberry Pi P1 Header and will give you 8 channels to sample analog inputs simultaneously. The four GPIO pins of the Raspberry Pi that you will need for communicating with the MCP3008 are the cobbler pins labeled as MISO, MOSI, SCLK and CE0 (or CE1).

4) Connecting Arduino to the Raspberry Pi
Another alternative to getting analog inputs from the Raspberry Pi would be to connect the Arduino to the Raspberry Pi as Arduino usually has a 10-bit ADC on board. With an Arduino, you would be able to trigger and control in real time potentiometers and many other analog sensors via USB connection without having to program in Arduino’s quasi-C++ language.

While it is great you can use the features and benefits of the Arduino microcontroller, the drawback of using Arduino with your Raspberry Pi to perform analog sampling is that Arduino's serial device name can change every time you connect Arduino to your Raspberry Pi. This means you will have to manually find Arduino's device name every-time and connect via USB which can get annoying.

Constructing a simple RC circuit and ADC circuit is definitely fun though it requires setting up the Raspberry GPIO pins, installing the necessary software and executing Python code which will become more complex the more sensors you add. Of course, you could easily add the sensors in Raspberry Pi Cayenne without having to do any coding.

Still, if you do not like tinkering much with breadboard wires; with a solution like the RasPiO Analog Zero board you can easily control GPIO pins and read analog sensors with very few lines of code because the board is easy to code with RPi.GPIO +Python and GPIO Zero +Raspberry Pi Python libraries so it requires minimal boilerplate code to get started.

Similar Gadget Explained Reviews


Connect With Gadget Explained