Multi SPI displays

In my future project I have to use multi (3) 2 digits 7 segments display. For now, I have only one but like to add more.
Each display must be driven separately by Arduino Uno.
Display what I have now is with 74HC595 shiftregister - 2 per one set of 2 digits unit.
my sketch for one unit is as follow

#include <ShiftRegister74HC595.h>
#define SDI 3
#define SCLK 4
#define LOAD 5
// create shift register object (number of shift registers, data pin, clock pin, latch pin)
ShiftRegister74HC595<2> sr(SDI, SCLK, LOAD);   

int value, digit1, digit2, digit3, digit4;
uint8_t  digits[] = { B11000000, //0
					  B11111001, //1 
					  B10100100, //2
					  B10110000, //3 
					  B10011001, //4
					  B10010010, //5
					  B10000010, //6 
					  B11111000, //7
					  B10000000, //8
					  B10010000  //9
};

The number to display is called by function

void showNumber(int num)
{
    digit2 = num % 10;
    digit1 = (num / 10) % 10;
    //Send them to 7 segment displays
    uint8_t numberToPrint[] = { digits[digit1],digits[digit2] };
    sr.setAll(numberToPrint);
}

My question is - how to modified this sketch to include multi units.

First - your topic title is wrong, your displays are not SPI. By choosing the correct title, you increase your chances of getting help.

You have two options for adding next shift registers - you can chain them to existing ones if it have a data_output pin.

Or you can simple choose a separate set of three pins for each module. Any digital pins can be used for shift registers. In this case you have to define new shift register object for each module in the code.

Sorry, but if it is not I2C nor SPI - so what it is?

If I add 3 more pins - can I use the same library?

Once again sorry.

It has it own protocol, indeed similar to SPI, but different in that it does not require predefined pins.

Of course yes.
The only thing you need - call the second object with different set of pins:

#include <ShiftRegister74HC595.h>
// pins for 1st SR
#define SDI 3
#define SCLK 4
#define LOAD 5
// create 1st shift register object (number of shift registers, data pin, clock pin, latch pin)
ShiftRegister74HC595<2> sr(SDI, SCLK, LOAD);   

// pins for 2nd SR
#define SDI2 10
#define SCLK2 11
#define LOAD2 12
// create 2nd shift register object (number of shift registers, data pin, clock pin, latch pin)
ShiftRegister74HC595<2> sr2(SDI2, SCLK2, LOAD2);   

Thank you very much. I will try it.

Once you start adding numbers at the end of variable names, it's time to consider an array:

#include <ShiftRegister74HC595.h>
// pins for 1st SR
#define SDI0 3
#define SCLK0 4
#define LOAD0 5

// pins for 2nd SR
#define SDI1 6
#define SCLK1 7
#define LOAD1 8

// pins for 3rd SR
#define SDI2 10
#define SCLK2 11
#define LOAD2 12

ShiftRegister74HC595<2> srArray[] = {
  {SDI0, SCLK0, LOAD0},
  {SDI1, SCLK1, LOAD1},
  {SDI2, SCLK2, LOAD2}
};

Or, cascade them all together in one string:

ShiftRegister74HC595<6> srCascade = {SDI0, SCLK0, LOAD0};
1 Like

Thx a lot. I will try

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