Close

Node-red flow, ESP and Teensy considerations

A project log for IKEA LACK Table Lamp Clock

A ceiling-mounted ikea table, with dimmable LEDs and a bunch of small lamp shades to show time.

christophChristoph 01/16/2020 at 22:560 Comments

The lamp will subscribe to three MQTT topics:

Flow screenshot:

Flow code:

[{"id":"aa4bc419.8a1788","type":"tab","label":"lack clock","disabled":false,"info":""},{"id":"4e9f9b17.5f2734","type":"inject","z":"aa4bc419.8a1788","name":"","topic":"lack_lamp/time","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":120,"wires":[["5653f91e.a05548"]]},{"id":"600a5141.5a463","type":"ui_slider","z":"aa4bc419.8a1788","name":"","label":"brightness top","tooltip":"","group":"95d92d08.7ad69","order":0,"width":0,"height":0,"passthru":true,"outs":"all","topic":"","min":0,"max":"100","step":1,"x":220,"y":220,"wires":[["2c8d835f.7c011c"]]},{"id":"25cdf3b3.c8379c","type":"ui_slider","z":"aa4bc419.8a1788","name":"","label":"brightness bottom","tooltip":"","group":"95d92d08.7ad69","order":0,"width":0,"height":0,"passthru":true,"outs":"all","topic":"","min":0,"max":"100","step":1,"x":210,"y":280,"wires":[["3337ab02.51efe4"]]},{"id":"3f3f2d01.17e1a2","type":"mqtt out","z":"aa4bc419.8a1788","name":"","topic":"lack_lamp/time","qos":"0","retain":"false","broker":"1b428099.712eff","x":680,"y":120,"wires":[]},{"id":"5653f91e.a05548","type":"moment","z":"aa4bc419.8a1788","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/London","adjAmount":0,"adjType":"days","adjDir":"add","format":"HH:mm","locale":"de_DE","output":"","outputType":"msg","outTz":"Europe/London","x":440,"y":120,"wires":[["3f3f2d01.17e1a2"]]},{"id":"2c8d835f.7c011c","type":"mqtt out","z":"aa4bc419.8a1788","name":"","topic":"lack_lamp/top","qos":"0","retain":"true","broker":"1b428099.712eff","x":480,"y":220,"wires":[]},{"id":"3337ab02.51efe4","type":"mqtt out","z":"aa4bc419.8a1788","name":"","topic":"lack_lamp/bottom","qos":"0","retain":"true","broker":"1b428099.712eff","x":490,"y":280,"wires":[]},{"id":"95d92d08.7ad69","type":"ui_group","z":"","name":"Lack Lamp","tab":"921e5f7.58b2da","disp":true,"width":"6","collapse":false},{"id":"1b428099.712eff","type":"mqtt-broker","z":"","name":"piffi","broker":"piffi","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"921e5f7.58b2da","type":"ui_tab","z":"","name":"Lack Lamp","icon":"dashboard","disabled":false,"hidden":false}]

Now everything the ESP needs to do is get into my WiFi, subscribe to the three topics, and dump messages to the serial interface when something happens. These will need some sort of prefix to tell them apart, because time and the two brightness values usually won't be updated at the same time. When one of the brightness values changes, I want it to be updated immediately and not when the next time update occurs. On the other hand, time will probably be the variable that is updated most frequently.

Prefixes will be "t" for time, "T" for top brightness and "B" for bottom:

t 07:42
T 45
B 0

This will be easy to generate on the ESP and easy to parse on the Teensy.

The Teensy has to 

Having both servos via PPM and PWM brightness adjustments makes things slightly more complicated on the Teensy. Both PPM and PWM use a timer, so output pins must be chosen such that the timer outputs don't interfere with each other (see https://www.pjrc.com/teensy/td_pulse.html). So I have

While we're at it, I spotted a mistake in my schematic. Background: I want the teensy to also act as a serial bridge to program the ESP, so I need both serial directions between the two devices. However, I routed Teensy::RX1 <- ESP::TX and Teensy:GND->ESP::RX:

Easily fixed with magnet wire!

Discussions