I2C 8-CH relay Module, I2C Keypad, I2C LCD project needs help

I have a machine I want to build for inserting document stubs into an envelope. I have a broken commercial version that I have to remove the electronics in it. I want to use a MEGA2560 and , using its I2C port and the numerous I2C devices, to monitor its operation.
I have no interest in the codes that blink the I2C relay modules. I have collected enough code to cobble together a sketch to turn on each relay on, but they wont stay on when I turn on another relay.
I found code for an I2C Keypad (Rob Tilliart's among others) and the ever-present I2C-LCD (20x4) Character screen and have a great start when I combined the two together.
However, my question is, how can I go about adding in a "toggle" section to the code so that once a relay is turned on (via the I2C Keypad) that the (I2C) relay engages and a corresponding status is displayed on the 20x4 character LCD?
I do this to cut down on the number of pins used to energize the relays via a key press (displaying this status on the LCD) since I also need to monitor the paper path sensors of the inserter so I can track what each piece of paper is advancing through the machine as it is getting inserted into the envelope and to then seal the envelope and discharge it into an awaiting bin.
I did find a pin to pin variance of what I want to do, but I can't figure out how to do it in an I2C environment. I want to save on the pin count of pins used of the Mega2560.
Any I ideas?

A Mega has 54 I/O pins. Why take on the trouble with I2C relays? Use 8 different outputs.

1 Like

Post a link to the relay board giving technical details. I believe each time you write to it you need to turn on all the relays you want, if you do not turn them on they will go off. For some clarification look up a PCF8574 and how it works. Hint you will probably need to keep either a mirror image of the outputs or read it and mask in or out what you want.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.