Hi, I am trying to build a pool controller based off of one bscuderi13 built to tie into SmartThings. Now his setup uses only 4 outputs to control two valves using relays, with 1 relay for open, and the other for the close.

I plan on driving 4 valves, for a total of 8 relays. I wish to use an MCP23008 to unload the Photon of directly driving the relays.

How would I address those pins using rickkas7 MCP23008 library and integrating that into bscuderi13’s code below?

How would they be defined by #define? How would you reference say GP7 on MCP23008 to be driven low to actuate a relay on a SainSmart 8 relay board?

My code also will be using the I2C pins D0 and D1 for reading other sensors and future chemistry control.

Post your forum Tips and Tricks here!
Do you have some simple but useful tip that will save users time, or make their forum use much more rich with features? Post them here! Tips and Tricks should be short and to the point. Also, please don't post questions here regarding anything other than the tips and tricks posted. I will organize and link to each relevant tip from this first post as the thread builds. If you have a way to improve a tip or trick, please make a suggestion. Thanks!
P…

Developing software is not only about putting lines of code - found somewhere else - together but about reading these lines, understanding what they do and why and then use that knowledge to adapt the code to fit your own needs.
If you have problems understanding the what and why, you can aske specific questions about that, but just asking: “What do I have to change to make it work?”, is not really the way we tend approach things here in this community.

Just one thing about

rx78nt1alex:

How would they be defined by #define?

I would not. I would use arrays and enums and stay away from #define whenever possible.
And I would also try to reduce all these copy-pasted code blocks and try to condense their intended behaviours into reusable functions.
Having a quick look at that code I’d detect potential to reduce the length of that code to a third/quater or even less of what it currently is.

I saw your instructions, so instead of the following for calling out relays that were located on the

digitalWrite(poollight, HIGH)

for a typical pin on the Photon,
I’d just say

gpio.digitalWrite(0,HIGH)

only after the global object to initialize and having void begin(); in setup to start the I2C interface.

In the setup itself for the pool control, I only need to say

gpio.pinMode(0, OUTPUT);

to define the pin and the mode, then later, anywhere else, I should be able have the program to call out pin 0 on the MCP23008 to HIG, just as I would a regular pin on the photon, as shown in your example? I will experiment with your examples once my MCP23008 comes in.

ScruffR, no doubt, I’m going to clean this thing up, but more likely, rewrite it entirely. I only posted it as the example of what I’m trying to do and make sure I understand the MCP library correctly.