nRF52832 with SK6812 LEDs

Hello,

I tried to run the example code for the ws2812 (which can be found at C:\ncs\v2.4.1\v2.4.1\zephyr\samples\drivers\led_ws2812) for the nRF52832 using nRF Connect SDK (v2.4.1).

Looking at the nrf52dk_nrf52832.overlay, it looks like MOSI would be used on P0.23.

&arduino_spi { /* MOSI on D11 / P0.23 */

I am trying to experiment using the nRF52 DK board. 
I have a known working LED ring which lights up from another board.

The code builds fine but when I run it, I see the following in the terminal.

Using a Saleae Logic analyzer, I don't see anything on P0.23. 

I tried adding the following from nrf52dk_nrf52832.dts but I ended up with the same message in the terminal and didn't see anything on the logic analyzer.

I tried multiple pins and couldn't see any changes on the IO lines that looked like the required signal for the WS2812 LEDs.

&spi2_default {
    group1 {
        psels = <NRF_PSEL(SPIM_SCK, 0, 25)>, <NRF_PSEL(SPIM_MISO, 0, 24)>,
        <NRF_PSEL(SPIM_MOSI, 0, 12)>;
    };
};

/*
 * Copyright (c) 2017 Linaro Limited
 * Copyright (c) 2018 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <errno.h>
#include <string.h>

#define LOG_LEVEL 4
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main);

#include <zephyr/kernel.h>
#include <zephyr/drivers/led_strip.h>
#include <zephyr/device.h>
#include <zephyr/drivers/spi.h>
#include <zephyr/sys/util.h>

#define STRIP_NODE		DT_ALIAS(led_strip)
#define STRIP_NUM_PIXELS	DT_PROP(DT_ALIAS(led_strip), chain_length)

#define DELAY_TIME K_MSEC(50)

#define RGB(_r, _g, _b) { .r = (_r), .g = (_g), .b = (_b) }

static const struct led_rgb colors[] = {
	RGB(0x0f, 0x00, 0x00), /* red */
	RGB(0x00, 0x0f, 0x00), /* green */
	RGB(0x00, 0x00, 0x0f), /* blue */
};

struct led_rgb pixels[STRIP_NUM_PIXELS];

static const struct device *const strip = DEVICE_DT_GET(STRIP_NODE);

int main(void)
{
	size_t cursor = 0, color = 0;
	int rc;

	if (device_is_ready(strip)) {
		LOG_INF("Found LED strip device %s", strip->name);
	} else {
		LOG_ERR("LED strip device %s is not ready", strip->name);
		return 0;
	}

	LOG_INF("Displaying pattern on strip");
	while (1) {
		memset(&pixels, 0x00, sizeof(pixels));
		memcpy(&pixels[cursor], &colors[color], sizeof(struct led_rgb));
		rc = led_strip_update_rgb(strip, pixels, STRIP_NUM_PIXELS);

		if (rc) {
			LOG_ERR("couldn't update strip: %d", rc);
		}

		cursor++;
		if (cursor >= STRIP_NUM_PIXELS) {
			cursor = 0;
			color++;
			if (color == ARRAY_SIZE(colors)) {
				color = 0;
			}
		}

		k_sleep(DELAY_TIME);
	}
	return 0;
}

0334.prj.conf

nrf52dk_nrf52832.dts

Has anyone had success with the WS2812 or SK6812 with the nRF52832 and nRF Connect SDK?

Thanks.

Parents
  • I don't have a WS2812 LED ring currently, will ask in office if anyone has one, But you might also want to check out older post here on the forum on the led example: https://devzone.nordicsemi.com/search?q=led_ws2812 

    You can also reach out in the Zephyr community https://zephyrproject.org/community/ .

    Can you also share the datasheet for the LED ring that you are using? 


    Regards,
    Jonathan

  • Was able to test with a led strip, seems to work with SPI. 



    Video showing that the leds change. Data out pin i connected to the logic analyzer just to see what i looked like. Only needed to connect Data in for it to work. 

    Also connected to the logic analyzer and I do see some action on the lines. 




    Regards,
    Jonathan

