SSD1306 OLED won't work

Hi, I’m trying to get an SSD1306 oled working with my Wemos D1 mini ESP8266. The particular OLED I have has and SCK instead SCL. I’ve tried following this guide: Time & Temperature on OLED Display — ESPHome

I have the same OLED as this guy

I have hooked up the SSD1306 as follows:

GND-GND (I’ve got my temp sensor connected here as well)
VDD-3 Volts (I’ve got my temp sensor and two diodes connected here as well)
SCK-D1 (GPIO05)
SCL-D2 (GPIO04)

These entries from the full log below were interesting:

[19:45:34][E][i2c.arduino:177]: Recovery failed: SCL is held LOW on the I2C bus
[19:45:44][C][i2c.arduino:047]:   Recovery: failed, SCL is held low on the bus
[19:45:45][E][ssd1306_i2c:036]: Communication with SSD1306 failed!

Flashing the esp8266 with ESPFlasher gives the following logs (removed the things relating to MQTT, network, LEDs, temp sensor etc):

Showing logs:
[19:45:34][I][logger:214]: Log initialized
[19:45:34][C][ota:461]: There have been 3 suspected unsuccessful boot attempts.
[19:45:34][I][app:029]: Running through setup()...
[19:45:34][I][i2c.arduino:161]: Performing I2C bus recovery
[19:45:34][E][i2c.arduino:177]: Recovery failed: SCL is held LOW on the I2C bus
[19:45:34][C][dallas.sensor:032]: Setting up DallasComponent...
[19:45:34][E][dallas.sensor:191]: Reading scratchpad failed: reset
[19:45:34][C][ssd1306_i2c:010]: Setting up I2C SSD1306...
[19:45:34][E][component:112]: Component ssd1306_base was marked as failed.
[19:45:44][C][api:025]: Setting up Home Assistant API server...
[19:45:44][I][app:062]: setup() finished successfully!
[19:45:44]'
[19:45:44][I][app:102]: ESPHome version 2022.3.1 compiled on Jun 16 2022, 19:05:38
[19:45:44][C][logger:233]: Logger:
[19:45:44][C][logger:234]:   Level: DEBUG
[19:45:44][C][logger:235]:   Log Baud Rate: 115200
[19:45:44][C][logger:236]:   Hardware UART: UART0
[19:45:44][C][i2c.arduino:038]: I2C Bus:
[19:45:44][C][i2c.arduino:039]:   SDA Pin: GPIO4
[19:45:44][C][i2c.arduino:040]:   SCL Pin: GPIO5
[19:45:44][C][i2c.arduino:041]:   Frequency: 50000 Hz
[19:45:44][C][i2c.arduino:047]:   Recovery: failed, SCL is held low on the bus
[19:45:44][I][i2c.arduino:054]: Results from i2c bus scan:
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x08
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x09
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x0A
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x0B
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x0C
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x0D
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x0E
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x0F
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x10
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x11
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x12
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x13
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x14
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x15
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x16
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x17
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x18
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x19
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x1A
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x1B
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x1C
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x1D
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x1E
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x1F
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x20
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x21
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x22
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x23
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x24
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x25
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x26
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x27
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x28
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x29
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x2A
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x2B
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x2C
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x2D
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x2E
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x2F
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x30
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x31
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x32
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x33
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x34
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x35
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x36
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x37
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x38
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x39
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x3A
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x3B
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x3C
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x3D
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x3E
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x3F
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x40
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x41
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x42
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x43
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x44
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x45
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x46
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x47
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x48
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x49
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x4A
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x4B
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x4C
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x4D
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x4E
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x4F
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x50
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x51
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x52
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x53
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x54
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x55
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x56
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x57
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x58
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x59
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x5A
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x5B
[19:45:44][E][i2c.arduino:062]: Unknown error at address 0x5C
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x5D
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x5E
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x5F
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x60
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x61
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x62
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x63
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x64
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x65
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x66
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x67
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x68
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x69
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x6A
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x6B
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x6C
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x6D
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x6E
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x6F
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x70
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x71
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x72
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x73
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x74
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x75
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x76
[19:45:45][E][i2c.arduino:062]: Unknown error at address 0x77
[19:45:45][C][homeassistant.time:010]: Home Assistant Time:
[19:45:45][C][homeassistant.time:011]:   Timezone: 'CET-1CEST,M3.5.0,M10.5.0/3'
[19:45:45][C][ssd1306_i2c:023]: I2C SSD1306
[19:45:45][C][ssd1306_i2c:023]:   Rotations: 0 °
[19:45:45][C][ssd1306_i2c:023]:   Dimensions: 128px x 64px
[19:45:45][C][ssd1306_i2c:024]:   Address: 0x3C
[19:45:45][C][ssd1306_i2c:025]:   Model: SSD1306 128x64
[19:45:45][C][ssd1306_i2c:027]:   External VCC: NO
[19:45:45][C][ssd1306_i2c:028]:   Flip X: YES
[19:45:45][C][ssd1306_i2c:029]:   Flip Y: YES
[19:45:45][C][ssd1306_i2c:030]:   Offset X: 0
[19:45:45][C][ssd1306_i2c:031]:   Offset Y: 0
[19:45:45][C][ssd1306_i2c:032]:   Inverted Color: NO
[19:45:45][C][ssd1306_i2c:033]:   Update Interval: 1.0s
[19:45:45][E][ssd1306_i2c:036]: Communication with SSD1306 failed!
[19:45:45][C][captive_portal:088]: Captive Portal:
[19:45:45][C][homeassistant.sensor:030]: Homeassistant Sensor 'inside_temperature'
[19:45:45][C][homeassistant.sensor:030]:   State Class: ''
[19:45:45][C][homeassistant.sensor:030]:   Unit of Measurement: ''
[19:45:45][C][homeassistant.sensor:030]:   Accuracy Decimals: 1
[19:45:45][C][homeassistant.sensor:031]:   Entity ID: 'sensor.mellanvaning_temperature'

