Home Assistant 삽질기 9 (ESPHome, 그리고 Odroid-Go, 버튼)

아….주 예전에 Odroid에서 나오는 제품을 탐닉할 때, Odroid-Go 라는 제품이 나와서 구입한 적이 있었다.

Odroid-Go

위의 링크에서 구매할 수 있는데, 사서 2-3일 정도 이것저것 해보고는 방치했던 제품이었다. 그런데… 얼마전에 문득 뒷면을 보니 뚜렷하게 적혀있는 칩셋명이 눈에 들어왔다.

ESPRESSIF

순간 “어라?” 라고 생각하면서 다시 들여다보니,

ESP32-WROVER-B

라고 적혀있는 것을 확인했다. 그렇다면…. ESPHome을 올릴 수 있지 않을까?!?

라고 생각하고 ESPHome 화면을 열어서 확인해보니, 제품 선택에서 “Odroid-Go” 라고 적혀 있었다. 그래서 선택 후 WiFi 설정만 하고 로그를 찍어보니 동작한다.

하지만 해당 제품을 가지고 Home Assistant에 연결하려고 이리저리 찾아봐도 정보가 없었다. 그래서 차근 차근 해보자는 의미로 일단 Button을 동작하게 만들어 보기로 했다.

ESPHome에서 제공하는 binary_sensor를 이용하면 될 것 같았고, 해당 코드를 아래와 같이 작성하였다.

참고로 GPIO 핀 배열은 아래 링크에서 찾을 수 있었다.

Odroid-Go Wiki

esphome:
  name: test
  platform: ESP32
  board: odroid_esp32

wifi:
  ssid: "-------"
  password: "-------"

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

status_led:
  pin: GPIO2

binary_sensor:
  - platform: gpio
    pin:
      number: 32
      mode: input_pullup
      inverted: true
    name: "buttonA"
    on_press:
      then:
        - logger.log: "button A is pushed"
  - platform: gpio
    pin:
      number: 33
      mode: input_pullup
      inverted: true
    name: "buttonB"
    on_press:
      then:
        - logger.log: "button B is pushed"

코드를 들여다 보면, GPIO2를 통해서 상태 LED를 표현하고 GPIO32핀을 통해서 버튼A를, GPIO33핀을 통해서 버튼B를 감지하기로 했다. 해당 설정을 컴파일해서 바이너리 파일로 받은 후, Odroid-Go에 업로드 하였다.

결과는 아래와 같았다.

[16:11:47][D][binary_sensor:036]: 'buttonA': Sending state ON
[16:11:47][D][main:169]: button A is pushed
[16:11:48][D][binary_sensor:036]: 'buttonA': Sending state OFF
[16:11:48][D][binary_sensor:036]: 'buttonB': Sending state ON
[16:11:48][D][main:172]: button B is pushed
[16:11:50][D][binary_sensor:036]: 'buttonB': Sending state OFF
[16:11:51][D][binary_sensor:036]: 'buttonA': Sending state ON
[16:11:51][D][main:169]: button A is pushed
[16:11:51][D][binary_sensor:036]: 'buttonA': Sending state OFF
[16:11:51][D][binary_sensor:036]: 'buttonB': Sending state ON
[16:11:51][D][main:172]: button B is pushed
[16:11:51][D][binary_sensor:036]: 'buttonB': Sending state OFF
[16:11:52][D][binary_sensor:036]: 'buttonA': Sending state ON
[16:11:52][D][main:169]: button A is pushed
[16:11:52][D][binary_sensor:036]: 'buttonA': Sending state OFF
[16:11:52][D][binary_sensor:036]: 'buttonB': Sending state ON
[16:11:52][D][main:172]: button B is pushed
[16:11:52][D][binary_sensor:036]: 'buttonB': Sending state OFF

버튼을 누를 때 마다 해당 로그가 찍히는 것을 확인하였다.

Odroid-Go에는 TFT LCD와 스피커, 그리고 버튼도 10개나 달려있다. 이것으로 무엇을 할 수 있을까 한번 고민해봐야 할 것 같다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다