I'm using an OLED (SSD1306) and MCP23x17 with a Nano ESP32 (both SPI).
I'm able to display "test7" on the OLED when the [display.] block is located before the if(!mcp.begin_SPI block, but not when placed after this block (as shown below).
Is there some conflict here that I'm not seeing?
#include <Adafruit_MCP23X17.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
// set pins on MCP23S17
const byte Sensor[5] = { 0, 1, 2, 3, 4 };
const byte Trigger[5] = { 8, 9, 10, 11, 12 };
//OLED display (width, height, D1(MOSI), D0(CLK), DC(MISO), RESET, CS)
Adafruit_SSD1306 display(128, 64, 38, 48, 47, 4, 13);
const byte CS_PIN = D10; //chip-select for MCP
Adafruit_MCP23X17 mcp;
void setup() {
Serial.begin(9600);
delay(1500);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
if (!mcp.begin_SPI(CS_PIN)) {
Serial.println("Error.");
while (1)
;
}
delay(1000);
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.println(F("test7"));
display.display();
delay(1000);
//set MCP PinMode for Sensor/Trigger
for (int i = 0; i < 5; i++) { mcp.pinMode(Sensor[i], INPUT); }
for (int j = 0; j < 5; j++) { mcp.pinMode(Trigger[j], OUTPUT); }
//set all Triggers to LOW/OFF
for (int k = 0; k < 5; k++) { mcp.digitalWrite(Trigger[k], LOW); }
}
void loop() {
Serial.println("loop");
}