I have used Nick Gammon's (MAX7219) and (bitBangedSPI) libraries to drive SPI 7-segment 8 digit led modules successfully from the Arduino Uno. I would like to extend the number of Slave Select (CS) choices by using the MCP23S17 chip. The Mcp23s17 libraries to use might be https://github.com/dreamcat4/Mcp23s17 or https://github.com/MajenkoLibraries/MCP23S17. I have found the stackExchange entry How do you use SPI on an Arduino? to be helpful and this entry to be helpful http://www.ermicro.com/blog/?p=1050, but all the examples just turn on LED lights, not digits of 7-segment led modules.

I realize I might have to modify the MAX7219 and bitBangedSPI libraries where the digitalWrite command is used. However, I'm not sure how to modify or drive these 7-segement modules using the MCP23S17 chip.

A skeleton script to display PI selected on pin 6 on the Uno and address 0x0 of the MCP23S17 is shown below. I would like to choose which pinout to utilize as well but am not sure how this would be coded. enter image description here

#include <SPI.h>
#include <bitBangedSPI.h>
#include <MAX7219.h>
// Mcp23s17 library available from https://github.com/dreamcat4/Mcp23s17
#include <Mcp23s17.h>

// Wire up the SPI Interface common lines:
// #define SPI_MOSI             7 //arduino   <->   SPI Master Out Slave In   -> SI  (Pin 13 on MCP23S17 DIP)
// #define SPI_MISO   not used 12 //arduino   <->   SPI Master In Slave Out   -> SO  (Pin 14 on MCP23S17 DIP)
// #define SPI_CLOCK            8 //arduino   <->   SPI Slave Clock Input     -> SCK (Pin 12 on MCP23S17 DIP)

// Then choose any other free pin as the Slave Select (pin 10 if the default but doesn't have to be)
#define MCP23S17_SLAVE_SELECT_PIN  6 //arduino   <->   SPI Slave Select           -> CS  (Pin 11 on MCP23S17 DIP)
// Up to 8 MCP23S17 devices can share the same SPI bus and slave select pins.
// Assign each chip a unique 3-bit device address (by setting the A2,A1,A0 pins)
// Then below, device address is optional 2nd parameter to the constructor fn...
// MCP23S17 Mcp23s17_0 = MCP23S17(MCP23S17_SLAVE_SELECT_PIN,0x0);
// ...
// MCP23S17 Mcp23s17_7 = MCP23S17(MCP23S17_SLAVE_SELECT_PIN,0x7);

// Instantiate a single Mcp23s17 object
MCP23S17 Mcp23s17_0 = MCP23S17(MCP23S17_SLAVE_SELECT_PIN,0x0);
const byte chips = 1;
static char outputBuffer[20]; // outputBuffer[] likely 2x the size it needs to be.

 // 1 chip, bit banged SPI on pins 6, 7, 8

MAX7219 display(chips, 6, 7, 8);  // Chips / LOAD / DIN / CLK
void setup()
    // Set all pins to be outputs (by default they are all inputs)

    float pi = PI;
    dtostrf(pi, 7, 7, outputBuffer);

}  // end of setup

void loop() { }

An example of the 8-digit 7-segment display. They are available on Amazon, Ebay, AliExpress etc. This one has 0.33 inch digits; other modules are 0.56 inch digits.

enter image description here enter image description here

  • 1
    It isn't really clear to me what you want to do here. Do you want to just use the pin extender for CS lines? Then you just need to go into those libraries and rewrite to call whatever function writes a pin high or low on the extender instead of whatever digitalWrite it is calling now. If you want to try to bitbang a completely separate SPI bus out of the extender then that's going to be a bit harder. Why are you bit-banging SPI instead of using hardware in the first place?
    – Delta_G
    Commented Jun 3, 2018 at 16:53
  • Answering your second question first -- I have used all the hardware SPI pins for multiple displays which are daisy-chained. Bit-banging allows me to extend to additional displays but takes up too many pins needed for other devices. The MCP23S17 seems like the logical choice for extension. I'm a user of the led control libraries, not a library author.
    – GoEphs
    Commented Jun 3, 2018 at 17:42
  • You can use the three hardware SPI pins to connect to as many displays as you want. The SPI bus is meant to be used by many things in parallel.
    – Delta_G
    Commented Jun 3, 2018 at 18:47
  • I'm curious how "as many displays as you want" is defined. I have 18 8-digit display modules to control. Daisy chaining the cheap 8-digit modules doesn't work well past four and certainly not 18.
    – GoEphs
    Commented Jun 3, 2018 at 19:14
  • it is unclear what 7-segment 8 digit led module you are using? .... is it just an LED array without any drivers/decoders?
    – jsotola
    Commented Jun 3, 2018 at 19:47

3 Answers 3


I'm not 100% on what you want to do but I have used both the chips you seem to want to do it with.

The MAX7219 can control 8 7Segment displays. I don't remember it being an SPI device, you just set the pattern you want in the registers and off it goes. (It could be that is used such a high level abstraction that I didn't realise it was SPI)

The IOX chip you are referring to is quite similar in behaviour, you setup the registers and away it goes.

On the surface it appears you can do what you want, but I suspect you will hit timing issues unless you want very static displays (maybe < 1FPS). The time it takes you to establish the correct settings on the IOX chips will be the limiting factor.

You might want to look at the I2C version of the IOX which will require just 2 pins to connect to up to 7 ICs.

Alternatively use a network of microprocessors to each drive the maximum number of MAX7219s that they can, such as Nanos, ESP8266-12/NodeMCU, etc.


The MAX7219 chip is designed to be daisy chained -- connect Dout to the Din of the next MAX7219 (see the No-op Register section in the data sheet). I'm not sure if there is a limit to the number that can be daisy chained.

In fact Nick Gammon's library appears to support this. The "chips" parameter is the number of daisy chained MAX7219s.

The MAX7219 is does not use SPI. As I understand it the SPI/bitBangedSPI libraries are used as a convenient way to send the data bits with a synchronized clock.


Just daisy chain the MAX7219s as already mentioned. I use SPI directly with the chip all time, it works great with the default modes - 4 MHz clock, Mode 0, MSBFIRST. Many libraries use software SPI to talk to it, which I think is just a waste of the SPI hardware in the '328P family of chips.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.