read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
#ARDUINO
#C++
#DISPLAY
#EMBEDDED
#ESP32
#ESP32-C3
#GRAPHICS
#I2C
#MICROCONTROLLERS
#OLED
#SSD1306
#U8G2
I’ve ended up with a bunch of these nice little ESP32-C3 modules.
I’m a bit late to the party with them, so other people have done a lot of heavy lifting working out how to drive the display. I followed this blog.
The only thing I didn’t quite like was the slight bodge in his drawing code where he used the U8G2_SSD1306_128X64_NONAME_F_HW_I2C class and then offset his code to work for 70x40 size display.
There is now an appropriate constructor that seems to work without needing any funny offsets.

#include <U8g2lib.h>
#include <Wire.h>
#include <U8g2lib.h>
#include <Wire.h>
U8G2_SSD1306_72X40_ER_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE, 6, 5);
int width = 72;
int height = 40;
void setup(void)
{
delay(1000);
u8g2.begin();
u8g2.setContrast(255); // set contrast to maximum
u8g2.setBusClock(400000); //400kHz I2C
u8g2.setFont(u8g2_font_ncenB10_tr);
}
void loop(void)
{
u8g2.clearBuffer(); // clear the internal memory
u8g2.drawFrame(0, 0, width, height); //draw a frame around the border
u8g2.setCursor(15, 25);
u8g2.printf("%dx%d", width, height);
u8g2.sendBuffer(); // transfer internal memory to the display
}
#ARDUINO
#C++
#DISPLAY
#EMBEDDED
#ESP32
#ESP32-C3
#GRAPHICS
#I2C
#MICROCONTROLLERS
#OLED
#SSD1306
#U8G2