Close
0%
0%

ESPHome Integration for M5StickC PLUS2

Getting the dongle going in ESPHome

Similar projects worth following
905 views
0 followers
Bought this little dongle and I want to make it work in Home Assistant using ESPHome. Trouble is, I have no idea what I'm doing. Hijinks ensue.

DISCLAIMER: I have no idea what I'm doing here, just fumbling through and finding things that work. If it helps you, fantastic; if you break something, sorry about that. Proceed with caution.

So I bought an M5StickC PLUS2 a few weeks back, $20 or so, took a couple of weeks to clear customs. Don't really have a specific task in mind for it, or rather now that I'm playing with it it's probably not the right tool for the the task I originally had in mind. But it's still a pretty cool thing, and I'd like to be able to use it in my Home Assistant system through ESPHome. 

Trouble is, the only YAML I can find is built for a previous version, the M5StickC. The internals are slightly different -- bigger battery, ESP32-PICO-V3-02 vs ESP32PICO-D4 on the older one, different UART chip, more memory, etc. They both have a lot of the same stuff, like LEDs and buttons and a 135x240 TFT LCD, a microphone, 6-axis MMU, etc., but different processors mean different GPIO pins, so the YAML I have didn't work. So I rolled my own.

  • Basic Functions

    Dan Maloney01/05/2024 at 19:55 0 comments

    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:...
    Read more »

View project log

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates