Setting up an Ikea light using MicroPython and RGB lights
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

7.5 KiB

Micropython Ikea Lights

Table of Contents

Overview

This project is looking at using an Ikea Vidja floor lamp with RGB LEDs controlled via an ESP32 or ESP8266 board.

It can be controlled through a webpage or through API GET requests, such as IOS Shortcuts

This was initially following along with this. I started working on getting web calls working to the controller, using TinyWeb. This worked except I ran into issues related to stopping a currently running preset (e.g. running LED loop). Lo and behold, Bhavesh posted an article solving this exact issue by using microdot. So many thanks for getting me on the right path there.

Notes On ESP32 and ESP8266 Boards

I have found that the LED lights can be controlled using the ESP8266 boards but not particularly well. A few issues I noticed:

  • When cycling through colors, blue would end up becoming red while only displaying blue colors for very brief moments or not at all
  • Noticeable flickering of the LEDs
  • Slow transitioning

The first 2 issues were likely due to the ESP8266 boards only supplying 3.3v, instead of that 5V that can be supplied by the E32s. The last issue might be due to the processing power behind chips or the 5V as well.

Best to use an ESP32 boards and not an ESP8266, although an ESP8266 can sort of work.

Requirements

Hardware Requirements

Software Requirements

  • microdot - The underlying asyncio flask-like webserver (Both files from /src)
    • IMPORTANT: These are not included as we should make sure to get the latest version from pip or github above

Schematic/Connection

This is pretty straight forward and I'll add a picture later at some point. But:

  • Pin 23 -> 300-500Ω Resistor -> Data pin of LEDs
    • On my LEDs, the data pin is the center line
  • 1000uF Capacitor between positive and negative of LED strip
    • Adafruit Best Practices notes this should be as close to the LEDs as possible. I have mine pushed into the connector itself, similar to the picture on the Best Practices page

Quick Start

Modify the config.py file with wifi, pin, and pixel settings

esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0x1000 images/images/esp32-20220117-v1.18.bin
wget https://raw.githubusercontent.com/miguelgrinberg/microdot/main/src/microdot.py
wget https://raw.githubusercontent.com/miguelgrinberg/microdot/main/src/microdot_asyncio.py
ampy --port /dev/ttyUSB0 put microdot.py
ampy --port /dev/ttyUSB0 put microdot_asyncio.py
ampy --port /dev/ttyUSB0 put library/pixels.py
ampy --port /dev/ttyUSB0 put library/wifi.py
ampy --port /dev/ttyUSB0 put boot.py
ampy --port /dev/ttyUSB0 put config.py
ampy --port /dev/ttyUSB0 put main.py
ampy --port /dev/ttyUSB0 put index.html

# Reboot the microcontroller

At this point, you should be able to access the webpage on the esp32 at http://IP/

You can also use something like shortcuts to send GET requests to the various endpoints

API Endpoints

/shutdown

Shuts the microDot application down.

Note: It can only be brought back up by restarting the esp32 or through usb and import main

/status

Provides memory and network information

/lights/on

Sets rgb of the lights to 255, 255, 255

/lights/off

Sets rgb of the lights to 0, 0, 0

/lights/rgb

Allows for changing the color of the string of lights using RGB. Requires r,g,b arguments in the GET request

/lights/preset/bounce

Accepts r,g,b arguments for the starting color

Light display sourced from here

/lights/preset/cycle

Accepts r,g,b arguments for the starting color

Light display sourced from here

/lights/preset/niagra

Light display sourced from here

/lights/preset/rainbow

Light display sourced from here

Hardware

LOLIN D32

I'm utilizing the Wemos LOLIN D32 v1.0.0 however and ESP32 should work well here.

This is based on the ESP32 (See datasheet)

Description Value
Microcontroller ESP-32
Board Power Supply (USB) 5V
Supported Batteries Lipo Battery 3.7V
Operating Voltage 3.3V
Lithium battery interface 500mA Max charging current
Digital I/O Pins 22
Analog Input Pins 6 (VP, VN, 32, 33, 34, 35)
Analog Output Pins 2 (25, 26)
LED BUILTIN Pin 5
Clock Speed(Max) 240Mhz
Flash 4M bytes
Length 57mm
Width 25.4mm
Weight 6.1g

PIN Layout

Wemos Lolin D32 Diagram

[Source]

Fritzing Part

I created a Fritzing part for the Wemos LOLIN D32.

Download Here

Erase Firmware Note

If there is no boot/flash button and you get the error Wrong boot mode detected (0x13)! when attempting to erase the flash, try grounding Pin 0 and resetting.