6 years, 2 months ago.

RedBear nRF51822 driving NeoPixels

Hi,

We are trying to use the nRF51822 from RedBear to drive an array of NeoPixels, but cannot get the LEDs to light up. We are using the following libraries without any success.

https://github.com/lavallc/nrf51-neopixel

https://github.com/cpldcpu/light_ws2812

We've also asked RedBear to look into the issue. https://redbearlab.zendesk.com/entries/73654999-BLE-Nano-with-Neopixel-WS2812-mbed?page=1#post_29874979

Any advice on this issue would be gratefully appreciated.

Thanks, Chris

Do they not compile? Do they not work? Did you check with a scope or logic analyzer what comes out?

posted by Erik - 27 Jun 2015

Hi. The code compiles, but doesn't turn on the LEDs. I haven't check the scope or logic analyzer yet. I'm talking with with RedBear to see if they can help me first. One of the engineers posted this code in their forum, but I couldn't get it work. Plus, his comments are confusing. You can see the complete thread using the link in my previous post.

----

Here I post the code to work with the neopixel and it works well.

#include "mbed.h"

DigitalOut myled(D3);

void RGB_Show(uint8_t r, uint8_t g, uint8_t b);

int main() {
    while(1) {
        RGB_Show(0xff,0x00,0x00);
        wait_ms(500);
        RGB_Show(0x00,0xff,0x00);
        wait_ms(500);
        RGB_Show(0x00,0x00,0xff);
        wait_ms(500);
        RGB_Show(0xff,0x00,0xff);
        wait_ms(500);
        RGB_Show(0xff,0xff,0x00);
        wait_ms(500);
        RGB_Show(0x00,0xff,0xff);
        wait_ms(500);
        RGB_Show(0xff,0xff,0xff);
        wait_ms(500);
    }
}

void RGB_Show(uint8_t r, uint8_t g, uint8_t b)
{
    uint8_t rgb[3] = {g, r, b};
    uint8_t *p = rgb;
    uint8_t *end = p + 3;

    while (p < end)
    {
        uint8_t pix = *p++;
        for (uint8_t mask = 0x80; mask; mask >>= 1)
        {
            if (pix & mask)
            {
                // T1H 760ns
                NRF_GPIO->OUTSET = (1UL << 8);
                NRF_GPIO->OUTSET = (1UL << 8);
                NRF_GPIO->OUTSET = (1UL << 8);

                // T1L 660ns
                NRF_GPIO->OUTCLR = (1UL << 8);
            }
            else
            { 
                // T0H 380ns
                NRF_GPIO->OUTSET = (1UL << 8);

                // T0L 840ns
                NRF_GPIO->OUTCLR = (1UL << 8);
                NRF_GPIO->OUTCLR = (1UL << 8);
                NRF_GPIO->OUTCLR = (1UL << 8);
                NRF_GPIO->OUTCLR = (1UL << 8);
            }
        }
    } 
    NRF_GPIO->OUTCLR = (1UL << 8);
    wait_us(100);
}

The mbed IO operator or APIs can not achieve such toggle speed. You can ask mbed team about how to deal with your problem using mbed APIs.

-------

posted by Chris Bick 29 Jun 2015
Be the first to answer this question.