nRF52840 DK updating WS2812B led strip?

Hi,

I have tried the led strip example program and it works. My project will use 88 WS2812B RGB LEDs. For testing I used only 5 WS812B RGB LEDs. If I want to turn on red LED alternate, the code that works is this below.

	memset(&pixels, 0x00, sizeof(pixels));
	memcpy(&pixels[0], &colors[0], sizeof(struct led_rgb));
	rc = led_strip_update_rgb(strip, pixels, STRIP_NUM_PIXELS);
	memcpy(&pixels[1], &black, sizeof(struct led_rgb));
	rc = led_strip_update_rgb(strip, pixels, STRIP_NUM_PIXELS);
	memcpy(&pixels[2], &colors[0], sizeof(struct led_rgb));	
	rc = led_strip_update_rgb(strip, pixels, STRIP_NUM_PIXELS);
	memcpy(&pixels[3], &black, sizeof(struct led_rgb));	
	rc = led_strip_update_rgb(strip, pixels, STRIP_NUM_PIXELS);	
	memcpy(&pixels[4], &colors[0], sizeof(struct led_rgb));
	rc = led_strip_update_rgb(strip, pixels, STRIP_NUM_PIXELS);

My concern is if I do it this way for 88 WS2812B RGB LEDs, there might be some delay lighting up all the LEDs. Is there a better way?

Regards,

Markel

  • Hi,

    The led strip using I2S interface works for nRF52840 DK. I have already solved my problem.

    Markel

  • Hi mtrobregado, 

    From the led_ws2812 sample I'm trying to use the I2S interface with the nRF52840DK however I'm running into the following build error. Did you run into this error as well by any chance? 

    /Users/joonhojang/Local_Drive/Workspace/KEYBOARD/Firmware_Modules/nRF52840/led_ws2812/build/led_ws2812/zephyr/include/generated/zephyr/devicetree_generated.h:1337:42: error: 'DT_N_S_ws2812_P_chain_length' undeclared here (not in a function); did you mean 'DT_N_S_ws2812_P_compatible'?
     1337 | #define DT_N_ALIAS_led_strip             DT_N_S_ws2812

    This is my nrf52840dk_nrf52840.overlay file 

    #include <zephyr/dt-bindings/led/led.h>
    
    /* Wiring:
     * - M1.S connected to GND
     * - SDOUT connected to M1.D
     * - ~300 ohm resistor between M1.D and TP5 (5V / Vbus)
     */
    
    &pinctrl {
    	i2s0_default_alt: i2s0_default_alt {
    		group1 {
    			psels = <NRF_PSEL(I2S_SCK_M, 1, 15)>,
    			        <NRF_PSEL(I2S_LRCK_M, 1, 12)>,
    			        <NRF_PSEL(I2S_SDOUT, 1, 13)>,
    			        <NRF_PSEL(I2S_SDIN, 1, 14)>;
    		};
    	};
    };
    
    i2s_led: &i2s0 {
    	status = "okay";
    	pinctrl-0 = <&i2s0_default_alt>;
    	pinctrl-names = "default";
    };
    
    / {
    	led_strip: ws2812 {
    		compatible = "worldsemi,ws2812-i2s";
    
    		i2s-dev = <&i2s_led>;
    		chain-length = <10>; /* arbitrary; change at will */
    		color-mapping = <LED_COLOR_ID_GREEN
    		LED_COLOR_ID_RED
    		LED_COLOR_ID_BLUE>;
    		out-active-low;
    		reset-delay = <120>;
    	};
    
    	aliases {
    		led-strip = &led_strip;
    	};
    };

Related