Any idea as to what could be wrong?

Check your wiring, You are saying:

The logfile is saying:

So I think your yaml is not according your wiring, you probably switched the SDA and SCL pin’s.

My bad, I mistyped.

It should be:
SCK-D1
SDA-D2

My card has a SCK instead of SCL but I thought it’ll probably work anyways?

I also have the temp sensor running off the same GND and 3V. Could that be interfering somehow? However, they’re running on different GPIO:s.

EDIT: My temp sensor stopped working as well for some reason…

The log is very clear about the problem, so check de soldering around the SCL pin of the esp and oled screen. Post also your yaml and maybe some pictures of the device.

Well, I got it working. I think the problem was that I tried to use the same resistor for the temp sensor and the display. However, once I soldered them with separate resistors it worked.

I’m now attempting to have it display the temp value but I’m having problems. Tried following this guide but my sensor keeps appearing as “nan” degrees.

sensor:
  - platform: dallas
    address: ***
    name: "unit_3"
    id: "unit_3_temp"
    unit_of_measurement: "°C"
  
  - platform: homeassistant
    id: unit_3_temp_oled
    entity_id: sensor.unit_3
    internal: true

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
      // Print "Unit-3 Temperature" in top center.
      it.printf(64, 0, id(font1), TextAlign::TOP_CENTER, "Unit-3 temperature");

      // Print time in HH:MM format
      it.strftime(0, 60, id(font1), TextAlign::BASELINE_LEFT, "%H:%M", id(esptime).now());

       it.printf(127, 23, id(font1), TextAlign::BASELINE_RIGHT , "%.1f°", id(unit_3_temp_oled).state);

The time is just displayed as 01:XX (I’m +1 GMT, so 19:56 currently), and the temperature is just “nan” degrees.

Any ideas?

Please post your complete yaml and the logfile from the device. The value ‘nan’ means that the data is not available. But why are you using platform: homeassistant for the temperature and not the value directly from the dallas sensor?

And did you add the device as an integration in HA?

Thanks for the suggestion. I’ve now used the dallas directy as per your suggestion and it actually works (the clock still doesn’t work). I will next attemp to connect it to MQTT according to this.

