Hardware: MakePython ESP32 development kit from Elektor. It has an ESP32 processor and a SSD1306 OLED display plus a few other peripherals. No external h/w.
Arduino IDE version 2.3.6 running on Windows 11.
I’m using the above development kit to try and learn about programming the ESP32 using the Arduino IDE. I have experience of programming although that’s a few years ago now – Microchip microcontrollers in assembly code and 8085s in C.
I’ve had the SSD1306 OLED working via the Thonny IDE with Python but would rather use Arduino C – is that C++? Plus I have run several Arduino C programmes successfully: the Flash LED type of thing. So the kit and the display works
The problem I have is that when I run an OLED programme from Arduino the display does not change. It doesn’t even clear. The comms are via I2C, SDA/SCL as per Adafruit_SSD1306.h. I’ve seen Adafruit_SSD1306.h doesn’t set the address (0x3C) so have tried setting it within the programme: it doesn’t help.
The programme is basically that at OLED Display interfacing with Arduino | Arduino Project Hub with corrections by candy_builds plus many serial.print statements so I can see what the programme is doing. With the corrections it compiles without error and uploads to the ESP32.
What I expect to see is the display will clear then display text, then inverted text, a different font size, then numbers and other text and graphics. As each display type is shown a descriptive message goes to the serial monitor. It’s easy to see in the code what is expected. What happens is nothing, well nothing on the OLED, not even clearing text that is already there from a previous Thonny test. However the programme is running because the serial monitor does report where it is.
It’s probably something simple that I haven’t setup but your help is appreciated.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3c // 0x3C according to SSD1306.py
#define i2caddr 0x3c // i2caddr used in Adafruit_SSD1306.h (shouldn't set in two places!)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Serial.begin(115200);
// initialize the OLED object
Serial.println("Check SSD1306 allocation");
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
}
void loop() {
Serial.println("Setup complete, starting display routines");
display.display();
delay(2000);
display.clearDisplay();
// Display Text
Serial.println("Text");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 28);
display.println("Hello world!");
display.display();
delay(2000);
display.clearDisplay();
// Display Inverted Text
Serial.println("Inverted Text");
display.setTextColor(BLACK, WHITE); // 'inverted' text
display.setCursor(0, 28);
display.println("Hello world!");
display.display();
delay(2000);
display.clearDisplay();
// Changing Font Size
Serial.println("Change Font Size");
display.setTextColor(WHITE);
display.setCursor(0, 24);
display.setTextSize(2);
display.println("Hello!");
display.display();
delay(2000);
display.clearDisplay();
// Display Numbers
Serial.println("Numbers");
display.setTextSize(1);
display.setCursor(0, 28);
display.println(123456789);
display.display();
delay(2000);
display.clearDisplay();
// Specifying Base For Numbers
Serial.println("Specifying base for numbers");
display.setCursor(0, 28);
display.print("0x");
display.print(0xFF, HEX);
display.print("(HEX) = ");
display.print(0xFF, DEC);
display.println("(DEC)");
display.display();
delay(2000);
display.clearDisplay();
// Display ASCII Characters
Serial.println("ASCII Characters");
display.setCursor(0, 24);
display.setTextSize(2);
display.write(1);
display.display();
delay(2000);
display.clearDisplay();
// Scroll full screen
Serial.println("Scroll");
display.setCursor(0, 0);
display.setTextSize(1);
display.println("Full");
display.println("screen");
display.println("scrolling!");
display.display();
display.startscrollright(0x00, 0x07);
delay(4500);
display.stopscroll();
delay(1000);
display.startscrollleft(0x00, 0x07);
delay(4500);
display.stopscroll();
delay(1000);
display.startscrolldiagright(0x00, 0x07);
delay(4500);
display.startscrolldiagleft(0x00, 0x07);
delay(4500);
display.stopscroll();
display.clearDisplay();
//draw rectangle
Serial.println("Rectangle");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Rectangle");
display.drawRect(0, 15, 60, 40, WHITE);
display.display();
delay(2000);
display.clearDisplay();
//draw filled rectangle
Serial.println("Filled Rectangle");
display.setCursor(0, 0);
display.println("Filled Rectangle");
display.fillRect(0, 15, 60, 40, WHITE);
display.display();
delay(2000);
display.clearDisplay();
//draw rectangle with rounded corners
Serial.println("Rounded Corners");
display.setCursor(0, 0);
display.println("Round Rectangle");
display.drawRoundRect(0, 15, 60, 40, 8, WHITE);
display.display();
delay(2000);
display.clearDisplay();
//draw circle
Serial.println("Circle");
display.setCursor(0, 0);
display.println("Circle");
display.drawCircle(20, 35, 20, WHITE);
display.display();
delay(2000);
display.clearDisplay();
//draw filled circle
Serial.println("Filled Circle");
display.setCursor(0, 0);
display.println("Filled Circle");
display.fillCircle(20, 35, 20, WHITE);
display.display();
delay(2000);
display.clearDisplay();
//draw triangle
Serial.println("Triangle");
display.setCursor(0, 0);
display.println("Triangle");
display.drawTriangle(30, 15, 0, 60, 60, 60, WHITE);
display.display();
delay(2000);
display.clearDisplay();
//draw filled triangle
Serial.println("Filled Triangle");
display.setCursor(0, 0);
display.println("Filled Triangle");
display.fillTriangle(30, 15, 0, 60, 60, 60, WHITE);
display.display();
delay(2000);
display.clearDisplay();
}