# Micropython Ikea Lights # Table of Contents * [Overview](#overview) * [Notes On ESP32 and ESP8266 Boards](#notes-on-esp32-and-esp8266-boards) * [Requirements](#requirements) * [Hardware Requirements](#hardware-requirements) * [Software Requirements](#software-requirements) * [Schematic/Connection](#schematicconnection) * [Quick Start](#quick-start) * [API Endpoints](#api-endpoints) * [/shutdown](#shutdown) * [/status](#status) * [/lights/on](#lightson) * [/lights/off](#lightsoff) * [/lights/rgb](#lightsrgb) * [/lights/preset/bounce](#lightspresetbounce) * [/lights/preset/cycle](#lightspresetcycle) * [/lights/preset/niagra](#lightspresetniagra) * [/lights/preset/rainbow](#lightspresetrainbow) * [Hardware](#hardware) * [LOLIN D32](#lolin-d32) * [PIN Layout](#pin-layout) * [Fritzing Part](#fritzing-part) * [Erase Firmware Note](#erase-firmware-note) # Overview This project is looking at using an [Ikea Vidja](https://www.ikea.com/us/en/p/vidja-floor-lamp-with-led-bulb-white-30416149/) 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](https://www.instructables.com/DIY-WiFi-RGB-Floor-Lamp-Ikea-Hack/). I started working on getting web calls working to the controller, using [TinyWeb](https://github.com/belyalov/tinyweb). This worked except I ran into issues related to stopping a currently running preset (e.g. running LED loop). Lo and behold, [Bhavesh](https://bhave.sh/micropython-microdot/) posted an article solving this exact issue by using [microdot](https://github.com/miguelgrinberg/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 * [Ikea Vidja](https://www.ikea.com/us/en/p/vidja-floor-lamp-with-led-bulb-white-30416149/) floor lamp * ESP32 Development Board - See [My Hardware](#my-hardware) for info on my setup * NeoPixel Like LEDs - I'm using [BTF-Lighting WS2812B](https://smile.amazon.com/dp/B01CDTEJBG) lights * 300-500Ω Resistor * 1000uF Capacitor ## Software Requirements * [microdot](https://github.com/miguelgrinberg/microdot) - The underlying asyncio flask-like webserver (Both files from [/src](https://github.com/miguelgrinberg/microdot/tree/main/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](https://learn.adafruit.com/adafruit-neopixel-uberguide/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](https://randomnerdtutorials.com/micropython-ws2812b-addressable-rgb-leds-neopixel-esp32-esp8266) ## /lights/preset/cycle Accepts r,g,b arguments for the starting color Light display sourced from [here](https://randomnerdtutorials.com/micropython-ws2812b-addressable-rgb-leds-neopixel-esp32-esp8266) ## /lights/preset/niagra Light display sourced from [here](https://www.instructables.com/DIY-WiFi-RGB-Floor-Lamp-Ikea-Hack/) ## /lights/preset/rainbow Light display sourced from [here](https://randomnerdtutorials.com/micropython-ws2812b-addressable-rgb-leds-neopixel-esp32-esp8266) # Hardware ## LOLIN D32 I'm utilizing the Wemos [LOLIN D32 v1.0.0](https://www.aliexpress.com/item/WEMOS-LOLIN32-V1-0-0-wifi-bluetooth-board-based-ESP-32-4MB-FLASH/32808551116.html) however and ESP32 should work well here. This is based on the ESP32 ([See datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)) | 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](static/wemos_lolin_d32-diagram.png) **[[Source](http://forum.hobbycomponents.com/viewtopic.php?f=111&t=2462)]** ### Fritzing Part I created a [Fritzing](https://fritzing.com) part for the Wemos LOLIN D32. [Download Here](static/wemos-lolin-d32.fzpz) ### 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.