{"id":1098,"date":"2025-03-26T07:46:24","date_gmt":"2025-03-26T06:46:24","guid":{"rendered":"https:\/\/sharedinventions.com\/?p=1098"},"modified":"2025-03-27T08:44:23","modified_gmt":"2025-03-27T07:44:23","slug":"esp32-c3-oled","status":"publish","type":"post","link":"https:\/\/sharedinventions.com\/?p=1098","title":{"rendered":"ESP32-C3 OLED"},"content":{"rendered":"\n<p>This microcontroller module is great as it is cheap, but also incorporates an OLED display. I admit, that the screen is extremely small 0.42&#8243;, but it can still display some basic information, and you will not buy a screen and the microcontroller for the price of ($6 or 5.6 EUR).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/sharedinventions.com\/wp-content\/uploads\/2025\/03\/PXL_20250326_062212137-scaled.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"917\" src=\"https:\/\/sharedinventions.com\/wp-content\/uploads\/2025\/03\/PXL_20250326_062212137-1024x917.jpg\" alt=\"\" class=\"wp-image-1100\" srcset=\"https:\/\/sharedinventions.com\/wp-content\/uploads\/2025\/03\/PXL_20250326_062212137-1024x917.jpg 1024w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2025\/03\/PXL_20250326_062212137-300x269.jpg 300w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2025\/03\/PXL_20250326_062212137-768x688.jpg 768w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2025\/03\/PXL_20250326_062212137-1536x1375.jpg 1536w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2025\/03\/PXL_20250326_062212137-2048x1834.jpg 2048w, https:\/\/sharedinventions.com\/wp-content\/uploads\/2025\/03\/PXL_20250326_062212137-660x591.jpg 660w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>There are at least two variants out there with this name, on mine the buttons are located oppose from the USB connector. <\/p>\n\n\n\n<p>Buy here<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/s.click.aliexpress.com\/e\/_oD4R12v\">https:\/\/s.click.aliexpress.com\/e\/_oD4R12v<\/a> Should be around 5\u20ac or $5.4<\/li>\n<\/ul>\n\n\n\n<p>(Affiliate link)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up in PlatformIO<\/h2>\n\n\n\n<p>We should use the e<code>spressif32<\/code> platform with the board of <code>esp32-c3-devkitm-1<\/code>, however e.g. the LED_BUILTIN is not the same with my board, so this is not the same board layout.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;env:esp32-c3-oled]\nplatform = espressif32\nboard = esp32-c3-devkitm-1\nframework = arduino\nlib_deps =\n  olikraus\/U8g2<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Initial code<\/h2>\n\n\n\n<p>Here is a sample code for the module. It of course already tests the screen with the U8g2 library, as it is the star of the show. To list all the peripherals tested:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>On-board 72&#215;40 OLED screen using hardware i2c,<\/li>\n\n\n\n<li>Built in LED on pin 8,<\/li>\n\n\n\n<li>Button called &#8220;BOOT&#8221; on pin 9,<\/li>\n\n\n\n<li>ESP32-c3 internal temperature sensor.<\/li>\n<\/ul>\n\n\n\n<p>(We use some legacy code for the temperature sensing, so it will not work in the future.)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;Arduino.h&gt;\n#include &lt;U8g2lib.h&gt;\n\/\/ Legacy library for the temperature sensor\n#include \"driver\/temp_sensor.h\"\n\n#include &lt;Wire.h&gt;\n\n#define SDA_PIN 5\n#define SCL_PIN 6\n\n#define PIN_LED     8\n#define PIN_BUTTON  9\n\nU8G2_SSD1306_72X40_ER_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);\n\nvoid drawText(const char *text)\n{\n  u8g2.drawStr(0, 0, text);\n}\n\n\/\/ Initialize the temperature sensor\nvoid initTempSensor(){\n  temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT();\n  temp_sensor.dac_offset = TSENS_DAC_L2;\n  temp_sensor_set_config(temp_sensor);\n  temp_sensor_start();\n}\n\nvoid setup() {\n  pinMode(PIN_LED, OUTPUT);\n  pinMode(PIN_BUTTON, INPUT);\n\n  Wire.begin(SDA_PIN, SCL_PIN);   \n  u8g2.begin();\n\n  u8g2.setDisplayRotation(U8G2_R3); \/\/ Rotate the display 180 degrees\n  u8g2.setFont(u8g2_font_fub25_tf); \/\/ Use high pixel wide font\n  u8g2.setDrawColor(1);\n  u8g2.setFontPosTop();\n\n  initTempSensor();\n}\n\nchar buffer&#91;5];\n\nvoid loop() {\n  \/\/ Read temperature and convert it to const char*\n  float temp_celsius = 0;\n  temp_sensor_read_celsius(&amp;temp_celsius);\n  snprintf(buffer, sizeof(buffer), \"%.0f\", temp_celsius);\n  const char* buffer_c = buffer;\n\n  u8g2.clearBuffer();\n  drawText(buffer_c);\n  u8g2.sendBuffer();\n\n  digitalWrite(PIN_LED, digitalRead(PIN_BUTTON));\n\n  delay(100);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How to continue<\/h2>\n\n\n\n<p>We should also check<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>WiFi and Bluetooth capability<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This microcontroller module is great as it is cheap, but also incorporates an OLED display. I admit, that the screen is extremely small 0.42&#8243;, but it can still display some basic information, and you will not buy a screen and the microcontroller for the price of ($6 or 5.6 EUR). There are at least two\u2026 <span class=\"read-more\"><a href=\"https:\/\/sharedinventions.com\/?p=1098\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":1100,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1098","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-misc"],"_links":{"self":[{"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/posts\/1098","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1098"}],"version-history":[{"count":3,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/posts\/1098\/revisions"}],"predecessor-version":[{"id":1105,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/posts\/1098\/revisions\/1105"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=\/wp\/v2\/media\/1100"}],"wp:attachment":[{"href":"https:\/\/sharedinventions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sharedinventions.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}