I had to re-route one of my LED diodes to D7/GPIO13. That particular LED has a pulsating effect depending on temperature but after installing the OLED the temp flashing has become rather irregular. Could it be that the circuit board can’t handle any more load?

esphome:
  name: unit-3
  on_boot:
    then:
      - switch.turn_off: dallas_power
      - delay: 25s
      - switch.turn_on: dallas_power

esp8266:
  board: esp01_1m

dallas:
  - pin: GPIO12
    update_interval: 5s

i2c:
  sda: GPIO04
  scl: GPIO05

time:
  - platform: homeassistant
    id: esptime

# Individual sensors
sensor:
  - platform: dallas
    address: ***
    name: "unit_3"
    id: "unit_3_temp"
    unit_of_measurement: "°C"

#Switches
switch:
  - platform: gpio
    id: "red_led_switch_unit_3"
    name: "red led_unit_3" 
    pin: GPIO14
    inverted: TRUE
    
  - platform: gpio
    id: "green_led_switch_unit_3"
    name: "green led_unit_3" 
    pin: GPIO13
    inverted: TRUE
    
  - platform: gpio
    id: dallas_power
    pin:
      number: GPIO12

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
      // Print "Unit-3 Temperature" in top center.
      it.printf(64, 0, id(font1), TextAlign::TOP_CENTER, "Unit-3 temperature");
      if (id(unit_3_temp).has_state()) {
        it.printf(50, 50, id(font2), TextAlign::BASELINE_RIGHT , "%.1f°", id(unit_3_temp).state);
      }

font:
  # gfonts://family[@weight]
  - file: "fonts/roboto.ttf"
    id: font1
    size: 15
    
  # gfonts://family[@weight]
  - file: "fonts/roboto.ttf"
    id: font2
    size: 20

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
#  password: ***
  reboot_timeout: 0s
ota:
  password: ***

captive_portal:
    

And i have such problem:


anybody know what to do?
Tnhks a lot!

I don’t see any logs, nor a config, so there is no problem!

here is conf:

esphome:
  name: nodemcu

esp8266:
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "HOb8vj0tp3UZnUXrQalXzCchQZ4B8zJWISp/QMBW****"

ota:
  password: "ee8fd253a9d79dac6d899535e73b****"

wifi:
  ssid: "Keenetic-6209"
  password: "mnbvcxz1"
  
  # Optional manual IP
  manual_ip:
    static_ip: 192.168.0.50
    gateway: 192.168.0.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Nodemcu Fallback Hotspot"
    password: "r5Ak3aZsO0HI"

captive_portal:
    
font:
  - file: 'arial.ttf'
    id: font1
    size: 8
    
i2c:
  sda: D1
  scl: D2

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: D0
    address: 0x3C
    lambda: |-
      it.print(0, 0, id(font1), "Hello World!");

there are no logs because the device is offline…

I had a similar problem on arduino ide, I don’t remember how I solved it, either the library or the esp-kernel version

offtop: how can i connect esp (with esphome) to homeassistan server via internet and not via LAN?

Try using contrast.
For example:

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: D0
    address: 0x3C
    contrast: 50
    lambda: |-
      it.print(0, 0, id(font1), "Hello World!");

Does it work on another device?

   encryption:
     key: "HOb8vj0tp3UZnUXrQalXzCchQZ4B8zJWISp/QMBW****"

I don’t use it so I can’t confirm if it’s a problem

Is the problem all the black dots? Could you please clarify.

For me it happened to be a case of wiring and selecting the wrong GPIO in the esp config. Are you hooking it up to 3.3 V or 5 V?

3.3V

before that, I also did it in arduino ide, it worked well, but I didn’t immediately get the same error, but I forgot what I fixed

Are you sure it is a SSD1306 ? I had a similar issue that was fixed by using the correct model which in my case was SH1106 128x64.

display:
  - platform: ssd1306_i2c
#    model: "SSD1306 128x64"
    model: "SH1106 128x64"
    update_interval: 0.5s
    contrast: 40%
#    reset_pin: D0
    address: 0x3C
1 Like

Gaz, Today I will try and write!

Yes, this is it! It works! thanks!