Turn on neopixel with pause
-
Hello,
is it possible to display a running light with neopixels?Regards
Lars -
@gringo
Can you explain in more detail what you want to do?
If you mean can you set a neopixel according to the state of the printer then yes you can by using daemon.g and monitoring state.status in the object model
For exampleif state.status = "paused" M150 X2 R255 U0 B0 P255 S1 F1 elif state.status = "processing" M150 X2 R0 U0 B0 P255 S1 F1 elif state.status = "idle" M150 X2 R255 U255 B255 P255 S1 F1 else M150 X2 R0 U0 B0 P0 S1 F1
-
Thanks Owen,
I have 58 neopixels under my printer and I would like to switch them on one after the other.
So first neopixel 1, short pause, switch on neopixel 2, short pause, switch on neopixel 3 and so on.
At the end all 58 neopixels are on.
If this is the case, Neopixel 1 should be switched off after a short pause, then switch off Neopixel 2, short pause, then switch off Neopixel 3 and so on. Until all neopixels are off.
Then start all over again as long as the print is running. -
Can I do something like that ?
Knight Rider -
I have another question about the while loop.
How do I have to write the while loop in daemon.g to make the pass every 2 seconds?
I have read the documentation but do not understand it. -
@gringo
OK, I think I understand what you want.
I don't have a neopixel, so this is untested.
Try this in daemon.g
I have attached the file to ensure you get the indenting correct as copy/paste sometimes screws it upYou can change any of the settings for colours by sending for example
set global.rLED = 127
from the command line
same for the delayBecause it's in an endless loop, you need a way to abort the daemon in case you need to modify it or just stop it.
Do this by sendingset global.runDaemon = false
; 0:/sys/daemon.g if !exists(global.runDaemon) global runDaemon = true if global.runDaemon = false ; send "set global.runDaemn = false" to stop daemon if needed M99 ; exit daemon. if !exists(global.ledDelay) global ledDelay = 2 ; modify to change delay. if !exists(global.rLED) global rLED = 255 ; set red value 0 to 255 if !exists(global.gLED) global gLED = 0 ; set green value 0 to 255 if !exists(global.bLED) global bLED = 0 ; set blue value 0 to 255 if !exists(global.wLED) global wLED = 0 ; set red value 0 to 255 if !exists(global.ledBrightness) global ledBrightness = 255 ; set brightness value 0 to 255 if !exists(global.ledState) global.ledState = 0 ; this will be toggled between 0 and 1 on each loop M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels before we start while true ; create an endless loop if global.runDaemon = false M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels M99 ; exit daemon. if state.status ="processing" ; check if we are printing ; toggle the LED state at each loop if global.ledState = 0 set global.ledState = 1 else set global.ledState = 0 ; loop through all the LED's while iterations < 57 ; set to one less than number of LED's in neopixel M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledState = 1 ? global.ledBrightness : 0} S1 F1 ; set next LED in loop to either brightness or off G4 S{global.ledDelay} M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledState = 1 ? global.ledBrightness : 0} S1 F0 ; set last LED in loop G4 S{global.ledDelay} else M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels if we have stopped printing G4 S{global.ledDelay} if state.status !="processing" G4 S1 ; if we aren't printing add a delay to give control back to processor
-
Thanks Owen, I will test it next days.
I like the script of your daemon.g you postet first.
Can you show me on this code how to program the while loop to run daemon.g every 2-3 seconds.Thanks for your help.
-
@gringo
The second code I posted does that.
Create a "while true" endless loop and put a G4 S2 in it -
I get this error
Error: Bad command: global.ledState = 0
Warning: both space and tab characters used to indent blocks at/before line 41
Error: in file macro line 46 column 28: meta command: unknown variable 'ledState'line 46 --> if global.ledState = 0
-
@gringo said in Turn on neopixel with pause:
I get this error
Error: Bad command: global.ledState = 0Remove the '.' between "global" and "ledState" at line 23.
Error: in file macro line 46 column 28: meta command: unknown variable 'ledState'
line 46 --> if global.ledState = 0
That's a result of the previous error.
Warning: both space and tab characters used to indent blocks at/before line 41
As it says.
-
@gringo said in Turn on neopixel with pause:
I get this error
Well I did say it was untested
Error: Bad command: global.ledState = 0
change this
if !exists(global.ledState) global.ledState = 0
to this
if !exists(global.ledState) global ledState = 0
Warning: both space and tab characters used to indent blocks at/before line 41
I don't see any spaces mixed with tabs on my code.
If you copied and pasted or modified the code you may have introduced some.If you use an editor like notepad++ or RJ TextEd, you can set it to display spaces and tabs.
Notepad ++
RJ TextEd
-
Thanks a lot, I will test it today and letting you know what happens
-
I´m testing it but all neopixel are shining red . After a while all neopixel turned off.
Can we create a Macro for testing? -
@gringo
As I said, I don't have a neopixel.
It's possible I have made an error with the M150 calls.
I have modified the code to add some echo commands and fix an error.
Tt seems to do the loops correctly.
Please try this and if the echos are correct but the LED control is wrong then you need to focus on the M150 commands to get the on/off correct; 0:/sys/daemon.g if !exists(global.runLED) global runLED = true if global.runLED = false ; send "set global.runLED = false" to stop daemon if needed M99 ; exit daemon. if !exists(global.ledSize) global ledSize = 58 ; modify to number of LED's in neopixel. if !exists(global.ledDelay) global ledDelay = 2 ; modify to change delay. if !exists(global.rLED) global rLED = 255 ; set red value 0 to 255 if !exists(global.gLED) global gLED = 0 ; set green value 0 to 255 if !exists(global.bLED) global bLED = 0 ; set blue value 0 to 255 if !exists(global.wLED) global wLED = 0 ; set red value 0 to 255 if !exists(global.ledBrightness) global ledBrightness = 255 ; set brightness value 0 to 255 if !exists(global.ledState) global ledState = 1 ; this will be toggled between 0 and 1 on each loop M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels before we start while true ; create an endless loop if global.runLED = false M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels echo "exiting macro" break ; exit loop. if state.status ="processing" ; check if we are printing ;toggle the LED state at each loop if global.ledState = 0 set global.ledState = 1 else set global.ledState = 0 ;loop through all the LED's while iterations < global.ledSize - 1 ; set to 1 less than number of LED's in neopixel if global.runLED = false M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels echo "exiting loop" break if global.ledState = 0 echo "next LED on " , iterations else echo "Next LED off" , iterations M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledState = 1 ? global.ledBrightness : 0} S1 F1 ; set next LED in loop to either brightness or off G4 S{global.ledDelay} M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledState = 1 ? global.ledBrightness : 0} S1 F0 ; set last LED in loop echo "last LED" G4 S{global.ledDelay} else M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels if we have stopped printing G4 S{global.ledDelay} G4 S{global.ledDelay} if global.runLED = false M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels echo "exiting daemon" M99 ; exit daemon. if state.status !="processing" G4 S1 ; if we aren't printing add a delay to give control back to processor
File
daemon.g -
@gringo
To updatedaemon.g
you must first rename it to saydaemon.g.old
Then upload your new version.
It wouldn't hurt to restart after that. -
@gringo
I may have not understood how M150 works correctly.
I was assuming that each command was applied immediatly and the F parameter only represented where the sequence started.
However this piece of information from the documentation suggests that is incorrect and the only F0 commands are applied.
The specified RGB values will be sent to the number of LEDs in the LED strip as specified by the S parameter, pushing the existing colours along the strip. To set all the LEDs the same colour, make the S parameter equal to or a little longer than the number of LEDs in the stripBased on that, try this code instead
; 0:/sys/daemon.g if !exists(global.runLED) global runLED = true if global.runLED = false ; send "set global.runLED = false" to stop daemon if needed M99 ; exit daemon. if !exists(global.ledSize) global ledSize = 58 ; modify to number of LED's in neopixel. if !exists(global.ledDelay) global ledDelay = 2 ; modify to change delay. if !exists(global.rLED) global rLED = 255 ; set red value 0 to 255 if !exists(global.gLED) global gLED = 0 ; set green value 0 to 255 if !exists(global.bLED) global bLED = 0 ; set blue value 0 to 255 if !exists(global.wLED) global wLED = 0 ; set red value 0 to 255 if !exists(global.ledBrightness) global ledBrightness = 255 ; set brightness value 0 to 255 if !exists(global.ledState) global ledState = 1 ; this will be toggled between 0 and 1 on each loop M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels before we start while true ; create an endless loop if global.runLED = false M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels echo "exiting macro" break ; exit loop. if state.status ="processing" ; check if we are printing ;toggle the LED state at each loop if global.ledState = 0 set global.ledState = 1 else set global.ledState = 0 ;loop through all the LED's while iterations < global.ledSize - 1 ; set to 1 less than number of LED's in neopixel if global.runLED = false M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels echo "exiting loop" break if global.ledState = 0 echo "next LED on " , iterations M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledBrightness} S1 F0 else echo "Next LED off" , iterations M150 R0 U0 B0 W0 P0 S1 F0 ; set next LED in loop to either brightness or off G4 S{global.ledDelay} else M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels if we have stopped printing G4 S{global.ledDelay} G4 S{global.ledDelay} if global.runLED = false M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels echo "exiting daemon" M99 ; exit daemon. if state.status !="processing" G4 S1 ; if we aren't printing add a delay to give control back to processor
-
Only the first Neopixel turns on. The display shows me counts of cylces and the count of enabled Neopixel.
In the first pass of all 58 neopixels, only the first one lights up. it is counted up to 56, then the first neopixel goes out again and stays out. It counts up to 56 again and then it starts all over again -
@gringo
Ok
I'm clearly not up with M150 so hopefully someone else can helpAll I can suggest is changing this
;loop through all the LED's while iterations < global.ledSize - 1 ; set to 1 less than number of LED's in neopixel if global.runLED = false M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels echo "exiting loop" break if global.ledState = 0 echo "next LED on " , iterations M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledBrightness} S1 F0 else echo "Next LED off" , iterations M150 R0 U0 B0 W0 P0 S1 F0 ; set next LED in loop to either brightness or off G4 S{global.ledDelay}
To this
;loop through all the LED's while iterations < global.ledSize if global.runLED = false M150 R0 U0 B0 P0 W0 S58 F0 ; turn off neopixels echo "exiting loop" break if global.ledState = 0 echo "next LED on " , iterations M150 R{global.rLED} U{global.gLED} B{global.bLED} W{global.wLED} P{global.ledBrightness} S{iterations+1} F0 else echo "Next LED off" , iterations M150 R0 U0 B0 W0 P0 S{iterations +1} F0 ; set next LED in loop to either brightness or off G4 S{global.ledDelay}