Code for ESP8266 WiFi module with NodeMcu firmware to control PCA9685 PWM controller. You can easily build WiFi-controlled smart home equipment or toys with this. Also contains a demo application: RGB LED strip with WiFi.
Licensed under WTFPL
- Any ESP8266 module
- PCA9685 connected to ESP's GPIOs
TODO: example schematics, photo/video of actual hardware
TODO: maybe write something useful here
Read the source
There are also some useful stuff in utils.lua
Directory rgbstrip
contains an application to control a RGB LED strip over WiFi via MQTT protocol. RGB channels are usually driven with MOSFETs controlled by PWM.
- Connect ESP8266 to PC (we assume that device is connected to
/dev/ttyUSB0
) - Install
NodeMCU
, if you don't have one:
./esptool/esptool.py --port /dev/ttyUSB0 erase_flash
./esptool/esptool.py --port /dev/ttyUSB0 write_flash 0x0 nodemcu-firmware/pre_build/latest/nodemcu_latest.bin
- Edit
rgbstrip/init.lua
and change configuration as you wish - Upload Lua files
for f in pca9685.lua rgbstrip/*.lua; do
./luatool/luatool.py -f "$f" -t "`basename $f`" -p /dev/ttyUSB0 || break
done
- Pre-compile
pca9685.lua
andserver.lua
on ESP8266. This is needed becauseNodeMCU
sometimes runs out of RAM when loading Lua modules. Open your favorite serial terminal program (warning:init.lua
configures UART to 115200 baud,NodeMCU
's default is 9600). Run following commands inNodeMCU
REPL:
node.compile('pca9685.lua')
node.compile('server.lua')
- If there was a compilation error, you can reset device and try again. Shit happens.
- If compilation was succesfull, there will be created
pca9685.lc
andserver.lc
files inNodeMCU
filesystem. Now original files can be removed:
file.remove('pca9685.lua')
file.remove('server.lua')
To control RGB strip, publish a MQTT message with topic <mqtt_topic>/rgb
(where <mqtt_topic>
is what you set in init.lua
) and payload with desired color as hex string (e.g. ff00ff
- purple).
It uses mosquitto to publish MQTT messages and Xdialog for simple GUI.
- Set your MQTT credentials in
mqtt_args
variable in the beggining of the script - Run
rgbstrip.sh
with one of the following argumentsw
orwhite
: set total brightness (r=g=b)c
orcolor
: set color with regular color choose dialogh
orhsvcolor
: set color with Hue/Saturation/Value slidersm
ormidi
: read MIDI control events from ALSA and set color accordingly- any other value: set color with Red/Green/Blue sliders