Maxxing out a Mega with GPIO

Feasibility question incoming...

What's I've done so far:

  • I've run a lot of CAT6 and CAT5 cables around the house, to windows, doors, ceilings, floors.
  • I have started to install various sensors, wired back to a single Arduino Mega.
  • I've made a little interface board that takes 8x 8P8C connectors (basically ethernet connectors but used for general IO rather than ethernet) and connects them to an Arduino Mega. I'm using 2 cores out of the 8-core CAT5 for power, switchable between 5V and 12V.
  • Also I'm using a W5100 board connected via SPI lines to the Mega, and sending messages in and out via MQTT. (Yes I know I could use W5500 or even W7500 but - I have quite a few of these little W5100 boards kicking around.)

What I'd like to do
However I'd like to up my game a little, and increase my port count to 24 ports.
So that's 6 cores of data plus 2 cores of power per port.
24x 6 = 144.

I have a bucket full of MCP23017 which I've not yet played with, and I'd like to make a main board for the Mega, with 3x sub-boards each having 8x ports. They would be connected to the main board with just power and I2C. Then the sub-boards would house the parallel IO expansion chips.

Each MCP23017 provides 16 general purpose IO, with 3x I2C address lines giving a maximum of 128 IO.

Plus the IO on the Mega - at least, any remaining IO that isn't used already for SPI (the Wiznet W5100 board).

By my calculations, it should be possible to achieve 144 general purpose IO plus SPI for the ethernet connection, plus a few spare for e.g. a display. I guess I'd need to be careful with I2C addresses, making sure I chose a display with a configurable address so it doesn't clash with any of the MCP23017s.

It's not something I have played with yet, so I don't know the exact limitations.

Things that seem a bit iffy

  • So far I've run ultrasonic distance sensors over 30m of CAT5 back to an Arduino - 3 of them to be specific - and had absolutely no issues with reliability. It has been running for a few years. But maybe if I introduce more IO then I'm going to get into power supply issues pretty early on. Voltage drop was always something that concerned me, however the sensors I want to use really are low current and so Vdrop doesn't seem to be such a problem. Most of the sensors will be alarm sensors that run at 12V and provide dry-contact outputs, or even just 2 cores of the cable used for a door sensor (dry contact) - so, pull-up resistors on the controller end and that's it. Maybe also a number of PIRs running at 5V. So I don't think it would be a huge issue. At least an interesting experiment.

Questions

  • I'd be interested if anyone has any thoughts on the above idea.
  • Do you foresee any limitations I haven't considered?
  • Should I really be considering another platform for this? I've had great success and reliability with the hardware I've used so far, namely the "Arduino Mega Core 2560" which is a small dev board, plus the W5100 ethernet, both of which I have included in my own parent board. Hence wanting to consider this.

Memory limitations, sure.
But, if your code is compact, you might get away with even more. It all depends what you're actually doing with the data.

You can 'bank switch' the MCP23017 devices by actively controlling an address pin, so the number of MCP23017's isn't limited to 8, you just need to manage the switching consistently in code. It would work like this:

  • use A1 and A0 as normal on each MCP23017 in a set of 4;
  • wire A2 on those devices to a pin on your Mega
  • set the line low and talk to devices 0x20 through 0x23
  • set the line high to 'deselect' them, and repeat this whole sequence for 4 more. Repeat for as many sets of 4 as needed. Keep in mind, the high 4 addresses can't be used for anything, because effectively, all your 'unselected' MPC23017 chips are overlaid in that 4-address space. For that reason, doing any 'autoscan for devices on I2C' would likely have problems. For the same reason, be sure to pick an LCD with an I2C address that's compatible. The common PCF8574 is addressed at 0x20, but the PCF8574A is at 0x38, so buy that one.

This addressing trick will work. Why one would do all this, instead of implementing a distributed network of RS485 devices is beyond me, but if you want to go down this route it's doable.

By the way, say goodbye to your Mega if you ever have a close-by lightning strike. All those long antennae will likely fry it, or at least a random number of input pins.

1 Like

At some point, of course, you'll run into problems with the number of devices on the clock and data pins. It might be worth looking at bus repeaters sooner rather than later.

Also, there are multiplexers to allow multiple devices with the same address on the bus:

1 Like

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