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!
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.
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.
@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.
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 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.
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.