Skip to content

System for controlling neopixel-compatible LED strips (ws2812b and similar)

Notifications You must be signed in to change notification settings

ivanovsaleksejs/leds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project aims to control ws2812b LED strips via UART port using simap/pixelblaze_output_expander or/and via WiFi connecting to several ESP32 devices with LED strips connected to each, using Raspberry Pi as a controller and host for node server and react based UI. It can switch LED strips on and off, change animations etc, all from your phone or PC or remote controller.

Installation

This guide will assume that you're using a /var/www/leds as a working directory for this project. If this is not the case then make sure to make adjustments in leds.service file and in your web server config.

ESP32

Download and write a micropython firmware into ESP32. If you want to be able to use an optimized function neopixel_write_compressed then you need to use my fork of this firmware. If you use up-to-date fork it will probably have a bug that will make LEDs flicker randomly once WiFi module is on. To avoid this I recommend to build from v1.9.4-701-g10bddc5c2. You can download a build here.

You can use esptool for flashing:

esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 firmware_1.9.4.bin

Your system may identify your ESP32 other than /dev/ttyUSB0. You can use ls /dev/ttyUSB* before and after connecting ESP32 to find a correct name. You can use other baud rate than 460800 if you wish.

Create files config.json and stripData.json from examples. Pay attention to controllerHostname parameter in config.json - it must be set the same as your Raspberry Pi local domain. Copy all .py files as well as .json files from esp32 folder onto your ESP32 (you can use ampy, for example):

ampy -p /dev/ttyUSB0 put config.json

You can use screen to check if everything works:

screen /dev/ttyUSB0 115200

If you see a repl prompt then ESP32 is connected to WiFi and discovered your Raspberry Pi by local domain.

Output expander

The expander that you can purchase on tindie is ready to use. However, instead of 2000000 baud rate you need to set it to 2304000 to make it work with RPi UART. Expander allows you to control more output channels (up to 64 on one UART pin) thus allowing you to get around the timing limitation of ws2812b.

Wiring

Connect LED strip to your ESP32. Make sure you have connected signal wire to the right pin (see config.json). Also make sure you have connected ESP32 ground to LED strip ground - otherwise you may face unpredictable behavior. Make sure you have powered your setup well - 5V LEDs like ws2812b require 25mA each when provided a white (0xFFFFFF) color, so, if your strip has 60 LEDs it may require up to 1.6A. It's better to use separate PSU (5V 2A or better) for each strip in this case.

Connect Data pin of the expander to RPi TX pin (usually 8th pin). Connect 5V to expander. Make sure you link grounds of strips, expander and RPi.

Raspberry Pi

Install nginx and redis on your RPi. You can use other web server software if you like but nginx is easier to configure and it's faster and stable. Configure avahi daemon (it is installed by default if you use raspbian) to specify a local domain according to esp32/config.json. Configure nginx to redirect all /backend links to 8081 port:

root /var/www/leds/build
location /backend {
    rewrite ^/backend/(.*) /$1 break;
    proxy_pass http://$server_addr:8081;
}

Install build-essential and libudev-dev necessary for usb lib: apt-get install build-essential libudev-dev. This will allow you to use usb based remote controller.

Install node and yarn. Run

yarn

to install all dependencies.

Running

Server

You can start server by running

sudo yarn server

Or you can register it as systemd item. Create leds.service from example. Create a symlink to it in /etc/systemd/system and enable it with

sudo systemctl enable leds

ESP32

Connect the power to your ESP32 and LED strips. File main.py should be executed automatically and default sequence will be launched.

Frontend

Create src/config.json from example. Build an app with

yarn build

Demo

About

System for controlling neopixel-compatible LED strips (ws2812b and similar)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published