I can't think of any organized way to walk through what I did to get to the point I am right now, so I'm just going to put the YAML here and let the comments speak for themselves. I wish the syntax highlighting was nicer, but there it is.
Based on the YAML I found for the M5StickC Plus on the ESPHome devices page:
substitutions:
devicename: test-dongle
upper_devicename: DONGLE TESTING
esphome:
name: $devicename
platform: ESP32
board: m5stick-c #there are only a few options, and this is the closest
platformio_options:
upload_speed: 115200
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: $devicename Fallback Hotspot
password: !secret wifi_password
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "<redacted>"
ota:
password: "<redacted>"
# The older version of this dongle has an AWP192 power management chip, so
# the YAML I started with had support for reading the battery voltage
# from the PM chip. The AWP192 was also needed to turrn the LCD backlight
# on for some reason. The PLUS2 stick doesn't have a power management chip,
# so we just read the battery voltage from the ADC on GPIO38 (got that
# little tidbit from diving into the schematic.)
sensor:
- platform: adc
pin: GPIO38 # ADC1_CH2
attenuation: 11db # because reasons?
update_interval: 60s
name: "Battery Voltage"
filters:
- multiply: 2.0 # Schematic shows a voltage divider with
# two 100k resistors feeding GPIO38, so
# we multiply by two. Seems to be giving
# accurate readings -- or at least reasonable
# Built-in 6-axis intertial measurement unit (IMU) that also includes a temperature sensor
# Pretty much just pulled this from the ESPHome docs, seems to work well
- platform: mpu6886
i2c_id: bus_a
address: 0x68
update_interval: 10s
accel_x:
name: "MPU6886 Accel X"
accel_y:
name: "MPU6886 Accel Y"
accel_z:
name: "MPU6886 Accel z"
gyro_x:
name: "MPU6886 Gyro X"
gyro_y:
name: "MPU6886 Gyro Y"
gyro_z:
name: "MPU6886 Gyro z"
temperature:
name: "MPU6886 Temperature"
# Button setup. The dongle has three buttons, this code does useful(ish)
# things with them:
# Button A (big one on front): Turns off LCD backlight while pressed
# Button B (small one on side): Sounds 1000Hz tone while pressed
# Button C (other small one): Supposed to turn off the internal LED,
# but doesn't work
binary_sensor:
- platform: gpio
pin:
number: GPIO37
inverted: true
name: ${upper_devicename} Button A
on_press:
then:
- light.turn_on: display_bl
on_release:
then:
- light.turn_off: display_bl
- platform: gpio
pin:
number: GPIO39
inverted: true
name: ${upper_devicename} Button B
on_press:
then:
#- light.turn_on: led1
- output.turn_on: buzzer
- output.ledc.set_frequency:
id: buzzer
frequency: "1000Hz"
- output.set_level:
id: buzzer
level: "50%"
on_release:
then:
#- light.turn_off: led1
- output.turn_off: buzzer
- platform: gpio
pin:
number: GPIO35
inverted: true
name: ${upper_devicename} Button C
on_press:
then:
- light.turn_on: led1
on_release:
then:
- light.turn_off: led1
# Built-in LED is on GPIO19. The IR LED is also on the same GPIO. One or
# both of them get VERY hot while LEDs are on.
light:
- platform: monochromatic
output: builtin_led
name: ${upper_devicename} Led
id: led1
- platform: monochromatic
output: backlight
name: ${upper_devicename} Backlight
id: display_bl
output:
- platform: ledc
pin: 19
inverted: true
id: builtin_led
- platform: ledc # Buzzer is connected to GPIO2, and we
pin: 2 # use PWM to control it, hence the ledc
inverted: true # platform
id: buzzer
- platform: ledc # TFT backlight is on GPIO19, ditto PWM
pin: 27
inverted: true
id: backlight
# This block was what was killing the original compile, haven't played
# with it yet
#remote_transmitter:
# - pin:
# number: GPIO9
# carrier_duty_percent: 50%
# id: internal
# From the schematic it looks like the TFT is using SPI
spi:
clk_pin: GPIO13
mosi_pin: GPIO15
# MMU uses I2C
i2c:
- id: bus_a
sda: GPIO21
scl: GPIO22
scan: True
# Get something on the display
font:
- file: "gfonts://Roboto"
id: roboto
size: 18
color:
- id: my_white
red: 100%
green: 100%
blue: 100%
# 1.14 inch, 135*240 Colorful TFT LCD, ST7789v2
display:
- platform: st7789v
model: TTGO TDisplay 135x240
cs_pin: GPIO5 # Had to change pin assignments
dc_pin: GPIO14
reset_pin: GPIO12
rotation: 270
lambda: |-
it.print(80, 0, id(roboto), id(my_white), TextAlign::TOP_CENTER, "M5Stick Test");
# Haven't worked on audio yet
#i2s_audio:
# id: bus_i2s
# i2s_lrclk_pin: G26
# i2s_bclk_pin: G0
#microphone:
# - platform: i2s_audio
# i2s_din_pin: GPIO34
# i2s_audio_id: bus_i2s
# adc_type: external
# pdm: true
# id: mic
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.