ESP8266 – HomeKit Essentials Lightstrip

This Project is Featured on instructables!

I have already written several blogs about ESP HomeKit. For the more experienced makers, this is not a problem. But for starters or starting makers or hobbyists it may not be so easy.

That’s why in this blog I’m going to make a LED strip using 3 “standard” modules. This should make it possible for everyone to make their own Homekit LED strip.

Hardware

Before we start our project, we have to gather the Hardware. I will sum-up the hardware and add a optional link where you can buy it.

ESP8266-01S

Many modules have been made around the ESP8266 chip. The ESP01 combines a small size with standard 2.54 mm headers. Conversely, only 2 GPIO pins are available, along with the serial RX and TX pins. For example, the module is widely used as a serial Wi-Fi/internet bridge between two microcontrollers. All Wi-Fi and TCP/IP functionality is already built in. The original blue ESP-01 modules had 512 KB of memory, the newer black modules – also known as ESP01S – have 1 MB of memory.

Relay

The SRD-05VDC-SL-C relay has three high voltage terminals (NC, C, and NO) which connect to the device you want to control. The other side has three low voltage pins (Ground, VCC, and Signal) which connect to the ESP8266-01S. Inside the relay is a 120-240V switch that’s connected to an electromagnet. When the relay receives a HIGH signal at the signal pin, the electromagnet becomes charged and moves the contacts of the switch open or closed.

MP2307 buck converter

The ‘Mini 360‘ DC-DC Buck Converter Power Module use integrally molded power inductor and synchronous rectifier control chip, smaller and more efficient. This Module can be used as a DIY mobile power, monitor power supply, power buggies, camera power supply, car power, communications equipment supply, various right size and weight for demanding applications such as aviation models, etc.

LED Strip

The LED strip can in principle be any strip, except for a color LED strip, because in this case we only have an on and off switch. In this example we use a 12 Volt white LED strip, also suitable for outdoor use, IP67 certified.

Circuit diagram Example

First, we have a look at what we are going to build. We start at the 12 Volt adapter. We have to convert it to 3.3V for the ESP8266-01S Module. Here fore, we use a P2307 buck converter. Then We have an SRD-05VDC-SL-C relay by which we control the power of the LED strip.

Writing the ESP8266

Flashing a program to the ESP8266 is a bit more difficult than flashing an Arduino. When flashing the Arduino, all you have to do is press the reset button and release while you upload a program (or even not doing anything if you have FTDI such as in Arduino UNO, NANO, MICRO, etc.). The Arduino will start uploading. With the ESP8266, you have to reset the microcontroller and start it in flashing mode using the GPIO0-to-Ground.

ESP8266-01S Program Scheme

The sketch shows the ESP8266 connected to a FTDI Programmer with a voltage regulator onboard.


NOTE: Be Sure that you have the Jumper placed on the 3.3V setting and not the 5V setting because this will destroy your ESP module!


As you can see two buttons have been added. The Left button, when pressed, connects the RESET pin to the ground and when it is released, connects the RESET pin to the VCC through a pull-up resistor.

Software preparation

We have to install esptool.py on our Mac in order to be able to flash our ESP module. To work with esptool.py, you’ll need Python 3.9 or a newer Python installation on your system. We recommend using the latest Python version, so go to Python’s website and install it in your computer.

With Python installed, open a Terminal window and install the latest stable esptool.py release with pip:

pip install esptool

Note: with some Python installations, that command may not work, and you’ll receive an error. If that’s the case, try to install esptool.py with:

pip3 install esptool
python -m pip install esptool
pip2 install esptool

After installing, you will have esptool.py installed into the default Python executables directory, and you should be able to run it with the command esptool.py. In your Terminal window, run the following command:

esptool.py

With esptool.py installed in your computer, you can easily flash your ESP32 or ESP8266 boards with the firmware.

ESP OS Preparation

To run our ESP HomeKit device, we need to install LifeCycle Manager 2 And Open RTos.

Life Cycle Manager (LCM)