Reply
  • Was able to test with a led strip, seems to work with SPI. 



    Video showing that the leds change. Data out pin i connected to the logic analyzer just to see what i looked like. Only needed to connect Data in for it to work. 

    Also connected to the logic analyzer and I do see some action on the lines. 




    Regards,
    Jonathan

Children
  • Can you share your code somehow?

    What did you use for prj.conf?

    What pin are you using?

    Which SPI?

    I was hoping to use P0.08 for driving the LED ring as it works out well for my layout.  If you have suggestions with how do that, that would be helpful as well.

    Thanks.

  • I see now that I am using NCS v 2.4.2. 

    Here are the files:
    3568.led_ws2812.zip


    Here is just the hex file:1513.zephyr.hex

    No major changes only made sure to include the conf and overlay files



    Regards,
    Jonathan


  • Hello Jonathan,

    I am not what exactly I did but trying changing the prj.conf in the project I had resulted in the code no longer compiling.  It is unclear to what I did because when I perform a beyond Compare of the files, I don't see differences. 

    Here is what is in the output form the Terminal in visual studio code.  (I am was using NCS 2.4.1)

    [168/178] Linking C executable zephyr\zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map
    cmd.exe /C "cd . && C:\ncs\toolchains\c57af46cb7\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe  -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr\zephyr_pre0.elf  -fuse-ld=bfd  -T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=C:/ncs/v2.4.1/v2.4.1/zephyr/samples/drivers/led_ws2812/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a  zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a  zephyr/lib/libc/minimal/liblib__libc__minimal.a  zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a  zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/led_strip/libdrivers__led_strip.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/spi/libdrivers__spi.a  zephyr/drivers/timer/libdrivers__timer.a  modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  modules/segger/libmodules__segger.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -L"c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v7e-m/nofp"  -LC:/ncs/v2.4.1/v2.4.1/zephyr/samples/drivers/led_ws2812/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -Wl,-no-pie && cmd.exe /C "cd /D C:\ncs\v2.4.1\v2.4.1\zephyr\samples\drivers\led_ws2812\build\zephyr && C:\ncs\toolchains\c57af46cb7\opt\bin\cmake.exe -E echo ""
    c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr/drivers/led_strip/libdrivers__led_strip.a(ws2812_spi.c.obj):(.rodata.ws2812_spi_0_cfg+0x0): undefined reference to `__device_dts_ord_107'
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\c57af46cb7\opt\bin\cmake.EXE' --build 'c:\ncs\v2.4.1\v2.4.1\zephyr\samples\drivers\led_ws2812\build'

    I downloaded NCS V2.5.0-rc2.

    I found the WS2812 example, was able to compile it using the Build Configuration based on the screenshot you shared. 

    The example just worked.  I am thankful it worked but I am struggling to understand how to modify things in NCS/zephyr.  When something breaks, I am having issues figuring what is wrong.  If there is other zephyr training that you can recommend, I would love to get some.

    Thanks for your assistance.

  • jablackann said:
    I found the WS2812 example, was able to compile it using the Build Configuration based on the screenshot you shared. 

    Good to hear that you got it working.

    jablackann said:
    If there is other zephyr training that you can recommend, I would love to get some.

    We do have the DevAcadamy, but that might not be exactly what you are looking for:https://academy.nordicsemi.com 

    There is also our webinars that can be foundhere: https://webinars.nordicsemi.com/videos , contain different types of showcases and introductions. 

    Then you also have the Zephyr YouTube channel, it does contains some very informative videos, https://www.youtube.com/@ZephyrProject/videos 



    As for continue debugging issues, its nice if you create new tickets for new topics here on DevZone, keeps it easier to find the correct topics when searching. 
    Happy to help!

    Regards,
    Jonathan

Related