NodeMCU MQTT LED Strip Controller Build & Config How-To Videos

Yep, I don’t change anything. I’m still using D4, in your sketch and the strandtest example. I will try an other pin, maybe this works.

EDIT:
I meassured the voltage between GND and the Data pin. It´s around 3,3V in both cases. The difference in my eye is only the used library to controll the strip. Adafruit_NeoPixel.h with 3.3V works but FastLED.h with 3.3V not. Even WS2812B are supported by both libraries.

Interesting! Might be the way Fastled sends their data/pwm (might be faster so overall voltage is lower than the ws2812b threshold). I’m pretty sure a level shifter will solve your problem (just make sure to get the 74hct245 since the i2c level shifters are too slow).

I’ll be updating the pcb board design soon to swap out the level shifters among other things/ideas I have in mind.

I´ve order these one: https://www.amazon.de/gp/product/B0148BLZGE
Now I´m afraid these are not the correct one, like you mentioned.

While researching I found this: https://github.com/FastLED/FastLED/wiki/Interrupt-problems

No those will not work unfortunately :frowning: they’re too slow.

Don’t worry about interrupt issues, the #define I have in the code resolves that particular issue

So, I finally get some 74HCT245N DIPs, but I couldnt find a tutorial how to wire it to the NodeMCU.
Do you can tell me ?

There’s a decent photo here, but for our specific case, we’ll need to connect it as follows (best bet is to do this on a breadboard):

DIR pin to GND pin (on the 74HCT245 chip)
OE pin to GND pin (on the 74HCT245 chip)
A0 pin to WS2812 signal input
B0 pin to D4 on NodeMCU
VCC pin to 5V (VIN) on NodeMCU
GND pin to Gnd on NodeMCU

Connect the 5V/Gnd lines from the WS2812 to your power supply’s 5V/Gnd, or to NodeMCU (as long as you’re only using a few LEDs). If using a power supply, make sure you have GND from the power supply connected to Gnd on the NodeMCU.

That should work…When I get a chance, I’ll update the schematic/board files for my breakout board to use the new level shifter, as well.

1 Like

Somehow it´s still not working. I wired it like you descripted, but only on LED light up, but it could not be controlled. I´m getting more and more frustrated.
Maybe I should start from scratch and also check if the components are okay.

I found another good tutorial here, which shows the pinout in a slightly better format. Can you make sure you have it wired this way? I would also add the resistor in line with the DIN on the LED strip.

Do you have access to an oscilloscope? You could see if the signal coming out of D4 on the NodeMCU is changing, and if the signal on A0 of the level shifter is also changing. If you’re only seeing the first LED light up, that tells me you’ve got a constant high output, so something may be connected wrong or like you said, you might have a bad component.

Keep in mind, the first LED lights up and stays on until the NodeMCU connects to Wifi/MQTT broker. It should turn off after a short while. But, it it stays on (and you’re getting MQTT data from the LED strip in Mqtt.fx) then it is a hardware problem.

1 Like

Again, I did a lot of testing to figure out whats wrong. I set up the circuit as shown at the pictures. I even connect my 100W power supply to exclude this as a error source.
With the strandtest example of Adafruit Neopixel library this works fine as before, so the 74HCT245N just works as it should, no problems here. I also tried PIN 2 instead D4 and still everything was fine.

But if I upload your/Bruh´s sketch just nothing happens, but the first LED lights up white.
So after this exclusion method, in my eyes, the faulty part must be the code. Or maybe the NodeMCU or some settings?
I do not know how to continue…

OK, how should I start…
FFS! I get this working! But no one will guess how…
I just played around with the board-setting and tried NodeMCU 0.9 but with this nothing works. Then I remembered that the Wemos (now Lolin) Mini is similiar to the NodeMCU, so why not give it a try? And you now what? This totally works fine, no guess how, but it works!
So now it can solder a small PCB and wire everything up. Im happy as possible, this botherd me so much… :rofl:

