Skip to content

MagicMirror module to control ws2812 led strips over TCP

License

Notifications You must be signed in to change notification settings

coderpussy/MMM-WS281X-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MMM-WS281X-Server

This module is designed to use the RPI-WS2812-Server (TCP socket) project from Tom. RPI-WS2812-Server uses rpi_ws281x PWM driver code from jgarff. Goal was to use ws2812 LED strips on Magic Mirror without the need of root user in NodeJS. Problem is direct memory access which can only be done by a user with privileged rights.

Platform

Development Status

This module works so far. ;-) There is still a lot of room for improvement and the source code could be better. Code improvements of this project are very welcome.

Screenshot

No screenshot can be displayed, because this project is executed in the background. It is possible that the connected LEDs are triggered at system start, system messages or camera movement. There is also an API endpoint to load sequence files or set individual colors manually.

Requirements

Currently this module is able to control 'ws281x' stripes. Neopixels or any other WS2812 stripe should work fine.

Dependencies

Needs to be installed (local or remote):

If the face recognition module by Thierry Nischelwitzer is additionally used:

Installation

RPI-WS2812-Server

Please follow the installation instructions on the project maintainer's page.

Also note the section for a system service installation. You need to do this. In case of trouble setting up the system service after make command please change the makefile. Just put a # in line 58 in front of the command. Reason is that directly after compiling the server a system service is not created or running. But the makefile instead await a running service. To finish that step successfully you have to work around like i described.

# systemctl stop ws2812svr.service

MMM-Face-Reco-DNN

Cloning the module

cd ~/MagicMirror/modules
git clone https://github.com/coderpussy/MMM-WS281X-Server.git
cd MMM-WS281X-Server
npm install

Add the module to MM

Open the file ~/MagicMirror/config/config.js and add the following to your modules section:

{
    module: 'MMM-WS281X-Server',
    config: {
        hostname: '192.168.0.10',
        port: 9999,
        ledOnStart: false,
        ledOnStartEffect: 'start',
        showAlert: false,
        showAlertEffect: 'alert',
        useMMMFaceRecoDNN: false,
        userLoginEffect: 'login',
        userLogoutEffect: 'logout',
        channel: 1,
        led_count: 24,
        led_type: 0,
        invert: 0,
        global_brightness: 255,
        gpionum: 18,
        spi: false,
        spi_dev: '/dev/spidev0.0',
        spi_speed: 20,
        alt_spi_pin: 10
    }
}

Module Configuration Options

If RPI-WS2812-Server is running and listening on TCP socket everything should work out of the box after installing this module and set up IP of server. In case of different types of LED strips chip and manually assign effects to strips from API Endpoint you have to set the config parameters like described on RPI-WS2812-Server project page.

Take a look in this module effects folder to get some ideas how to adjust effects or create new ones by editing the text files. It is a kind of ledscript language designed by the RPI-WS2812-Server project leader.

Config Description
hostname IP address of running ws2812 server instance. Could be same or remote machine
Default value: 127.0.0.1
port Port where server instance is running
Default value: 9999
ledOnStart Want to have an effect on mirror start
Default value: false
ledOnStartEffect Saved *.txt file
Default value: start
showAlert Show LED effect on system alert
Default value: false
showAlertEffect Saved *.txt file
Default value: alert
useMMMFaceRecoDNN Set to true if module is used for LED effect
Default value: false
userLoginEffect Saved *.txt file
Default value: login
userLogoutEffect Saved *.txt file
Default value: logout
channel LED configuration taken from Server project
Default value: 1
led_count How many LEDs are involved
Default value: 24
led_type What type of LED is used. Take a look at server project
Default value: 0
invert Invert colors at initialization
Default value: 0
global_brightness Set global brightness
Default value: 255
gpionum Set GPIO or
Default value: 18
spi If you want use SK9822 LED strips
Default value: false
spi_dev SPI device
Default value: /dev/spidev0.0
spi_speed SPI speed in Mhz
Default value: 20
alt_spi_pin Alternative SPI pin
Default value: 10

Trigger from another module

Notifications shown in the default alert module. MMM-Face-Reco-DNN module can be used for LED effect running by camera movement recognition on login or logout.

API Endpoint

Possible combinations of API commands

http://yourmagicmirror/WS281X-Server/animation?name=fade
http://yourmagicmirror/WS281X-Server/resetled
http://yourmagicmirror/WS281X-Server/set?color=blue
http://yourmagicmirror/WS281X-Server/set?hex=fff
http://yourmagicmirror/WS281X-Server/set?hex=ffffff
http://yourmagicmirror/WS281X-Server/set?hex=ffffffff
http://yourmagicmirror/WS281X-Server/set?r=25&g=200&b=200
http://yourmagicmirror/WS281X-Server/set?wheel=20

CURL Example

curl -X GET "http://yourmagicmirror/WS281X-Server/animation?name=gradient"

Credits

Big hugs and thx to:

About

MagicMirror module to control ws2812 led strips over TCP

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published