How can I control addressable RGB LEDS?
-
Given the ease of programming the WS2812b type RGB LEDs in the arduino environment, here's what I've done:
- set an output PIN for use with M42
- Connect this output pin to an analog input pin of the arduino. In my case I use an ESP32 which can bé easily purchased.
- Monitor the input of the arduino to see what values it gives according to the values set on the M42. Depending on whether it is 8 or 32 bits the sampling may be different
- Decide what values I use and why (Warm up, start, print, ....)
- Program the Arduino with the FastLED library that will assign a color / effect according to the value of the input PIN
- Write a macro in the DUET for each output value of the PIN that connects to the Arduino
- Call the Macro in order to provoke the output by the DUET PIN which will be sampled by the Arduino and execute the code to put the LEDS in the color chosen in previous steps.
I have it that way and set different scenarios for Standby, warming, cooling, calibrating, printing and off. I call macros from confit.g at printer startup or from G-code generated by Slic3r. Alternatively I can enable them from the PanelDue.
Hope it helps as Google Translator helps me
-
1RI, thank you so much for the information, I figured there was a way that even I could understand, this really helps a lot and I even have a few ESP32's laying around besides Nano's, Unos and even a few Mega Arduino's.
-
@wkellyo
glad that it served you. -
@1ri , would you be willing to share code you have created? While I understand the concepts you've outlined, any specific code for an arduino, macros, etc. would sure help me out as I could see the examples. Maybe you could zip what you have into a single zip file and attach to this post or message me and I'll give you my email address. I'm not much of a programmer but by using examples, I can usually figure stuff out. Thanks so much in advance and if you chose not to, there's no harm in asking.
Kelly -
for sure,
I attach a file with the .ino I use and a folder with the macros that send the value to pin P100 (GPIO1 on DUEX5) or duex.gp1 for RRF3.
Once the arduino is programmed, it prints the value it receives from the Duet via the serial port by sending the M42 commands to it.
This makes it easier to adjust the values that need to be compared with the Arduino to display each color using the serial monitor.As you can see, the comments inside the macros and the .ino file are in Catalan, as it is my native language, but Google Translator is quite efficient in Catalan.
best regards
I put the link in my drive because I couldn't upload a zip file. If anyone can guide me in how to do it, I would be very grateful
Solved!! Just read this post to see that ZIP files are not supported....
-
@1ri, Bless you! I took a look at the files and other than the task of translating (as you said Google should work very well) I am confident I can make it all work. I have a Duet2 and a Duex5 in my printer so I have lots of available outputs. My goal at first is to simply be able to turn the lights on and off and change the colors via DWC using macros which should be easy enough since you have provided the macros I can modify. I also will have to modify the Arduino code somewhat, probably make it even simpler. Later I may try making them animate when the printer is being used. Thank you so much again!
Kelly
-
With this in mind, in a configuration like ours with Duet2 + DUEX, only PINs 100-103 are available on the GPIO & I2C connector in the DUEX5, which are not so many.
In RRF3, which will be effective from now on, I use this command to set the PIN in order to be able to use it later with the M42 of the macros.
M950 P0 C "duex.gp1", which may be the value of gp1 to gp3 depending on the GPIO to be used
-
I messed around with all this today and actually have it working. The Arduino file was a definite challenge as the translation wasn't perfect and I had several errors that had to be fixed. But, it works and now I can tweak it all out to my liking and install the LED strips into the bed light diffusers. Thanks again!
Kelly
-
I'm glad you got it working. FWIW, Duet 3 supports DotStar LED strips natively.
-
for reference adafruit DotStar LEDs are APA102(or SK98225) LEDs so any APA102 4 wire LEDS will work
-
-
Hi, 1ri wrote the original code and shared with me. I added another color to the existing code, please see this this post and it should explain everything you need. If you need the files, let me know with a private IM and I'll get them to you.
https://forum.duet3d.com/topic/14411/gpio-pins-on-duex5-useage/10
-
Can you state the real goal here? There is likely a better way.
For example, how about an ESP8266 or ESP32 that monitors the printer and does what you want with the lights according to printer state. NOTHING in the G-Code...
Anyway, what's the goal?
-
@Danal I guess the main goal was to have bed lighting color that I could change using DWC. Then the idea of interfacing it to the printer to change color depending on the printer status came to mind. I am fairly new to Arduino, Raspberry Pi, etc. and when it comes to coding, if I can't find an example to go by, modify, etc. I end up reaching out to others. I struggle to write from scratch and then only basic, simple stuff but I'm slowly learning. If I had a Duet3 board I'd look into the Dotstars instead. You mention these two Wireless type boards and I've seen them before but wasn't sure of being able to make them work for this or how to interface to the Duet. You also mention monitoring the printer status but I wouldn't really know where to begin. I'm always up for a challenge and if you know of better ways to do this please share with me. BTW you have a nice, well written web site, I spent the better part of an hour there a week or so ago!
-
@wkellyo Awesome thanks i will look at this closly today and maybe i will have more
question -
I have an LED RGB strip connected directly to fan outputs on the duex5.
The colours are controlled by macros depending on the state of the machine.
Red for startup, bed levelling etc
Green for printer ready but idle
Blue for printing.
Of course other colours could be used for other states.I also have Red, Green and Blue sliders that can be adjusted in real time if I want to display them.
I'm just waiting now for the object model to include variables so I can change the LED from 1 colour to another gradually.
Hope that helps
-
Thanks folks! That helps.
Dotstar on Duet3, with various macros that Duet/RepRap firmware auto-invokes, like start.g, pause.g, etc. that will be one of the "cleanest" ways to have events on a Duet change lighting, with everything direct attached to the Duet itself.
Having said that, it will also be VERY easy to produce a device that polls a printer for status, and has menu choices that tie printing, heating, idle, etc, etc. to colors or other states on one or more NeoPixel or Dotstar strips.
This opens the door to the lights being on the printer, or being in another room. As long as the printer is network reachable.
Would there be interest in this? As a free download that runs on off-the-shelf hardware costing $20 to $40 USD? I want to orient it toward a couple of hardware options that are not going to require soldering (or very little). Not just a collection of boards...
-
@appjaws Nice even better can you share how you connected them to duex5 and the code please ?
What kind of RGB did you use i have WS2818? -
@appjaws what pin's did you use gpio or which one's
-
@matej1006 I connected the RGB wires to the fan outputs negative pins for fan 3,4 and 5 and the common wire to the positive .
the LED settings were then added to config.g:-; LED Lighting
M950 F3 C"duex.fan3" Q500 ; create fan 3 on pin duex.fan3 and set its frequency for LED Red
M106 P3 C"RGB Red" ; set RGB Red to P3
M950 F4 C"duex.fan4" Q500 ; create fan 4 on pin duex.fan4 and set its frequency for LED Green
M106 P4 C"RGB Green" ; set RGB Green to P4
M950 F5 C"duex.fan5" Q500 ; create fan 5 on pin duex.fan5 and set its frequency for LED Blue
M106 P5 C"RGB Blue" ; set RGB Blue to P5I just bought a strip from amazon, my system is 24V so I bought a 5 meter reel of DC24V LED Ribbon.
Hope this helps