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.

  • I meant to add the capture from when I had inverted the colors and then set the chain length back to 12.

    8712.SK6812 with LED Ring chain length of 12, color inverted from original code.sal

  • 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

  • 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


Related