Hi,
now I am successfully loading code to my ESP32, I move to my next issue. I am not getting anything on my SSD1306.
I tested it on an Arduino using your example and it works fine. However not with the ESP32. I used a cut down version of the code in the BLE client without the BLE elements. See below and used the same wiring as in the BLE client example. But I see nothing on the screen.
David
/********* Rui Santos Complete project details at http://randomnerdtutorials.com *********/ #include <Wire.h> #include <Adafruit_SSD1306.h> #include <Adafruit_GFX.h> //Default Temperature is in Celsius //Comment the next line for Temperature in Fahrenheit #define temperatureCelsius #define OLED_RESET 16 //SSD1306 Display Adafruit_SSD1306 display(OLED_RESET); void setup() { //OLED display setup Wire.begin(); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE,0); display.setCursor(30,0); display.print("HELLO WORLD"); display.display(); } void loop() { }
Hello David. I’ve not tried that code, but here’s what I recommend:
Can you upload to the ESP32 the Arduino code that worked for you?
Which pins are connected in your ESP32 to the OLED display? Can you double-check your schematics?
If the code runs in your Arduino, it should run in your ESP32. Otherwise, it looks like one of the pins is not connected properly.
Hi Rui,
I have uploaded the Arduino code in your example (https://randomnerdtutorials.com/guide-for-oled-display-with-arduino/) and tested with Arduino Uno. This works fine. I transfer the code to the ESP32 and it compiles and loads, but I am getting the following errors appearing constantly in the monitor window (see below), whether I have wires connected or not. I try this with different ESP32s and I get the same result. If I reload a blink example back to the ESP32, it works fine.
Rebooting…
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:812
load:0x40078000,len:0
load:0x40078000,len:11572
entry 0x40078a5c
Guru Meditation Error: Core 1 panic’ed (IntegerDivideByZero)
. Exception was unhandled.
Core 1 register dump:
PC : 0x400d26a4 PS : 0x00060730 A0 : 0x800d0c78 A1 : 0x3ffca760
A2 : 0x3ffc1024 A3 : 0x00000000 A4 : 0x00000001 A5 : 0x00000064
A6 : 0xffffffff A7 : 0x00000080 A8 : 0x02625a00 A9 : 0x3ffca740
A10 : 0x00000001 A11 : 0x00000021 A12 : 0x3ffc5318 A13 : 0x00000000
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x0000001c EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x400e8258 LEND : 0x400e8267 LCOUNT : 0x00000000
Backtrace: 0x400d26a4:0x3ffca760 0x400d0c75:0x3ffca780 0x400d159e:0x3ffca7a0 0x400d09fa:0x3ffca7d0 0x400e5d07:0x3ffca7f0
Rebooting…
Just for your reference: here is the code:
/*
* Random Nerd Tutorials – Rui Santos
* Complete Project Details http://randomnerdtutorials.com
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
#define DHTPIN 2 // what pin we’re connected to
#define DHTTYPE DHT11 // DHT 11
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Wire.begin();
dht.begin(); // initialize dht
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);// initialize with the I2C addr 0x3C (for the 128×32)(initializing the display)
Serial.begin(9600);
}
void displayTempHumid(){
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
display.clearDisplay(); // clearing the display
display.setTextColor(WHITE); //setting the color
display.setTextSize(1); //set the font size
display.setCursor(5,0); //set the cursor coordinates
display.print(“Failed to read from DHT sensor!”);
return;
}
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0,0);
display.print(“Humidity: “);
display.print(h);
display.print(” %\t”);
display.setCursor(0,10);
display.print(“Temperature: “);
display.print(t);
display.print(” C”);
display.setCursor(0,20);
display.print(“Temperature: “);
display.print(f);
display.print(” F”);
}
void loop()
{
displayTempHumid();
display.display();
}
Does that error happen in two different ESP32 boards? Or are you always using the same board for your tests?
Hello again!
I’ve tested right now and you’re right the Arduino code doesn’t work with the ESP32 anymore. I’ve just updated the code in the ESP32 course for the LoRa receiver to make it work properly.
Here’s the updated code: https://github.com/RuiSantosdotme/ESP32-Course/blob/master/code/LoRa_RFM95/LoRa_Receiver/LoRa_Receiver.ino
Basically, in the latest OLED library update they made some changes. There’s a new way to initialize the OLED display with ESP32: https://gist.github.com/RuiSantosdotme/020c23f3b45132f755f39f37a536b780
Thanks and let me know if this works for you!
Hi Rui, I have had mixed success with this. I now see graphics on the display but I only see the word ‘Test’ not Test Message’ and the rest of the screen is garbage. I have tried 2 different boards. I have also tried with 32 and 64 for height, but I get the same problem just with smaller text. I also updated the ssd1306 library recently.
I’ve just spent the last hour re-trying those examples and they worked for me with the latest OLED library. Note: I’ve only tried on an OLED 128×64… It should work with any display size. Can you try the exact example that comes with the library? Go to File > Examples > Adafruit SSD1306 > ssd1306_128x64_i2c
I am getting nothing new on the screen when I run the ssd1306_128x64_i2c example. It still has the last results from the previous test. So for some reason this example is not working.
So I just tried loading the Esp8266 and ESP32 oled driver for ssd1306 library and running the examples in there and they all work fine. (after I changed D3/D5 to 21/22). I can not get the standard library examples to work at all. I am running 1.2.9 of the Adafruit SSD1306 library. Is that the latest?
Thanks for letting me know David. How did you initialize the pins? Can you post here that code section?
It should automatically assign the SCL (22) and SDA (21) pins… Yes. I also have the Adafruit SSD1306 library 1.2.9 library.
I attach 2 pieces of code: The ESP test code, which you created. This only prints the word Test and then lots of garbage below. The the section of the Adafruit test library code:
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
//for ESP32
//SDA on 21
//SCL on 22
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128×32
Serial.println(F(“SSD1306 allocation failed”));
for(;;); // Don’t proceed, loop forever
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(“Test message”);
display.setCursor(0,10);
display.println(“Test2 message”);
display.display();
}
#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
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128×64
Serial.println(F(“SSD1306 allocation failed”));
for(;;); // Don’t proceed, loop forever
}
etc.
Hello David. Thanks for letting me know. With those examples, you just have a comment in your code and there’s not actual pin declaration.
//for ESP32
//SDA on 21
//SCL on 22
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
I honestly don’t know why the code isn’t working for you and I can’t reproduce that error on my end (the garbage message after “Test”)…
Oh no. I am not sure where to go from here.
Just for the record I attach a picture of the circuit and display output. i also attach the code below that produced this. I have tried with 2 different SSD1306 displays and 3 ESP32 boards, all of which produce the same result. If you have any inspirations, please let me know ….
Find image here: https://www.dropbox.com/s/nhvfcj0owiv7583/esp32-ssd1306.jpg?dl=0
/********* Rui Santos Complete project details at http://randomnerdtutorials.com *********/ #include <Wire.h> #include <Adafruit_SSD1306.h> #include <Adafruit_GFX.h> //Default Temperature is in Celsius //Comment the next line for Temperature in Fahrenheit #define temperatureCelsius #define OLED_RESET 16 //SSD1306 Display Adafruit_SSD1306 display(OLED_RESET); void setup() { //OLED display setup Wire.begin(); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE,0); display.setCursor(30,0); display.print("HELLO WORLD"); display.display(); } void loop() { }
I’m honestly puzzled and I can’t figure out what’s missing. Even with that code and with that display print lines?
display.print("HELLO WORLD");
Does it print in the OLED display this message?
Testm
According to your image is printing that.
My apologies, I uploaded the wrong code (I have been trying so many). This is the code that generated the Testm output. It seems as though the screen is not clearing and just has what is in the buffer on the screen except for the 1st 5 letters of the message.
I have also been experimenting with SSD1306Wire library and that works perfectly with the same hardware setup.
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
//for ESP32
//SDA on 21
//SCL on 22
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128×32
Serial.println(F(“SSD1306 allocation failed”));
for(;;); // Don’t proceed, loop forever
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(“Testmessage”);
display.display();
}
void loop() {
// put your main code here, to run repeatedly:
}
Hello David, I’m honestly running out of ideas. I’ve tested that exact same code that you’ve sent me and it works fine for me (ESP32 + OLED 128×64):
I’m not doing anything special.. I just have the latest version of the libraries:
- Adafruit_SSD1306 – 1.2.9
- Adafruit_GFX – 1.3.6
Thanks for your time and help figuring out how we can fix this problem.