yanbe / ssd1306-esp-idf-i2c

Sample code for driving 128x64 OLED display (SSD1306 driver) via ESP-IDF's I2C master driver
Apache License 2.0
108 stars 43 forks source link

Heltec - Makerhawk ESP32 Wifi #8

Open gameofyou opened 4 years ago

gameofyou commented 4 years ago

Just adding this comment to your project because from my google search there appears to be a number of people who have searched for an esp-idf based solution to driving this type of display which has been integrated into this board. Heltec themselves however only provide ardinuo based code. It is however very simple to get running, the key thing is a reset needs to be sent to the OLED display for it to start working.

diff --git a/main/main.c b/main/main.c
index 2f35dd2..c1f1776 100644
--- a/main/main.c
+++ b/main/main.c
@@ -11,8 +11,9 @@
 #include "ssd1366.h"
 #include "font8x8_basic.h"

-#define SDA_PIN GPIO_NUM_15
-#define SCL_PIN GPIO_NUM_2
+#define SDA_PIN GPIO_NUM_4
+#define SCL_PIN GPIO_NUM_15
+#define RST_PIN GPIO_NUM_16

 #define tag "SSD1306"

@@ -24,7 +25,7 @@ void i2c_master_init()
                .scl_io_num = SCL_PIN,
                .sda_pullup_en = GPIO_PULLUP_ENABLE,
                .scl_pullup_en = GPIO_PULLUP_ENABLE,
-               .master.clk_speed = 1000000
+               .master.clk_speed = 700000
        };
        i2c_param_config(I2C_NUM_0, &i2c_config);
        i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
@@ -35,6 +36,11 @@ void ssd1306_init() {

        i2c_cmd_handle_t cmd = i2c_cmd_link_create();

+        gpio_set_direction(RST_PIN,GPIO_MODE_OUTPUT);
+        gpio_set_level(RST_PIN, 0);
+        vTaskDelay( pdMS_TO_TICKS( 100 ) );
+        gpio_set_level(RST_PIN, 1);
+
        i2c_master_start(cmd);
        i2c_master_write_byte(cmd, (OLED_I2C_ADDRESS << 1) | I2C_MASTER_WRITE, true);
        i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
arturfreitas commented 4 years ago

That was extremely useful! Thanks a lot.

jonesy2 commented 3 years ago

You can do this in hardware if you're running out of pins - a 100nF cap to GND and a 10k res to VCC on the reset pin.