ESPHome client for controlling a Lego Duplo train.
Two variants are available:
| Variant | Config file | MCU | Communication | Backend required |
|---|---|---|---|---|
| HTTP (original) | train-pusher-client.yaml |
ESP8266 (D1 Mini) | HTTP REST API | Yes (train-pusher) |
| BLE (direct) | train-pusher-ble.yaml |
ESP32 (D1 Mini 32) | Bluetooth LE | No |
Table of Contents
Activate Python virtualenv and install required packages. Check ESPHome docs for Python requirements:
python3 -m pip install virtualenv
python3 -m virtualenv venv
source venv/bin/activate
pip install -r requirements.txtTo deactivate Python virtualenv run deactivate
NOTE: Python virtualenv MUST be activated with
source venv/bin/activateeach time before usingesphome
NOTE: First time upload should be performed via cable, all subsequent uploads could be performed Over-The-Air (OTA upload)
To build and upload firmware activate Python virtualenv and install packages from the requirements.txt as described in the Project configuration section above and then run ESPHome:
esphome run train-pusher-client.yamlIn order to check device logs run:
esphome logs train-pusher-client.yamlMore details on ESPHome usage could be found via esphome -h command and on the official website
The BLE variant (train-pusher-ble.yaml) uses an ESP32 to communicate directly with the train via Bluetooth Low Energy, eliminating the need for the Node.js backend.
- D1 Mini 32 (ESP32) -- the ESP8266 does not support BLE
- Same TLC5947 LED driver and button hardware as the HTTP variant
Turn on the train and scan for BLE devices using one of these methods:
- nRF Connect mobile app (iOS/Android) -- look for a device named
LPF2 Smart Hub - ESP32 BLE scan -- flash the config with a placeholder MAC, check the ESPHome logs for discovered devices
| Button | ESP8266 (D1 Mini) | ESP32 (D1 Mini 32) | Reason |
|---|---|---|---|
| Stop | GPIO 0 | GPIO 25 | GPIO 0 is a strapping pin on ESP32 |
| Brake | GPIO 2 | GPIO 26 | GPIO 2 drives onboard LED on ESP32 |
All other pins (4, 5, 12, 13, 14, 15, 16) remain the same.
Set the train's BLE MAC address in train-pusher-ble.yaml substitutions:
substitutions:
train_mac_address: "AA:BB:CC:DD:EE:FF"source venv/bin/activate
esphome run train-pusher-ble.yaml| Button | TLC5947 pin | D1mini pin |
|---|---|---|
| Green Backward | 22 | 5 |
| Green Forward | 23 | 12 |
| White | 19 | 4 |
| Yellow | 14 | 5 |
| Blue | 17 | 2 |
| Red | 20 | 0 |