Initial install, Wi-Fi settings and over the air firmware upgrades for any ESP-open-RTos repository on GitHub.

ESP-open-RTos

A community developed open source FreeRTOS-based framework for ESP8266 WiFi-enabled microcontrollers. Intended for use in both commercial and open source projects. Originally based on, but substantially different from, the Espressif IOT RTOS SDK.

Bin Files

At first, you need to download three bin files otaboot.bin, rboot.bin and blank_config.bin. The OTAboot.bin contains the Lifce Cycle Manager part. The rboot.bin contains the bootloader for the ESP8266. The blank_config.bin in just a blank config file. Now connect your device to your FTDI adapter in flash-mode.

LATESTRELEASE
File nameotaboot.bin
Version: 2.1.2


File namerboot.bin
Version: 1.4.2


File nameblank_config.bin
Version: 1.4.2


Installing Life Cycle Manger 2

The Right button, when pressed, connects the PROGRAM pin to ground and when it is released, connects the PROGRAM pin to the VCC through a pull-up resistor.

I also added A LED when the ESP is in PROGRAMMING STATE  state the LED is ON. When The ESP is in “NORMAL” state, the LED is OFF. Using these two buttons, you can do all the tasks you need with the ESP8266:

  • Working on NORMAL mode – Both buttons are released.
  • RESETTING the ESP8266 – Press the RESET button and release.
  • Start in FLASH MODE – Press both buttons, release the RESET button and then release the PROGRAM button.

PUTTING DEVICE INTO FLASH MODE

To enable ESP8266 firmware flashing, GPIO0 pin must be pulled low before the device is reset. Conversely, for a normal boot, GPIO0 must be pulled high or floating. Start in FLASH MODE – Press both buttons, release the RESET button and then release the PROGRAM button.

Go to the directory you made where you put the previously downloaded (e.g., Downloads) Root.bin, Blank_config.bin and Otaboot.bin files.

Use esptool.py to flash it in your device. First, erase flash memory from your ESP module:

esptool.py erase_flash

Normally, your ESPPort will be something like (e.g /dev/cu.usbserial-A50285BI). Then, set your device in flash-mode again, and flash the new firmware:

esptool.py -p /dev/cu.usbserial-A50285BI --baud 115200 write_flash -fs 1MB -fm dout -ff 40m 0x0 rboot.bin 0x1000 blank_config.bin 0x2000 otaboot.bin

Connecting to Life Cycle Manger 2

You must configure Wi-Fi network and OTA repository. To configure Wi-Fi settings, the device generates its own Wi-Fi in AP mode. You must connect to it in order to set up your Wi-Fi network. Before you connect to Life Cycle Manger 2, reset your module by pressing the reset button.

Simply click the Wi-Fi Icon on your Mac, and search a SSID with LCM-XXXXXX , connect to it, and wait a few seconds until a captive portal appears showing you all Wi-Fi networks that the device has found.

Then select your Wi-Fi Network you want to connect to.

Then enter your Wi-Fi passwordDo not click Join yet!

Setting a value for a LED_pin visual feedback is possible. This is done by selecting in the pull down menu a GPIO pin, where your LED is connected (Default 2 on your ESP Chip).  

Then place a tick after If active on ‘1’. 

Now you can enter the OTA repository ( this is your previously made GitHub name followed by your repository name):

AchimPieters/ESP8266-HomeKit-Essentials-Lightstrip

OTA binary file:

main.bin

To finish initial setup, click Join button and wait about 7 minutes until process finish (While installation is working, device doesn’t show anything, and buttons don’t work). After that, the LED turns on for a couple of seconds, and you will be able to add your accessory to your HomeKit ecosystem using Home App. Life Cycle Manger 2 will install your HomeKit device on your ESP.

Connecting with Homekit

Now you can add your HomeKit Outlet by scanning the QR code below. To make the connection between your ESP8266-01S – HomeKit Light strip and the HomeKit app.

Lets Start Building

