Hi,
I have gone through all the posts here regarding SSD1306 OLED issues and surfed the internet for solutions.
I have tested with Arduino Nano and STM32 connected on CLK PB6 / SDA PB7:
pic1: Arduino Nano with SSD1306 works
pic2: STM32f411 with TM1637 4 digit LED display works
pic3: STM32f411 with SSD1306 doesn't turn display on.
I am using this Adafruit 1306 code
https://randomnerdtutorials.com/guide-f ... h-arduino/
This is the main part of the code - this works on Arduino
#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)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
display.clearDisplay();
SSD1306 OLED STM32f411 not connecting
-
- Posts: 41
- Joined: Thu May 02, 2024 11:10 am
SSD1306 OLED STM32f411 not connecting
- Attachments
-
- Arduino_1306_sm.jpg (85.2 KiB) Viewed 4584 times
-
- STM32_TM1637_sm.jpg (80.57 KiB) Viewed 4584 times
-
- STM32_1306_sm.jpg (71 KiB) Viewed 4585 times
-
- Posts: 41
- Joined: Thu May 02, 2024 11:10 am
Re: SSD1306 OLED STM32f411 not connecting
I found the solution here. It requires OLED_RESET 4.
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
You can download the code example. Password: Subscribe my channel
https://www.youtube.com/watch?v=tXaeRzaBwBY
This code worked for me:
/* SCLK B6 / SDA B7 */
#include <Wire.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 4
// Adafruit_SSD1306 display(OLED_RESET);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64)
// Clear the buffer.
display.clearDisplay();
}
void loop() {
// Draw a test
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("OLED with STM32F103C");
display.setCursor(0,12);
display.println("-------Welcome-------");
display.println("To The Thunderdome");
display.setTextSize(1);
display.setCursor(4,50);
display.print(millis()/1000);
display.display();
delay(1000);
// display.clearDisplay();
}
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
You can download the code example. Password: Subscribe my channel
https://www.youtube.com/watch?v=tXaeRzaBwBY
This code worked for me:
/* SCLK B6 / SDA B7 */
#include <Wire.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 4
// Adafruit_SSD1306 display(OLED_RESET);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64)
// Clear the buffer.
display.clearDisplay();
}
void loop() {
// Draw a test
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("OLED with STM32F103C");
display.setCursor(0,12);
display.println("-------Welcome-------");
display.println("To The Thunderdome");
display.setTextSize(1);
display.setCursor(4,50);
display.print(millis()/1000);
display.display();
delay(1000);
// display.clearDisplay();
}
-
- Posts: 142
- Joined: Mon May 06, 2024 1:46 pm
- Location: Germany
Re: SSD1306 OLED STM32f411 not connecting
Once again: can you please put your sketch in code-Tags?
The </> icon.
You can still do it after posting ...
What is that OLED-RESET?
Does your display have 5 pins?
The </> icon.
You can still do it after posting ...
You are using a display with I²C-interface, normally it only has Vcc, SCL, SDA and GND.
What is that OLED-RESET?
Does your display have 5 pins?
-
- Posts: 41
- Joined: Thu May 02, 2024 11:10 am
Re: SSD1306 OLED STM32f411 not connecting
Yes, I have four pin. The Adafruit 1306 library is written for OLED with reset pin (5 pin), so you have to tell not to use it. The documentation I read says -1 turns the reset pin off, this didn't work for me but using OLED_RESET 4 does. Don't ask me why, I don't what the significance is, it just works.
https://github.com/adafruit/Adafruit_SSD1306
https://github.com/adafruit/Adafruit_SSD1306
-
- Posts: 41
- Joined: Thu May 02, 2024 11:10 am
Re: SSD1306 OLED STM32f411 not connecting
I googled this:
Adafruit SSD1306 OLED display library allows you to reset the display using the OLED_RESET pin, which is set to 4 (D4) by default. You can set OLED_RESET to -1 if your OLED display does not have a reset pin.
I think the 1306 OLED display I have might have something different about the way reset pin is wired, which is why OLED_RESET 4 works. Even though it is 4 pin version.
If you follow this guy's tutorial this is how he does it with ST32 using 4 pin OLED although he doesn't explain it.
https://www.youtube.com/watch?v=tXaeRzaBwBY
Adafruit SSD1306 OLED display library allows you to reset the display using the OLED_RESET pin, which is set to 4 (D4) by default. You can set OLED_RESET to -1 if your OLED display does not have a reset pin.
I think the 1306 OLED display I have might have something different about the way reset pin is wired, which is why OLED_RESET 4 works. Even though it is 4 pin version.
If you follow this guy's tutorial this is how he does it with ST32 using 4 pin OLED although he doesn't explain it.
https://www.youtube.com/watch?v=tXaeRzaBwBY
Re: SSD1306 OLED STM32f411 not connecting
if there is no reset pin, and you define OLED_RESET, it just don't reset the lcd
it probably works, but it is unknown if there may be situations if reset is after all required.
it probably works, but it is unknown if there may be situations if reset is after all required.
-
- Posts: 142
- Joined: Mon May 06, 2024 1:46 pm
- Location: Germany
Re: SSD1306 OLED STM32f411 not connecting
I²C is also called TWI = two wire interface.
The reason: it has exact 2 lines ... SCL and SDA.
There is no reset line.
And if your display has not 5 lines, it can't have an effect to display controller like deleting memory etc.
But Adafruit has a strange constructor for I²C, explanations are confused:
The only thing I can see inside Adafruit_SSD1306.cpp is:
So:
1. What happens, if you use:
2. What happens, if you set reset to -1 again and place a:
after your display.begin() ?
I²C at 400 kHz is not really fast.
Arduino Nano only have 16 MHz.
STM32F411 can run with 100 MHz (but I don't know if it starts on power-on at this speed).
I guess, a BlackPill is simply too fast and you have to give a "settling time" to display?
The reason: it has exact 2 lines ... SCL and SDA.
There is no reset line.
And if your display has not 5 lines, it can't have an effect to display controller like deleting memory etc.
But Adafruit has a strange constructor for I²C, explanations are confused:
Code: Select all
Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi = &Wire,
int8_t rst_pin = -1, uint32_t clkDuring = 400000UL,
uint32_t clkAfter = 100000UL);
The only thing I can see inside Adafruit_SSD1306.cpp is:
Code: Select all
// Reset SSD1306 if requested and reset pin specified in constructor
if (reset && (rstPin >= 0)) {
pinMode(rstPin, OUTPUT);
digitalWrite(rstPin, HIGH);
delay(1); // VDD goes high at start, pause for 1 ms
digitalWrite(rstPin, LOW); // Bring reset low
delay(10); // Wait 10 ms
digitalWrite(rstPin, HIGH); // Bring out of reset
}
1. What happens, if you use:
Code: Select all
#define OLED_RESET 5
Code: Select all
delay(100);
I²C at 400 kHz is not really fast.
Arduino Nano only have 16 MHz.
STM32F411 can run with 100 MHz (but I don't know if it starts on power-on at this speed).
I guess, a BlackPill is simply too fast and you have to give a "settling time" to display?
Re: SSD1306 OLED STM32f411 not connecting
@STM32ardui I think I've encountered similar issues with SSD1306 (e.g. those modules bought on Aliexpress)
https://www.aliexpress.com/w/wholesale-ssd1306.html
But that I've got one that has the reset pin on the headers and I connected that and used a PAxx gpio pin to drive that reset pin, no issues
for some reason the software lcd reset seemed to be causing issues at times.
I'm not sure if it could be related to timing as stm32 is possibly much faster than say atmega328, it may take some delays in the lib code I'd guess if it is true
https://www.aliexpress.com/w/wholesale-ssd1306.html
But that I've got one that has the reset pin on the headers and I connected that and used a PAxx gpio pin to drive that reset pin, no issues
for some reason the software lcd reset seemed to be causing issues at times.
I'm not sure if it could be related to timing as stm32 is possibly much faster than say atmega328, it may take some delays in the lib code I'd guess if it is true