Controlling WS2812 LEDs with NCS on nRF52832DK with gpios (not SPI)

I have downloaded the WS2812 driver example and have successfully been using the nRF52832 DK to control these lights with SPI. I am ready to start developing on a custom board (still nRF52832). The only issue is that the LEDs are not connected to an SPI MOSI pin.

In the driver documentation, it looks like it is possible to control the LEDs with a normal GPIO pin. However, I am not quite sure what I should do to the board .overlay file or .config file to switch from SPI to GPIO configuration. For now I am just trying to get this to work on the DK, I haven't made the DTS file for my board yet.

All I have tried is using the driver example and replacing the .overlay file contents with this...

 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/led/led.h>
//  #include "../nrf52-bindings.h"
 
 / {
	 led_strip: ws2812 {
		 compatible = "worldsemi,ws2812-gpio";
		 label = "WS2812";
 
		 chain-length = <16>; /* arbitrary */
		 color-mapping = <LED_COLOR_ID_GREEN
					 LED_COLOR_ID_RED
					 LED_COLOR_ID_BLUE>;
		 /*
			 * Arduino D11 / P0.25, which was chosen to match the pin
			 * used in nrf52dk_nrf52832.overlay.
			 */
		 in-gpios = <&gpio0 25 0>;
	 };
 
	 aliases {
		 led-strip = &led_strip;
	 };
 };
 

I found this in the overlay file for a board that uses GPIO. After also removing the references to SPI in the board .conf and prj.conf file I get this error...

undefined reference to `__device_dts_ord_11'

Is it possible to control the LEDs with normal GPIO pins with nRF52832 boards? If so what am I doing wrong? Thanks...

Parents Reply Children
  • No. Actually I was wondering if I am able to control the LEDs with a pin that is not a SPI MOSI pin. As you pointed out in the overlay file, one of these MOSI pins is P0.23. Looking at the nRF52DK_832 .dts file below, it looks like P0.26 and P0.30 are also MOSI pins. Is there any way to control WS2812 LED without these any of these MOSI pins on the nRF52832 DK? Specifically maybe pin P0.28? Thanks.

    &spi0 {
    	compatible = "nordic,nrf-spi";
    	/* Cannot be used together with i2c0. */
    	/* status = "okay"; */
    	sck-pin = <27>;
    	mosi-pin = <26>;
    	miso-pin = <28>;
    };
    
    &spi1 {
    	compatible = "nordic,nrf-spi";
    	status = "okay";
    	sck-pin = <31>;
    	mosi-pin = <30>;
    	miso-pin = <29>;
    };
    
    arduino_spi: &spi2 {
    	compatible = "nordic,nrf-spi";
    	status = "okay";
    	sck-pin = <25>;
    	mosi-pin = <23>;
    	miso-pin = <24>;
    	cs-gpios = <&arduino_header 16 GPIO_ACTIVE_LOW>; /* D10 */
    };

  • Hello,

    That option is only supported on nRF51 https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/led_strip/Kconfig.ws2812#L29. ''The GPIO driver does bit-banging with inline assembly and is not available on all SoC''

    You are using arduino_spi_arduino_spi: &spi2, so just need to configure the SPI pin you want to use in the overlay.

    For example.

    &arduino_spi {
    compatible = "nordic,nrf-spim";
    status = "okay";
    sck-pin = <25>;
    mosi-pin = <28>;
    miso-pin = <24>;
    cs-gpios = <&arduino_header 16 GPIO_ACTIVE_LOW>; /* D10 */
    led_strip: ws2812@0 {
    compatible = "worldsemi,ws2812-spi";
    label = "WS2812";

    /* SPI */
    reg = <0>; /* ignored, but necessary for SPI bindings */
    spi-max-frequency = <SPI_FREQ>;

    /* WS2812 */
    chain-length = <16>; /* arbitrary; change at will */
    spi-one-frame = <ONE_FRAME>;
    spi-zero-frame = <ZERO_FRAME>;
    };
    };

    The SPI instances (for example SP1, SPI0) you dnt need to use can select them as disable. 

    Thanks.

    Best Regards,

    Kazi Afroza Sultana

Related