Created
December 1, 2025 20:36
-
-
Save palaniraja/8000da682f51d2dc3f1fcf33915c044f to your computer and use it in GitHub Desktop.
ESP32 C3 with 70x40 OLED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Arduino.h> | |
| #include <U8g2lib.h> | |
| #define LED_PIN 8 | |
| #define I2C_SDA_PIN 5 | |
| #define I2C_SCL_PIN 6 | |
| static unsigned int count = 0; | |
| U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE, I2C_SCL_PIN, I2C_SDA_PIN); | |
| int width = 72; | |
| int height = 40; | |
| int xOffset = 28; // left offset for active area | |
| int yOffset = 24; // shift box even further down to reveal top border | |
| void setup() | |
| { | |
| Serial.begin(115200); | |
| Serial.println("Hello World!"); | |
| pinMode(LED_PIN, OUTPUT); | |
| u8g2.begin(); | |
| u8g2.setContrast(255); // set contrast to maximum | |
| u8g2.setFont(u8g2_font_ncenB10_tr); | |
| } | |
| void loop() | |
| { | |
| Serial.printf("Count: %d\n", count++); | |
| if (count % 2 == 0) { | |
| digitalWrite(LED_PIN, HIGH); | |
| } else { | |
| digitalWrite(LED_PIN, LOW); | |
| } | |
| u8g2.clearBuffer(); // clear the internal memory | |
| u8g2.drawFrame(xOffset, yOffset, width, height); // draw box at active area | |
| // Center text inside the box | |
| int textX = xOffset + width/2 - 20; // adjust -20 for font width | |
| int textY = yOffset + height/2 + 5; // adjust +5 for font baseline | |
| u8g2.setCursor(textX, textY); | |
| u8g2.printf("%d", count); | |
| u8g2.sendBuffer(); // transfer internal memory to the display | |
| delay(1000); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [env:c3-oled] | |
| platform = espressif32 | |
| board = esp32-c3-devkitm-1 | |
| framework = arduino | |
| monitor_speed = 115200 | |
| monitor_filters = | |
| time | |
| send_on_enter | |
| build_flags = | |
| -D ARDUINO_USB_MODE=1 | |
| -D ARDUINO_USB_CDC_ON_BOOT=1 | |
| lib_deps = | |
| https://github.com/olikraus/U8g2_Arduino.git |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment