the MCP23017 and an RGB panel with smartMatrix3 software do run together.
using pins 19 and 18 (a4 or a5) for the communication on the teensy and mcp23017. for anyone trying the same, I struggled to get it work at first. I spent ages and eventually found that I needed to place a 47kohm resistor from pin 19 to 5V, and pin 18 and 5v. this one took me a while to find, and the mcp23017 wouldn’t work without the resistors.
the code which is just a combination of example sketch ‘blink without delay’ and the adafruit mcp23017 example sketch ‘toggle’ is pasted below. thanks guys, great to have a responsive forum to help me with this stuff.
/*
- teh teensey, the rgb panel, the mcp23017 all work together. no flickering on the screen
-
-
*/
#include <SmartLEDShieldV4.h> // comment out this line for if you’re not using SmartLED Shield V4 hardware (this line needs to be before #include <SmartMatrix3.h>)
#include <SmartMatrix3.h>
#include <Wire.h>
#include “Adafruit_MCP23017.h”
Adafruit_MCP23017 mcp;
#define COLOR_DEPTH 24 // known working: 24, 48 - If the sketch uses type rgb24
directly, COLOR_DEPTH must be 24
const uint8_t kMatrixWidth = 32; // known working: 32, 64, 96, 128
const uint8_t kMatrixHeight = 32; // known working: 16, 32, 48, 64
const uint8_t kRefreshDepth = 36; // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 4; // known working: 2-4, use 2 to save memory, more to keep from dropping frames and automatically lowering refresh rate
const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_MOD16SCAN; // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels, or use SMARTMATRIX_HUB75_64ROW_MOD32SCAN for common 64x64 panels
const uint8_t kMatrixOptions = (SMARTMATRIX_OPTIONS_NONE); // see SmartMatrix - Overview for options
const uint8_t kScrollingLayerOptions = (SM_SCROLLING_OPTIONS_NONE);
const int ledPin = 13; // the number of the LED pin
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;
SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer1, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);
SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer2, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);
SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer3, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);
SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer4, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);
SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer5, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);
void setup() {
mcp.begin(); // use default address 0
Serial.begin (9600);
mcp.pinMode(0, OUTPUT);
//pinMode(13, OUTPUT);
// Variables will change:
pinMode(ledPin, OUTPUT);
matrix.addLayer(&scrollingLayer1);
matrix.addLayer(&scrollingLayer2);
matrix.addLayer(&scrollingLayer3);
matrix.addLayer(&scrollingLayer4);
matrix.addLayer(&scrollingLayer5);
matrix.begin();
scrollingLayer1.setMode(wrapForward);
scrollingLayer2.setMode(bounceForward);
scrollingLayer3.setMode(bounceReverse);
scrollingLayer4.setMode(wrapForward);
scrollingLayer5.setMode(bounceForward);
scrollingLayer1.setColor({0xff, 0xff, 0xff});
scrollingLayer2.setColor({0xff, 0x00, 0xff});
scrollingLayer3.setColor({0xff, 0xff, 0x00});
scrollingLayer4.setColor({0x00, 0x00, 0xff});
scrollingLayer5.setColor({0xff, 0x00, 0x00});
scrollingLayer1.setSpeed(10);
scrollingLayer2.setSpeed(20);
scrollingLayer3.setSpeed(40);
scrollingLayer4.setSpeed(80);
scrollingLayer5.setSpeed(120);
scrollingLayer1.setFont(gohufont11b);
scrollingLayer2.setFont(gohufont11);
scrollingLayer3.setFont(font8x13);
scrollingLayer4.setFont(font6x10);
scrollingLayer5.setFont(font5x7);
scrollingLayer4.setRotation(rotation270);
scrollingLayer5.setRotation(rotation90);
scrollingLayer1.setOffsetFromTop((kMatrixHeight/2) - 5);
scrollingLayer2.setOffsetFromTop((kMatrixHeight/4) - 5);
scrollingLayer3.setOffsetFromTop((kMatrixHeight/2 + kMatrixHeight/4) - 5);
scrollingLayer4.setOffsetFromTop((kMatrixWidth/2 + kMatrixWidth/4) - 5);
scrollingLayer5.setOffsetFromTop((kMatrixWidth/2 + kMatrixWidth/4) - 5);
scrollingLayer1.start(“Layer 1”, -1);
scrollingLayer2.start(“Layer 2”, -1);
scrollingLayer3.start(“Layer 3”, -1);
scrollingLayer4.start(“Layer 4”, -1);
scrollingLayer5.start(“Layer 5”, -1);
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
mcp.digitalWrite(0, ledState);
}
}