Basically, if I comment out the line instantiating the Adafruit_Keypad, the sketch starts the display as normal and prints a timestamp to serial every 2 sec. If I uncomment the delay(2000); line before display.begin, it also starts and gets to the loop, though I see some "⸮⸮⸮⸮⸮⸮⸮⸮" printed to serial at startup. Adjusting the delay time or rearranging the order of things in setup() can make the issue come and go.
Sometimes, just changing that delay value or adding additional Serial.printlns makes the board un-flashable (without double-pressing reset). I'd like to see if there's a "correct" way to use these together, to avoid encountering these issues. I noticed someone else had mentioned reset delays with the SSD1306 board here: viewtopic.php?f=47&t=172124a&p=840479&hilit=SSD1306#p840207
Here's my minimal reproducing example:
- Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include "Adafruit_Keypad.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// display
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
//In order of breakout board:
//CS -> D13
//RST -> D12
//D/C -> D11
//CLK -> SCK
//DATA -> MOSI
//VIN -> 5V
//3.3Vo -> none
//GND -> GND
#define OLED_CS 13
#define OLED_RESET 12
#define OLED_DC 11
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
&SPI, OLED_DC, OLED_RESET, OLED_CS);
// Keypad
const byte ROWS = 4; // rows
const byte COLS = 4; // columns
//define the symbols on the buttons of the keypads
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte colPins[COLS] = {10, 9, 7, 5}; //connect to the first 4 pins on keypad board L->R (not counting first and last pad)
byte rowPins[ROWS] = {0, 4, 6, 8}; //connect to the last 4 pins (not counting first and last pad)
//// Initialize Adafruit_Keypad class
Adafruit_Keypad customKeypad = Adafruit_Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
//delay(2000);
Serial.println("Starting up");
// 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
}
}
void loop() {
// Clear the buffer
display.clearDisplay();
// Draw a single pixel in white
display.drawPixel(10, 10, SSD1306_WHITE);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(2000);
Serial.println(millis());
}
I've also attached a fritzing image of the connections as well.