AB Electronics IO Pi 32 Review
The IO Pi is a 32 channel digital expansion board from AB Electronics designed for use on the Raspberry Pi computer platform. The board is based around the MCP23017 16-bit I/O expander from Microchip Technology Inc. A pair of MCP23017 expanders are included on the board allowing you to connect up to 32 digital inputs or outputs to the Raspberry Pi.
Whilst we have used similar functionality in our smart home for many years now, the hardware we are currently using for the digital IO computer interface is no longer available and supported. We thought it was time that we found an alternative solution, one which would also allow us to expand the number of digital inputs available. Our modular design enables us to simply swap in this IO board for the older one that we are currently using.
We have chosen this specific device for this review/project because it enables us to connect a large number of digital devices to our Home Control System (HCS) using wires. Whilst running these wires can often be a time-consuming and challenging task, we have found this provides a huge number of advantages and it is our preferred way to enable home automation:
- It enables low cost, 'off the shelf' digital sensors such as PIR sensors, smoke alarms, door contact sensors, and dusk/dawn sensors to be used.
- It provides much better performance and much lower latency.
- It uses much less power and doesn't require any batteries to be replaced.
- It is much more reliable than any wireless technology such as Z-Wave.
- It is future-proof compared to all the other standards and protocols used in home automation.
- It is more secure.
- All of the data generated by this project remains under our control and stays within our home.
As you will see from our design, we have adopted a modular approach, to make trouble-shooting and any fault repairs a much simpler task. In addition this design is extensible and could support up to 128 digital inputs. Whilst this may sound like a lot, we have already connected every door and every room PIR sensor up using this approach in our current home. If this is not enough, we can simply duplicate the hardware to provide another 128 digital inputs.
The I2C address bits are selectable using the on-board jumpers. The MCP23017 supports up to 8 different I2C addresses so with two MCP23017 devices on each IO Pi you can stack up to 4 IO Pi boards on a single Raspberry Pi giving a maximum of 128 I/O ports. The address configuration is described on the AB Electronics website.
The board is physically installed by mounting it onto the RPi's GPIO pins. This IO Pi expander is powered through the host Raspberry Pi using the GPIO port and extended pins on the GPIO connector allow you to stack the IO Pi along with other expansion boards.
The IO Pi includes a 5V port that can be isolated from the Raspberry Pi via an isolation jumper (circled in photo below) so you can use a separate higher current power supply to power the IO Pi reducing the load on the Raspberry Pi. The use of an external supply is recommended if you plan on connecting more than one IO Pi to your Raspberry Pi.
The PCB conveniently exposes 4 rows of 8 pins, so we will solder four 10-way ribbon cables directly to this board. They will share a common ground and +5V supply.
There are two ways to connect a switch to the IO Pi:
- Connect it between an input pin and 5V or an input pin and ground. If you use the 5V method then you will need a pull-down resistor connected between the input pin and ground. The inputs on the IO Pi contain a very small amount of capacitance and when you release the switch even though the 5V is no longer connected there will be a small charge remaining on the pin which is enough for the IO Pi to get confused and not know if it should read the pin as on or off. A pull-down resistor takes away the remaining charge by allowing it to flow to ground.
- Connect the switch between the input pin and ground. Normally you would need to use a resistor to act as a pull-up so there is a constant 5V supply to the pin when the button is not pressed but the IO Pi comes with pull-up resistors inside of the chip which you can enable or disable.
The way our optically isolated input boards work means that they need to be fitted with a 47kΩ pull-down resistor.
On the end of each ribbon cable is a 10-way plug as shown here (but not with plugs on each end as shown here).
Only 8 of the 10 wires are connected directly to the board. The 0V and +5V wires are extended off to the 5V dc power supply.
We intend to connect all of our sensors using our Home Control System (HCS) using our generic optically isolated input board. These provide a standard 4-pin connector for many types of devices and basically maintain the modular nature of our design. If something breaks, it is very quick and easy to replace each circuit board.
Raspberry Pi Setup
The IO Pi 32 datasheet describes the I2C address configuration using jumpers and this document can be found on the AB Electronics website. We have used the default settings of IC1 port = I2C Address 0x20 and IC2 port = I2C Address 0x21:
Firstly, make sure everything on your Raspberry Pi is up to date with the commands:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
Then reboot the RPi once this has completed.
You need to install the i2c-tools utility:
sudo apt-get install python-smbus
This also installs the 12c-tools package.
We need to modify the black list file:
sudo vi /etc/modprobe.d/raspi-blacklist.conf
We comment out these two lines with a #:
We modify the modules file:
sudo vi /etc/modules
Adding a line to end of file:
To avoid having to run the I2C tools at root add the pi user to the I2C group:
sudo adduser pi i2c
We then attached the IO PI 32 board onto the RPi and restarted.
Using the i2cdetect command, we can now check the board has been detected:
We had the option of using either Python or Java in this type of application. Our software has one simple objective to achieve and that is to send an events to our Home Control System (HCS) every time an input changes state. In order to handle the numerous inputs and potentially frequent input state changes, the software will be multi-threaded.
For the GPIO connected board we are using our own Java code. This is because we have created a generic set of classes for use on all of our slave HCS processor and this also does things like performance monitoring, heartbeat generation, etc.
The core Java code for monitoring the GPIO pins is based around Pi4J and basically sets up 8 pins as outputs and 8 pins as inputs. In reality, we only have 5 outputs available because 2 are used for I2C interface and one for the 1-Wire functionality. This isn't a problem because this project only uses one output pin to drive an LED as a visible heartbeat indicator.
We have on DS18B20 1-Wire sensor connected on this project to monitor the temperature within this shelf.
The completed Java software will be made available here very soon.
Initially, we did our testing using Python and the AB Electronics python library to talk to the IO Pi. You can download the library from github using the following commands in a terminal:
git clone https://github.com/abelectronicsuk/ABElectronics_Python_Libraries.git
You will need to tell python where you download the AB Electronics python library by adding it to PYTHONPATH:
We started with the AB Electronics tutorial, to confirm everything was working as expected.
We then tested the AB Electronics AB Electronics input tutorial. There are two ways you can connect a button to the IO Pi. You could connect it between an input pin and 5V or an input pin and ground. Our optically isolated input board uses the ILQ74 IC to connect the input pin to +5V when the input is active and we have onboard pull-down resistors.
The completed Python software will be made available here very soon.
All the hardware described here is mounted on a 19" rack cabinet shelf. This makes it very 'plug and play' and also makes it very easy to test. The shelf has two main connections, 12V dc power and an Ethernet network cable.
This is the latest view of our 19" rack shelf. We have just about finished building all of the required optically isolated input boards. We are now using five, four connected to the IO PI 32 and one connected directly to the Raspberry Pi GPIO pins via our Raspberry Pi Header Board. The final thing yet to be completed is all of the ribbon cables between the boards.
This type of home automation interface was pretty much where we started about ten years ago. Multi-channel, digital inputs should be the entry point for anyone looking to make their home smart. This type of project represents the most gain for the least amount of investment. It is also a wise investment by being much more future-proof than any of the wireless technologies currently in use and by offering the best performance and reliability.
We have been impressed with the IO Pi device. Whilst there looks like a lot of wiring and soldering in this project (and there is!) we have built a premium grade solution and something much simpler and cheaper could be built around this device if required. The performance of the device has proven to be very good and we have very low latency times when checking the digital inputs for changes in values.
It is worth noting that the new Raspberry Pi B+ has a more GPIO than the older models and provides an alternative method to delivering this kind of capability. We have also developed a header board that works with our optically isolated input boards.
The typical costs for this type of project are:
- Raspberry Pi = £28.00
- 8GB SD card =£5.50
- AB Electronics IO Pi 32 = £20.39
So for not a lot of money (~£54), you get 32 channels of smart home digital input and output capability. This would buy you just 2 wireless sensors using technology like Z-Wave. When you network every door in your house, as we have done, this is really the only cost-effective way to do it. And that is before you get onto the latency, performance and security issues. We have also used this design to connect up a PIR sensor in every room in our house.
On top of this you have to add the 8-channel 12V interface boards but, we have built these for about £24 each (£ 3 per sensor). You don't have to use these though.
This design means you can use very low cost reed relays in door frames as door contact sensors and you can also interface very cheap, standard PIR sensors. Basically anything that provides a switched 12V dc output can be connected.
The 19" rack shelf was about £18 from Pro Audio Stash.