The Raspberry Pi GPIO is great but it does miss one vital feature, analog input.There are a few ways to add analog-to-digital conversion, but each has its drawbacks. You could use a cheap ADC chip like the MCP3008, but that requires a lot of wires and soldering. Some of the best Raspberry Pi HATs, have ADC but what if you don’t need or want to pay for a HAT with a ton of other features?
However, if you’re looking for an affordable and lightweight solution for getting analog input on your Raspberry Pi, the Pimoroni IO Expander could be your best choice. For just $10, the IO Expander offers ADC, along with Pulse Width Modulation (PWM) and extra GPIO pins to any model of Raspberry Pi.
Design of the Pimoroni IO Expander
The Pimoroni IO Expander is not a typical add on board for the Raspberry Pi. Measuring a mere 1 x 0.9 inch (25 x 23mm) the board has only five connections which are made to the GPIO. The need for so few connections is due to the IO Expander using I2C, a two wire serial communication protocol.
These five pins can be soldered to using the included male / female header pins, then placed atop the I2C pins of the GPIO. This design is not accidental, rather it is deliberate as the IO Expander is part of Pimoroni’s Breakout Garden range of boards. Using the Breakout Garden HAT (opens in new tab) we can insert up to six boards in the range to create bespoke projects quickly. Other boards in the range include a thermal camera, a six axis motion sensor (X,Y,Z and magnetic heading) and there are screens such as LCD, e-ink and OLED.
Pimoroni IO Expander Hardware Specifications
The Pimoroni IO Expander uses a programmable Nuvoton MS51 microcontroller, which is a cost effective and reliable means to provide the extra GPIO pins via the I2C interface. In fact, the custom firmware can be replaced with your own, should you have the need and the skills to do so.
The microcontroller provides a full extra 14 GPIO pins, which can be configured as “digital” and added to those already on the Pi. Or the IO Expander can be used to provide eight analog pins using the MS51’s built in 12-bit Analog to Digital Converter (2DC) and six Pulse Width Modulation (PWM). All 14 of the IO Expander ’s GPIO pins are pre-soldered and ready for use. Additional pins for a 3.3V output, GND and a voltage input (VIN) are present at the top and bottom of the pin columns.
Using the Pimoroni IO Expander
We tested the IO Expander using a Breakout Garden HAT on a Raspberry Pi 4 4GB with the latest version of Raspberry Pi OS. Installation of the Python module via cloning a Git repository was painless and, within a few minutes, we were able to complete a series of example projects that covered reading the changing level of an analog voltage source, controlling an RGB LED using PWM to mix the colors, and precisely controlling a servo using PWM.
The Python “ioexpander” module is expansive and will cover even the needs of the most demanding projects. But the module also abstracts the complexities away and thus enables learners to get to grips with the board.
Right now, the only supported way to get data from the IO Expander is via the Python module, but as this board uses I2C to communicate with the Raspberry Pi, it should be possible to read the data with any language that has I2C libraries, for example Node-RED.
Use Cases for the Pimoroni IO Expander
The IO Expander is a solid choice if your project needs analog inputs, PWM or just 14 more GPIO pins. With the IO Expander we can add analog inputs with just this board, making it an ideal drop in replacement for our Raspberry Pi Light Show project, or as a control board for servos to precisely control a robot arm project. But this board is also useful if you have used all of the GPIO pins on your Pi.
There is nothing to hate about this board. Small in size but big in features. We finally have a convenient and simple means to add analog input, a feature missing from all models of Raspberry Pi, and augment the existing complement of GPIO pins with extra PWM and digital pins. For just under $10 the IO Expander is a complete no-brainer, and should be in the bits box of every Raspberry Pi enthusiast.