Skip to content

ESPHome configuration for a Bluetooth Low Energy heart rate display on an M5Stack Core or LilyGO TTGO T-Display ESP32

License

Notifications You must be signed in to change notification settings

koenvervloesem/ESPHome-Heart-Rate-Display

Repository files navigation

ESPHome Heart Rate Display

Continuous integration License

This ESPHome configuration builds firmware that shows the heart rate sent by a Bluetooth Low Energy heart rate sensor on the display of an M5Stack Core or LilyGO TTGO T-Display ESP32.

This looks like this on an M5Stack Core:

An M5Stack Core as a heart rate display

And like this on a LilyGO TTGO T-Display ESP32:

A LilyGO TTGO T-Display ESP32 as a heart rate display

And like this on a SH1106 1.3 inch OLED display:

A 1.3 inch OLED display as a heart rate display

Requirements

  • M5Stack Core, LilyGO TTGO T-Display ESP32 or a 1,3 inches SH1106 OLED display and an ESP32
  • ESPHome 1.19.0 or later
  • A heart rate sensor that implements the Heart Rate Measurement characteristic of Bluetooth Low Energy.

Limitations

  • This configuration doesn't enable Wi-Fi because the combination of the BLE client, display and Wi-Fi components uses too much memory, resulting in a boot loop. See issues #1336, #1731 and #2045.
  • On older M5Stack Core models, the colors are inverted. See issue #1893. One solution is to copy the ili9341 directory from your ESPHome installation's components directory and put it in a directory custom_components next to your YAML file. Then change the line this->invert_display_(true); in the file custom_components/ili9341/ili9341_display.cpp to this->invert_display_(false);. When compiling the firmware again, ESPHome uses your custom component instead of the default one.

Usage

There are three example configurations in this repository:

Change the ble_mac substitution to the BLE MAC address of your heart rate sensor and in case you are using the SH1106 OLED Display adapt the node_board to your choice.

After this, flash the firmware to your device, e.g. with:

esphome run m5stack_example.yaml --device /dev/ttyUSB0

If you successfully created a configuration for another ESP32 board or another standalone display, please contribute an example configuration with a pull request.

How does this work?

ESPHome 1.18 added support for an ESP32 BLE Client and a BLE Sensor, which allows you to connect to Bluetooth Low Energy devices and read characteristics. This initial implementation was limited to one-byte characteristics which it interprets as float values. But thanks to pull request #1851 (Add optional lambda to BLESensor for raw data parsing), you can also read the raw bytes, and this is available since ESPHome 1.19.

This ESPHome configuration makes use of these raw bytes in two ways (in common/heart_rate.yaml):

  • Read the heart rate value from the second and third bytes of the Heart Rate Measurement characteristic (see the Heart Rate Service specification).
  • Read the raw bytes of the Device Name characteristic and convert it to a string, which is published to a text sensor.

Learn more about ESPHome

If you want to learn more about ESPHome, read my book Getting Started with ESPHome: Develop your own custom home automation devices and the accompanying GitHub repository koenvervloesem/Getting-Started-with-ESPHome.

License

This project is provided by Koen Vervloesem as open source software with the MIT license. See the LICENSE file for more information.

The included Roboto font is licensed under the Apache License, Version 2.0.

The C++/runtime codebase of the ESPHome project (file extensions .c, .cpp, .h, .hpp, .tcc, .ino) are published under the GPLv3 license. The Python codebase and all other parts of the ESPHome codebase are published under the MIT license. See the ESPHome License for more information.