Lambda question

I am trying to add a SSD1306 OLED Display to my project, but adding the sample configuration produces an error on the lambda line (line# 65). I don’t grok lambda; what am I missing here?

EDIT: Because it is on the last line of the YAML file, I did not see the error message. I am missing a font file? What do I put here? Is there a default font?

substitutions:
  display_name: temperature-1
  
esphome:
  name: ${display_name}
  platform: ESP8266
  board: d1_mini

# Enable logging
logger:
  level: DEBUG
  
# Enable Home Assistant API
api:

ota:
  safe_mode: True

wifi:
  ssid: "Kwinnet"
  password: !secret wifi_password
  fast_connect: true


#-----------------------------
dallas:
  - pin: D3      
    update_interval: 5s    
    
sensor:
  # WiFi Signal sensor.
  - platform: wifi_signal
    name: ${display_name} WiFi Signal
    update_interval: 60s
 
 
  #Dallas DS18B20 Temperature sensor  
  - platform: dallas
    address: 0x67020D9246E81C28
    name: ${display_name} Temperature
    unit_of_measurement: '°F'
    filters:
    - lambda: return x * (9.0/5.0) + 32.0;


#Blink the LED_BUILTIN if there's a problem, on otherwise.    
status_led:
  pin:
    number: D4     #GPIO2, LED_BUILTIN
    inverted: True
    
    
# Example configuration entry
i2c:
  sda: D1
  scl: D2

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

Here is the section that explains how to define a font (I’m not aware of any default font):

Before you can specify and use a font you need to define them first.

Thanks for the link.

Part of my frustration with Home Assistant and ESPHome in particular is that while the documentation is usually excellent, it is too often incomplete. We’re somehow supposed to know where to look for the missing information. Why couldn’t the sample code be complete? How hard is it to add the font component in the example so that the example would work without further research?

2 Likes

This link is an example of excellent documentation.

I wish there were an index of tutorials like this.

This is the page I was working from: SSD1306 OLED Display.
It would have been really helpful if the page you linked were also in the “See also” of the SSD1306 OLED Display page.

It compiles now after I created the fonts folder and copied a font from Windows.
It doesn’t work yet, the log shows: “Communication with SSD1306 failed!”, but I think that’s my OLED shield. The vendor of the part doesn’t say which I/O pins are used for SDA/SCL. I assumed the “default” D1/D2, but that doesn’t work.

Your comments are appreciated.

It’s all working now. Turns out that the shield uses D3 for the OLED Reset.