Software I2C U8g2Lib doesn't work

Post here first, or if you can't find a relevant section!
Post Reply
zjm001
Posts: 3
Joined: Sun Jan 08, 2023 1:16 pm

Software I2C U8g2Lib doesn't work

Post by zjm001 »

Hello guys,
I tried to use the 128X64 OLED by using U8g2Lib's software I2C , but it doesn't work.
However, I used the same code on Arduino UNO,and it worked well (except pins definations).
My chip is STM32F103ZET6
SDA => PF8
SCL => PF10
Please recommand me a usable lib if this actually a bug.
Below is my code.
Thank you :D .

Code: Select all

#include <U8g2lib.h>
#include <Wire.h>
#define SCL_OLED PF10
#define SDA_OLED PF8
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /*clock=*/SCL_OLED, /*data=*/SDA_OLED, /*reset=*/U8X8_PIN_NONE);
void setup() {
  pinMode(SDA_OLED, OUTPUT);
  pinMode(SCL_OLED, OUTPUT);
  u8g2.begin();
  u8g2.enableUTF8Print(); // enable UTF8 support for the Arduino print() function
}

void loop() {
  u8g2.setFont(u8g2_font_unifont_t_symbols);
  u8g2.firstPage();
  do
  {
    u8g2.setCursor(0, 15);
    u8g2.print("Hello World!");
  } while (u8g2.nextPage());
  delay(1000);
}
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Software I2C U8g2Lib doesn't work

Post by fpiSTM »

Why not use the hardware I2C?
zjm001
Posts: 3
Joined: Sun Jan 08, 2023 1:16 pm

Re: Software I2C U8g2Lib doesn't work

Post by zjm001 »

Well, my I2C bus has some devices that can't be set address in their init functions. At the same time,U8g2Lib also provides the SW init function,so I want to use the software I2C to use the OLED . :)
zjm001
Posts: 3
Joined: Sun Jan 08, 2023 1:16 pm

Re: Software I2C U8g2Lib doesn't work

Post by zjm001 »

fpiSTM wrote: Sun Jan 08, 2023 1:57 pm Why not use the hardware I2C?
The hardware I2C is tested OK,but the software I2C is also failed.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Software I2C U8g2Lib doesn't work

Post by ag123 »

User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Software I2C U8g2Lib doesn't work

Post by fpiSTM »

I already use the SW I2C of this library with another mcu and it works.
Maybe timing issue if you used the internal clock (HSI)?
hotxxw
Posts: 1
Joined: Wed Feb 22, 2023 1:05 am

Re: Software I2C U8g2Lib doesn't work

Post by hotxxw »

I also encountered the same situation. The hardware I2C is OK, but the software I2C is unrealistic. Have you solved this problem?
Post Reply

Return to “General discussion”