@bartus Thanks for your help and patience with me! But I have one question left. How could I use the “group-feature” like you´re using it in your kitchen? Where do I define which strips are into the same group?

That is excellent news to hear!! I was definitely running out of ideas, and the white LED confused me, because it’s typically what turns on at first (while the board is connecting to Wifi/MQTT), though it should have gone out since your board was connecting (and sending MQTT data). I wonder, do you have the latest FastLED and Board libraries installed in your Arduino IDE? It’s just weird that selecting a different board would make yours work (from the picture, it seems like it could either be a v1 or a v3 NodeMCU). In any case, I’m glad you got it working, I hate these things when they give me problems, but seeing those pretty LEDs light up just makes it all better :slight_smile:

As for groups, in my code, you should see two MQTT topic description fields within the Arduino code. The first is for the individual strip, the second is for the group. So, all you have to do is set all your strips to look at the same “group” set topic. Each NodeMCU will send status to its individual topic, and it will still listen to the individual set topic, as well, in case you want to control each strip separately, but when you send an MQTT message to the group topic, all strips will change at once. This worked great for my holiday lights, where I had an LED strip installed in every window, and they all changed in sync as each new effect command was sent from openHAB.

Enjoy!

BTW, now that you have it working and it seemed to be a config/software issue, do you mind running a small experiment and running the signal line directly off D4? I’m just really curious if the level shifter is actually needed, or whether it was always just a software thing…

Like I found out in the Adafruit strandtest, it also works without level shifter with this sketch and fastled.
I only put a resistor of 390 Ohm between the signal and the strip. Between 300 - 500 Ohm are recommended.

1 Like

Hi just playing with your code and wanted to try out the strip before implementing into OpenHab.

Using my MQTT broker I was sending the following:

Message arrived [Kichen/UNLight/set] "state":"ON":default
parseObject() failed

Could you advise on the correct syntax I’m struggling picking out of the Json code

Thanks

Try sending any of the strings from the .map file in post #1:

{"effect":"bpm"}
{"effect":"noise"}
{"effect":"fire"}
{"effect":"rainbow"}
{"effect":"twinkle"}
{"effect":"glitter"}
{"effect":"solid"}
{"effect":"sinelon"}
{"effect":"juggle"}
{"effect":"confetti"}
{"effect":"dots"}
{"effect":"lightning"}
{"effect":"candy cane"}
{"effect":"cyclon rainbow"}
{"effect":"ripple"}
{"effect":"christmas alternate"}
{"effect":"police all"}
{"effect":"police one"}
{"effect":"random stars"}
{"effect":"sine hue"}
{"state":"ON"}
{"state":"OFF"}

Basically, you need an opening/closing {}, and a key/value pair for each option you want to change (e.g. “state”:“ON”)…if you want to send multiple commands, you can separate them with a comma, i.e. {“state”:“ON”,“brightness”:“255”}. Color commands need the three R/G/B values, i.e. {“color”: {“r”:“128”, “g”:“64”, “b”: “0”}}

HI , thanks for the last pointer I have been able to get the NodeMCU programmed on the network, connected to my MQTT server. Followed your last guidance and send command to control everything from MQTTfx.

I’ve now hit another sticking point for me. I followed your first post and videos and created the following all the relevant parts. I have included these below if someone can spot what i ahve done wrong?!

The issue is with the rule file I believe but not sure how to fix. My VS Studio is saying there are errors as the following image:

I thought this was because the items weren’t created but they are in my/your ledstrip.items file.

The result is a failed Json creation and the following being sent by my Mqtt server:

Any suggestions would be gratefully received.

Code used below:

ledstrip.items:

String LEDStrip_FF_Kitchen_Cabinet_1 "Kitchen Cabinet 1 String" {mqtt=">[broker:home/FF_Kitchen_Cabinet_1/set:state:*:default]"}
Switch LEDStrip_FF_Kitchen_Cabinet_1_Power "Kitchen Cabinet 1 Power"  [ "Switchable" ] {mqtt=">[broker:home/FF_Kitchen_Cabinet_1/set:command:*:MAP(LEDStripEffectJSON.map)]"}
Number LEDStrip_FF_Kitchen_Cabinet_1_FX "Kitchen Cabinet 1 Fx" {mqtt=">[broker:home/FF_Kitchen_Cabinet_1/set:command:*:MAP(LEDStripEffectJSON.map)]"}
Color LEDStrip_FF_Kitchen_Cabinet_1_Color "Kitchen Cabinet 1 Color"	<rgb> [ "Switchable" ]	
Number LEDStrip_FF_Kitchen_Cabinet_1_Speed "Kitchen Cabinet 1 Speed [%.0f]"		
Number LEDStrip_FF_Kitchen_Cabinet_1_Intensity "Kitchen Cabinet 1 Intensity [%d]"

ledstrip.sitemap:

sitemap sitemapnameforleds label="Led Strip Test" 
{
Switch item=LEDStrip_FF_Kitchen_Cabinet_1_Power
Selection item=LEDStrip_FF_Kitchen_Cabinet_1_FX mappings=[1="BPM",2="Noise",3="Fire",4="Rainbow",5="Twinkle",6="Glitter",7="Solid",8="Sinelon",9="Juggle",10="Confetti",11="Dots",12="Lightning",13="Candy Cane",14="Cyclon Rainbow",15="Ripple",16="Christmas Alternate",17="Police All",18="Police One",19="Random Stars",20="Sine Hue"] 
Colorpicker item=LEDStrip_FF_Kitchen_Cabinet_1_Color
Setpoint item=LEDStrip_FF_Kitchen_Cabinet_1_Speed minValue=5 maxValue=240 step=5
Setpoint item=LEDStrip_FF_Kitchen_Cabinet_1_Intensity minValue=0 maxValue=255 step=16 

}

ledstrip.rules

    rule "LED Strip Kitchen Cabinet 1 JSON Color"
    when Item LEDStrip_FF_Kitchen_Cabinet_1_Color received update
    then LEDStrip_FF_Kitchen_Cabinet_1.sendCommand("{\"color\": {" + 
    		"\"r\": " + (LEDStrip_FF_Kitchen_Cabinet_1_Color.state as HSBType).red + "," +
    		"\"g\": " + (LEDStrip_FF_Kitchen_Cabinet_1_Color.state as HSBType).green + "," +
    		"\"b\": " + (LEDStrip_FF_Kitchen_Cabinet_1_Color.state as HSBType).blue + "}}") end
   

    rule "LED Strip Kitchen Cabinet 1 JSON Speed"
    when Item LEDStrip_FF_Kitchen_Cabinet_1_Speed received update
    then LEDStrip_FF_Kitchen_Cabinet_1.sendCommand("{\"transition\": \"" + LEDStrip_FF_Kitchen_Cabinet_1_Speed.state + "\"}") end

    rule "LED Strip Kitchen Cabinet 1 JSON Intensity"
    when Item LEDStrip_FF_Kitchen_Cabinet_1_Intensity received update
    then LEDStrip_FF_Kitchen_Cabinet_1.sendCommand("{\"brightness\":" + LEDStrip_FF_Kitchen_Cabinet_1_Intensity.state + "}") end

LEDStripEffectJSON.map:

1={"effect":"bpm"}
2={"effect":"noise"}
3={"effect":"fire"}
4={"effect":"rainbow"}
5={"effect":"twinkle"}
6={"effect":"glitter"}
7={"effect":"solid"}
8={"effect":"sinelon"}
9={"effect":"juggle"}
10={"effect":"confetti"}
11={"effect":"dots"}
12={"effect":"lightning"}
13={"effect":"candy cane"}
14={"effect":"cyclon rainbow"}
15={"effect":"ripple"}
16={"effect":"christmas alternate"}
17={"effect":"police all"}
18={"effect":"police one"}
19={"effect":"random stars"}
20={"effect":"sine hue"}
ON={"state":"ON"}
OFF={"state":"OFF"}

