Control RGB Color or rutine via impulses



  • Hello Guys,

    first of i got a Idea how i could control my RGB Led's via a Fan pin but i don't know how far others are with a maybe better Solution so i explain it.

    End of 2018 i got a arduino Nano with a few Led's and other stuff and i asked my self how i can control my RGB Led's.
    It should be possible to send fast impulses to a input pin of a controller that is programmed to handle those and turn the Led's on to Red or led them blink or what ever i want right?

    So i can create a Sequenz what those should do while printing or heating up the Hotend and Heatbed etc.
    I didn't tryed it yet but if the Firmware dosen't send a Error or something else while i turn on and off my Fan like crazy i will test it.

    Or is there a simpler way?


  • administrators

    I have come across 3 types of RGB LED strips:

    1. Strips with separate 12V or 24V inputs for the red, green and blue LEDs. You would need to use 3 fan and/or heater outputs to control them. one for each colour.

    2. 5V LED strips with a single input and individually addressable LEDs, using WS2812B or SK6812 LEDs and associated serial protocol (Adafruit Neopixel and similar). These have very specific timing requirements and are not suitable for driving from a Duet (or any other system that has other real-time tasks to manage concurrently). You could use an Arduino Nano or similar to drive them and send it commands from the Duet (remember to level shift the control signal from 3.3V to 5V).

    3. 5V DotStar addressable LED strips. These use SPI protocol, which makes them much more suitable for the Duet. There is code to drive DotStar LEDs in the RepRapFirmware source, but currently it is not enabled for the standard Duet builds. You would need a buffer to level shift the SPI clock and data signals to 5V.

    5V LED strips draw a lot of current, so you would generally need an external 5V power supply for them.



  • Thx, the DotStar look realy nice so i think i will wait until the Support from you're side is there. ☺



  • David, it is possible to drive a WS2812 RGB led from SPI... Here is some Python code I used to drive a WS2812 strip from a Micropython board:

    import math
    import gc
    
    from pyb import SPI
    
    
    def tsv2rgb(hue, saturation, value):
        """
        See http://fr.wikipedia.org/wiki/Teinte_Saturation_Valeur#Conversion_de_TSV_vers_RVB
        """
        S = saturation / 100.
        V = value / 100.
    
        Ti = int((hue / 60)) % 6
        f = hue / 60. - Ti
        L = V * (1 - S)
        m = V  * (1 - f * S)
        n = V * (1 - (1 -f) * S)
    
        if Ti == 0:
                red = V
                green = n
                blue = L
        elif Ti == 1:
                red = m
                green = V
                blue = L
        elif Ti == 2:
                red = L
                green = V
                blue = n
        elif Ti == 3:
                red = L
                green = m
                blue = V
        elif Ti == 4:
                red = n
                green = L
                blue = V
        elif Ti == 5:
                red = V
                green = L
                blue = m
        else:
            red = green = blue = 0
    
        # Scale to 8 bits
        red *= 256
        green *= 256
        blue *= 256
    
        return int(red), int(green), int(blue)
    
    
    def byte2bits(byte):
        b0 = chr(0x03)
        b1 = chr(0x0F)
        bits = ''
        mask = 0x80
        while mask != 0:
            bits += b0 if (byte & mask) == 0 else b1
            mask >>= 1
        return bits
    
    def main():
        spi = SPI(1, SPI.MASTER, baudrate=6400000, polarity=0, phase=1)
        spi.send(chr(0x00))
    
        buf = bytearray(10 * 3)
        n = 0
        while True:
            pos = 0
            while pos < len(buf):
                buf[pos], buf[pos+1], buf[pos+2] = tsv2rgb(0, 100, 100)
                pos += 3
            data = ''.join(list(map(byte2bits, buf)))
            spi.send(data)
            gc.collect()
            n += 1
    
    if __name__ == "__main__":
        main()
    

  • administrators

    I looked into this early last year and came to the conclusion that although it would work, it wouldn't be possible to get the timing perfectly consistent, because even if you use DMA to drive the SPI, other concurrent activity such as DMA to the network interface would be liable to mess it up. That's why I decided to support DotStar instead. The DotStar driver is already working and one of our OEM customers is using it.



  • Well, I agree if you want to have a continuous stream of data, to make fast animations, but it works fine without the need of a DMA to control a few leds...


Log in to reply