SSD1306 Display is not working on Bluepill Board STM32F103

Hardware Details

MCU - Bluepill STM32F103CB
OLED SSD1306 128x32 I2C display
PA3 - SDA
PA4 - SCL
Note: These are non standard I2C pin of STM32F103C MCU

Code (in PlatformIO)

  1. First I used the softwire library’s scanner code to validate the I2C connection of PA3(SDA) & PA4 (SCL). Got the Slave address as 0x3C

  2. Then I tried Ada fruit SSD1306 library, but that doesn’t support non-standard I2C pin of MCU

  3. Finally I used the U8G2 library, below code but Display is not working(showing nothing)

#include <U8g2lib.h>
U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C display(U8G2_R0, PA4, PA3, U8X8_PIN_NONE);
void setup()
{
display.begin();
}
void loop()
{
  display.clearBuffer();
  display.setFont(u8g2_font_ncenB08_tr);
  display.drawStr(0, 10, "Hello STM32!");
  display.sendBuffer();
  delay(1000);
}

Digital Logic analyzer waveform output

Problem Statement

After seeing the code and Logic analyzer waveform, there are some issue configuration in the code while use U8g2lib library. Please help here solve this issue

Also I asked help from library owner in github but I didn’t got the solution

Thanks in Advance!!!

Logic analyzers are a life saver!! This may or may not help but I developed an esp-idf component for the SSD1306. It is minimalistic i.e. one font type, works with either display i.e. 128x32 or 128x64, it is an updated code base that supports i2c_master.h for I2C transactions.

SSD1306 ESP-IDF (ESP-32-S3) Example

1 Like

Thanks for the sharing details. Since I am intermediate level programmer going too much deep to edit the library code I will difficult for me. If any pre library made which support non i2c pin will easier to implement.

  1. Adafruit SSD1306
  2. SSD1306ASCII
  3. U8g2
    For this use case, I tried all this library but U8g2 library only show bus activity, rest of library didn’t working at all.

Non-standard? If I read the datasheet correctly of the STM32F103xB, then PA3 and PA4 are not hardware I2C pins at all. Not even with a remap would an I2C peripheral be connected to those pins.

So hardware I2C is out of the question. A slower software I2C is the only thing you’ve got then. Do you see it the same way?

1 Like

Yes you are correct, Hardware I2C is not possible here. I am looking for software I2C(like softwire library) supported SSD1306 Display library.

Actually Here I am trying to rewrite code for DIY M181 LCR Meter designed by JYETech.

The occasional glitches on the SCL (?) line in the logic analyzer definitely don’t look good. If the SoftWire library is what’s causing that, that needs to be fixed.

In any case, I found https://github.com/BLavery/miniOled and prepared this project: Can you try and upload it and see what happens?

1 Like

This SCL line glitches is come only if I use the U8g2 library. With Softwire library it is working fine without glitches (by running the I2C scanner example).

I tried the code prepared by you. Straight away display start working, attached image. Thanks you so much for your support and help🙌.

Nice! But are you sure about

This looks like the regular 128x64 pixel version. The 128x32 pixels look like this, half-height.

images

as opposed to

s-l400

Delete

from the platformio.ini, reupload and see if the text now starts at the top of the display. The code tries to write the text to the first line.

  oled.setTextXY(0,0);              // Set cursor position, start of line 0
  oled.putString("ACROBOTIC");

It suspiciously starts at only half the height of the display, so I really think you have the 128x64 pixel version and not x32.

Yes, I have 128x64 pixel version.

Update the code as per your suggestion &
Add extra lines of code to test the complete display area

  oled.setTextXY(3, 2); // Set cursor position, line 3
  oled.putString("Hello");
  oled.setTextXY(4, 20); // Set cursor position, line 4
  oled.putString("World!!!");
  oled.setTextXY(5, 10); // Set cursor position, line 5
  oled.putString("123");
  oled.setTextXY(6, 1); // Set cursor position, line 6
  oled.putString("Testing via");
  oled.setTextXY(7, 5); // Set cursor position, line 7
  oled.putString("Sofwire");

Result is

1 Like

To be fair against u8g2, you should retry it with

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ PA4, /* data=*/ PA3, /* reset=*/ U8X8_PIN_NONE);   // All Boards without Reset of the Display

Same Issue is back mentioned as starting of this topic

Code Used

#include <U8g2lib.h>
// U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C display(U8G2_R0, PA4, PA3, U8X8_PIN_NONE);
U8G2_SSD1306_128X64_NONAME_F_SW_I2C display(U8G2_R0, /* clock=*/ PA4, /* data=*/ PA3, /* reset=*/ U8X8_PIN_NONE);   // All Boards without Reset of the Display
void setup()
{
display.begin();
}
void loop()
{
  display.clearBuffer();
  display.setFont(u8g2_font_ncenB08_tr);
  display.drawStr(0, 10, "Hello STM32!");
  display.sendBuffer();
  delay(1000);
}

Waveform output

I see. Best to stay with a working example then.