In a previous adventure, I discussed using I2C to read from sensors. I also wrote about how I utilize the Raspberry Pi GPIO interface with the Waveshare 8-channel relay expansion board to drive the sprinkler valves that control our crop irrigation system.
This time, I would like to discuss the use of I2C to communicate with remote I/O expansion devices.
The SparkFun Relays
In my original chicken coop project, I successfully used a SparkFun quad relay card to drive the actuators that controlled the coop door, as well as the coop light and electric fence. SparkFun makes a few variations of this device:
COM-15093 - Single relay
COM-16566 Quad relay
COM-16810 DUAL SSR
They almost work the same way, but not exactly. I was able to cobble together a universal plug-in for my PiotServer, but it would have been nicer if SparkFun had used the same API for all their relay devices.
But as I mentioned in part 4 of this series, I decided to move away from the 3V Qwiic I2C system to the more robust nodeLynk 5V system using the Molex 2.54mm connectors. So let’s look at the other options I came across.
More I/O
There are a couple of great I/O expander chips available for the I²C bus. Some of the more popular ones include the
MCP23008 - 8-Bit I/O Expander
PCA9536 - 4-Bit I/O Expander
PCA9671 - 16-Bit I/O Expander
TCA9534 - 8-Bit I/O Expander w/ Interrupt
These devices are similar in concept but different enough that it makes sense to write distinct drivers for each.
National Control Devices (NCD) offers a high-quality series of boards that use the MCP23008 chip to drive both mechanical and solid-state relays, as well as FETs. One of my favorites is their single-channel 30-amp relay board. A nice thing about the NCD design is that it makes the unused channels of the MCP23008 accessible via a screw terminal connector. I like the way these boards are configured and their ruggedness—a perfect fit for our agricultural projects.
NCD also has a few mini modules that are based on the PCA9536 Remote 4-Bit I2C I/O Expanders;
One thing to note when writing code for both the PCA9536 and the MCP23008 is that the I/O pins can be configured for either input or output, and that you should write your code generic enough to handle other configurations using these chips.
Iowa Scaled Engineering
Another very cool I²C board I like is the I2C-RELAY16, created by two model railroad enthusiasts, Nathan Holmes and Michael Petersen, at Iowa Scaled Engineering. This board is based on a PCA9671 16-bit I/O expander and piggybacks on many commonly available 16 SPDT relay modules, such as the SainSmart or its PRC clones.
A Qwiic connector version is also available from Iowa Scaled Engineering. Since the PCA9671 can operate from 2.3 V to 5.5 V, it’s easy enough to hack together a nodeLynk Molex 2.54mm to Qwiic cable to go directly to it from the nodeLynk 5V system.
Even More GPIO
The other device I should mention is the TCA9534 8-bit I/O Expander. Sparkfun put one of these on a breakout board with easy-to-use latch pins. You don’t have to use the Qwiic connector, and since the TCA9534 can operate with a power supply voltage ranging from 1.65 V to 5.5 V, you could easily wire a nodeLynk Molex 2.54mm cable to it.
The device is easy enough to write a driver for, and Sparkfun did a good job of explaining it in their hookup guide.
Well done.