Hi!
I'm building a MIDI controller - a sequencer - part of a audio/video display.
Finally, I got my MCP23S17s somehow to work, but there seems to be something missing.
The Setup:
-Arduino Uno R3
-One long strand of WS2801 bullet type RGB-LED Pixels (8 Rows with 44LEDs). Each cup uses 2 LEDs for illumination, one LED is on the back of the board in the space between cups.
LED-configuration 1/4 of the first strand: Wall-(0,1)-2-(3,4)-5-(6,7)-8-(9-10)-Wall
-One MCP23S17 (SPI-Version, datasheet here: http://ww1.microchip.com/downloads/en/DeviceDoc/20001952C.pdf) for each row, all the pins used as Inputs with pullUps activated.
-CS, CLK, MISO and MOSI start from pins 10-13 of the arduino and pass all MCPs
- A hefty 20A 5V power supply
The goal:
- Activating the microswitch in a cup should change the color of the two LEDs in the same cup from green to red
The problem:
- After connecting the sixth MCP: Several cups light up together, non-flickering. Connected individually or with less than six devices in the same bus every row works as it should.
- Check this Youtube video to see the problem
The code:
- Uses Cort Buffingtons MCP23S17 library with standard SPI and FastLED for the WS2801s
What i tried/did so far:
- Exchanging the MCP23S17
- Verified all address pins on the MCPs are correct
- Checked voltages for all components
- Tried to address 4 of the MCPs with a ChipSelect on Uno Pin 10 and four on Uno Pin 7 (changed the code accordingly), resulting in a single inactive row
- Bridging one or multiple MCPs
#include <FastLED.h>
#include <MCP23S17.h>
#include <SPI.h>
//LED-Parameter
#define DATA_PIN 3
#define CLK_PIN 2
#define LED_TYPE WS2801
#define COLOR_ORDER RGB
#define NUM_LEDS ((16*2)+(4*3))*8
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];
//Zeilen-PCBs
#define SPI_ChipSelect 10
MCP one(0,SPI_ChipSelect);
MCP two(1,SPI_ChipSelect);
MCP three(2,SPI_ChipSelect);
MCP four(3,SPI_ChipSelect);
MCP five(4,SPI_ChipSelect);
MCP six(5,SPI_ChipSelect);
MCP seven(6,SPI_ChipSelect);
MCP eight(7,SPI_ChipSelect);
int selmatrix[8][16];
void setup() {
delay(3000); // 3 second delay for LED recovery
one.begin();
two.begin();
three.begin();
four.begin();
five.begin();
six.begin();
seven.begin();
eight.begin();
for (uint8_t i=1; i<17; i++) {
one.pinMode(i, INPUT);
two.pinMode(i, INPUT);
three.pinMode(i, INPUT);
four.pinMode(i, INPUT);
five.pinMode(i, INPUT);
six.pinMode(i, INPUT);
seven.pinMode(i, INPUT);
eight.pinMode(i, INPUT);
one.pullupMode(i, HIGH);
two.pullupMode(i, HIGH);
three.pullupMode(i, HIGH);
four.pullupMode(i, HIGH);
five.pullupMode(i, HIGH);
six.pullupMode(i, HIGH);
seven.pullupMode(i, HIGH);
eight.pullupMode(i, HIGH);
}
FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalPixelString);
FastLED.setBrightness(BRIGHTNESS);
fill_solid( leds, NUM_LEDS, CRGB::Red);
FastLED.show();
delay(200);
fill_solid( leds, NUM_LEDS, CRGB::Green);
FastLED.show();
delay(200);
fill_solid( leds, NUM_LEDS, CRGB::Blue);
FastLED.show();
delay(200);
fill_solid( leds, NUM_LEDS, CRGB::Black);
FastLED.show();
}
void readTable() {
for (int i=0;i<16;i++) {
selmatrix[0][i]=one.digitalRead(i+1);
selmatrix[1][i]=two.digitalRead(i+1);
selmatrix[2][i]=three.digitalRead(i+1);
selmatrix[3][i]=four.digitalRead(i+1);
selmatrix[4][i]=five.digitalRead(i+1);
selmatrix[5][i]=six.digitalRead(i+1);
selmatrix[6][i]=seven.digitalRead(i+1);
selmatrix[7][i]=eight.digitalRead(i+1);
}
}
void clearDisplay(boolean refresh) {
for (int k=0;k<NUM_LEDS;k++){
leds[k]=CRGB::Black;
}
if (refresh){
FastLED.show();
}
}
void writeDisplay() {
clearDisplay(false);
int led=0;
CRGB c;
for (int h=0;h<8;h++) {
for (int j=0;j<16;j++) {
if (selmatrix[h][j]){
c=CRGB::Green;
}
else {
c=CRGB::Red;
}
if (((j+1)%4)!=0){
leds[led]=c;
leds[led+1]=c;
led+=3;
}
if (((j+1)%4)==0){
leds[led]=c;
leds[led+1]=c;
led+=2;
}
}
}
FastLED.show();
}
void loop() {
readTable();
writeDisplay();
}