MCP23S17 ? Which library?

I'm working on a moderately complex controller to run a model railroad.
Planning to base the controller on the Heltec ESP32 V3: https://heltec.org/project/wifi-kit-32-v3/ I need just about 32 IOs: about 8 inputs to read detectors and about 24 relays to control power and switches.
Naturally I'm looking at MCP23S17s; reading posts, watching videos, looking at library documentation.

Q1: why are there SO MANY MCP23S17 Arduino and MC libraries?? There must be at least a dozen or more

Q2: Which one should I use? One that's easy to use - with DUAL MCP23S17s, most lightweight and well vetted?

Q3: Where can I find an example that include CIRCUIT DIAGRAMS for DUAL MCP23S17s? There's tons and tons and tons of code examples to read but very few circuit diagrams!

Many thanks to all y'all !

I start searching for vetted libraries at reference.arduino.cc

Next stop is arduinolibraries.info

1 Like

Try 'DUAL MCP23S17' as a search term.

1 Like

Q1: start with the first one.
compile the hello world
Note SRAM and Progmem.

repeat that with the next 3 and you have the library with the smallest footprint.

Alternative:
Write down your requirements.
Check the datasheet of the MCP23S17 and only implement the real needed functionalities.
No library will be smaller then your own optimized code with just the parts you really need.

1 Like

If you're not looking for interrupt capability a couple of SIPO and PISO shift registers could also do the job - at a higher chip count.

1 Like

Personally, I would use a MCP23017. It has an I2C interface instead of SPI, which I find easier to work with. There are lot so libraries out there to control them and there are three address jumpers to allow you to wire multiple chips onto the same I2C circuit. Take a look at the Adafruit MCP library has code for both and some great examples about using multiple chips on the same circuit and how to wire with the address pins.

1 Like

@ryancasler
there are lot of alternatives of different port expanders. Without context I wouldn't dare to vote for one or the other.
When @DirkBlaze is using already SPI in his setup, it's a good idea to stick with a SPI IC. Even stand alone (with no other devices) a SPI implementation will use less software resources on an AVR than a I2C implementation (haven't checked the ESP so far) . Further more SPI will be faster out of the box. And don't forget, that the MCP23S17 has address pins, so you can use several MCP23S17 with one CS line if needed.

1 Like

The Heltec ESP32 I'm using does have an OLED display which, I think, uses SPI under the Heltec libraries, not certain

based on the schematic it looks like an I2C OLED:

But It seems that the used GPIO17 and GPIO18 are not available on the header, just as "Testpads" - I can't locate these testpads on the image.

1 Like

@noiasca 17 and 18 being OLED_SDA OLED_SCL, I would guess they are connected directly to the OLED display.

My project for a CNC conversion at
http://www.thebox.myzen.co.uk/Hardware/CNC_Conversion.html
Uses two MCP23S17 chips, the code and schematic show you how it is done.

1 Like

The reason they are using SPI mode is because the steppers are connected to one of them. I2c is probably too slow to get the timing right. But SPI should be fast enough.

So, are you trying to recreate the CNCs firmware? No offense but that's going to be a daunting task for someone who doesn't know how to program for an MCP chip. You might want to start with something simpler.

The OP said

Yes I did, it was some years ago. I was making the CNC because I wanted to make this project,
http://www.thebox.myzen.co.uk/Hardware/Hexome.html
and I knew I would need a CNC miller to make the PCB.

The schematic was just to show the OP how to connect two of these devices together as I understood that is what he wanted. I have used the I2C version of the chips occasionally but in this project, as you said, I wanted the speed.

1 Like

Building a CNC or "converting" one, including the very neatly done circuit on a perf board is a really impressive project. Many kudos.

If you don't need the speed of SPI, the I2C version is a lot simpler since you don't need to screw with the Chip Select pin. You can just wire them both and set the address and be done with it.

You could also consider wiring the other pins with a different esp32 instead of using a GPIO expander. You can communicate between the ESP32s using the ESP-NOW. That way you don't have to run the wiring all to 1 location but can wire everything to 3 locations.

With the MCP you're going to have to keep all 3 boards very close to one another unless you use something like an LTC4311 I2C active terminator. SPI and I2C are designed for on-board communication and not over a distance.

1 Like

Some very good ideas which have crossed my mind.

1 Like

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