Shool boy error I had not installed the transform plugin to so the transform now works.

Still have an issue with my rules a file in VS Studio…

1 Like

Does your sitemap load properly? Because it seems like the items aren’t being created properly (or perhaps you still hadn’t saved the .items file while writing the rules file?)

I would see if the rules are actually executing, first (i.e. Color rule being fired when you update the LEDStrip_FF_Kitchen_Cabinet_1_Color item). Write the following statement into your rule:

logInfo("Test", "Color rule executed")

and see if it gets written into your log when you change the color. That will validate your items and sitemap, at least. But, if you already have frontail installed, you should already be seeing these entries in there when you update any of the LEDStrip items - something like the following:

2018-07-01 22:21:05.133 [ome.event.ItemCommandEvent] - Item 'LEDStrip_Kitchen_Cabinet_Color' received command 106,12,0

2018-07-01 22:21:05.154 [vent.ItemStateChangedEvent] - LEDStrip_Kitchen_Cabinet_Color changed from 0,0,0 to 106,12,0

2018-07-01 22:21:05.212 [ome.event.ItemCommandEvent] - Item 'LEDStrip_Kitchen_Cabinet' received command {"color": {"r": 0.000000000000,"g": 0,"b": 0.00}}

2018-07-01 22:21:05.227 [vent.ItemStateChangedEvent] - LEDStrip_Kitchen_Cabinet changed from {"color": {"r": 0,"g": 0.0000000000,"b": 0}} to {"color": {"r": 0.000000000000,"g": 0,"b": 0.00}}

I believe you were correct that the site maps had not loaded correctly. I have installed frontail and debugged loads of my OH system. It’s definitely a great tool!

Following my debugging and you assistance I am up and running with my system but the colour picker is not working. Frontail is giving the following:

2018-07-26 20:20:35.159 [ome.event.ItemCommandEvent] - Item 'LEDStrip_FF_Kitchen_Cabinet_1_Color' received command 11,51,96
==> /var/log/openhab2/openhab.log <==
2018-07-26 20:20:35.190 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert '{"color": {"r": 96,"g": 56.015999998368,"b": 47.04}}' to a command type which item 'LEDStrip_FF_Kitchen_Cabinet_1_Color' accepts: [HSBType, PercentType, OnOffType, IncreaseDecreaseType, RefreshType].

As you can see it’s not able to send the command to the unit. Are you able to shed any ideas onto this one. I have checked my spellings and as you can see I can change effects:

2018-07-26 20:25:44.232 [ome.event.ItemCommandEvent] - Item 'LEDStrip_FF_Kitchen_Cabinet_1_FX' received command 3
2018-07-26 20:25:44.247 [vent.ItemStateChangedEvent] - LEDStrip_FF_Kitchen_Cabinet_1_FX changed from 5 to 3

Change intensity:

2018-07-26 20:26:50.585 [ome.event.ItemCommandEvent] - Item 'LEDStrip_FF_Kitchen_Cabinet_1' received command {"brightness":144}
2018-07-26 20:26:50.594 [vent.ItemStateChangedEvent] - LEDStrip_FF_Kitchen_Cabinet_1 changed from {"brightness":160} to {"brightness":144}

Again any help is very much apricated.

I think I see the problem - it looks like you’re sending the “{color…}” JSON string back to the _Color item (the item that you’re using in your sitemap to select the color…Instead, you should be sending that string to the STRING item (LEDStrip_FF_Kitchen_Cabinet_1). I bet you just mistyped something in your rules file. Compare the Color changing rule to the Speed or Intensity rule (which seems to work fine). Or, just post the color rule here, so I can take a look at it.