Now that we have programmed our ESP8266-01S, we can get our hardware ready. We start by soldering A red wire to the VCC pin, a Black wire to the GND Pin, A white wire to GPIO0 and a 10KΩ to the CH_PD Pin.

Here you can see how it should look like.

Bent the unsolder leg to the VCC Pin And solder it.

To make sure noting can touch the pins, we use a Heat shrink tubing.

Place the Heat shrink tubing carefully around the pins, resistor, and cables.

Not everybody has a heating gun, but you can shrink the tube with the heat of your soldering iron.

On the back of your ESP8266-01S Module, I used some double-sided tape.

Paste the ESP8266-01S module on top of the Really Module like the image below.

Now we take the MP2307 buck converter module and solder a red wire to the VCC output pin, a Black wire to the GND output pin. On the other side, we also solder two wires.

We paste the MP2307 buck converter with double-sided tape to the Relay module as shown below.

Connect the VCC Out wire to the middle of the screw terminal of the Relay module. Also add an extra wire.

Solder the VCC red wire to the VCC Pin of the Relay and the Black GND wire to the GND Pin of the Relay Module. Connect the 12 Volt Wire of the LED led strip to The screw terminal of the real module.

Now solder the Middle wire of the Relay screw terminal to the VCC of the power plug. Then Solder the GND Wire of the LED Strip and the GND wire of the MP2307 buck converter module and connect it to the GND pin of the Power Plug.

NOTE: DO NOT CONNECT THE RED VCC AND BLACK GND WIRES TO THE ESP8266-01S MODULE YET!

Before we can connect the MP2307 buck converter module and the ESP8266-01S module, we have to change the output voltage of the MP2307 buck converter module. Connect the 12 Volt Power adapter to your Power Plug en connect your multimeter to the Output wires. Then turn the Pot-resistor until you have 3.3V.

Once you have calibrated the MP2307 buck converter module, solder the Red wire to the VCC Pin of the Really module. And the Black wire to the GND pin of the Really Module. Plugin the 12 Volt power supply, and you can use your own made HomeKit Led strip!

Troubleshooting

This new LCM code is able to load/update the bootloader from GitHub. The new bootloader is able to count the amount of short power cycles (<1.5s) From the second cycle, the cycles must be shorter than 4 seconds. Also, a LED is lit if defined.

Note: The default value of 3 reduces the chance of user miscounting and triggering something else than intended or playful children.

Power cyclesSolution
5 ~ 7Check for new code / Update
8 ~ 10Erase wifi info and clear Life Cycle Manager 2 mode
11 ~ 13Erase wifi info and set Life Cycle Manager 2 mode and gain access to emergency mode
14 ~ 16Factory reset

Note: To produce and sell HomeKit compatible accessories, your company need to be certified for that (https://developer.apple.com/homekit/, If you’re interested in developing or manufacturing a HomeKit accessory that will be distributed or sold, your company must enroll in the MFi Program.) Espressif have their implementation of HomeKit framework, but it will give you it only if you have MFi certification (notice this text at the bottom of page you mentioned: Please note that the Espressif HomeKit SDK is available to MFi licensees only, and you need to provide the Account Number for verification purposes when requesting the SDK.).This project is a non-commercial implementation of HAP protocol, not meant for commercial use.


REFERENCE

Maxim Kulkin, esp-wifi-config (2019), Library to bootstrap WiFi-enabled accessories WiFi config, https://github.com/maximkulkin/esp-wifi-config Paul Sokolovsky, esp-open-sdk (2019), Free and open (as much as possible) integrated SDK for ESP8266/ESP8285 chips, https://github.com/pfalcon/esp-open-sdk Espressif Systems, esptool (2019), ESP8266 and ESP32 serial bootloader utility, https://github.com/espressif/esptool HomeACcessoryKid, life-cycle-manager (2019), Initial install, WiFi settings and over the air firmware upgrades for any esp-open-rtos repository on GitHub, https://github.com/HomeACcessoryKid/life-cycle-manager 

Scroll to Top