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’s a quick fix to not having an appropriate constructor with the right size - digging into the U8g code the parts are all there for us to declare our own and get a slightly neater bit of code.

#include <U8g2lib.h>
#include <Wire.h>
class U8G2_SSD1306_72X40_NONAME_F_HW_I2C : public U8G2 {
public: U8G2_SSD1306_72X40_NONAME_F_HW_I2C(const u8g2_cb_t *rotation, uint8_t reset = U8X8_PIN_NONE, uint8_t clock = U8X8_PIN_NONE, uint8_t data = U8X8_PIN_NONE) : U8G2() {
u8g2_Setup_ssd1306_i2c_72x40_er_f(&u8g2, rotation, u8x8_byte_arduino_hw_i2c, u8x8_gpio_and_delay_arduino);
u8x8_SetPin_HW_I2C(getU8x8(), reset, clock, data);
}
};
U8G2_SSD1306_72X40_NONAME_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