Author Topic: Digital rgb ledstrip driven by RFDuino  (Read 42433 times)

disk91

  • RFduino Jr. Member
  • **
  • Posts: 24
  • Karma: +1/-0
    • View Profile
    • www.disk91.com
Re: Digital rgb ledstrip driven by RFDuino
« Reply #15 on: January 29, 2014, 02:23:12 PM »
  Thank you for posting the links and info. I also got an RGB-123 kit, but I've been working with WS2811 strips and Arduino Pro Mini boards. February is my month to hack. (Maybe January was a much-needed vacation for our moderator? Hopefully, he'll be back soon, with help on the libraries.  :-)

The main issue we have to manage with RGB123 led strip is that we have to respect a perfect time during a long period. This period is longer than time BLE can survive w/o interruption. If you keep interruption running you'll lose syncho and led strip will not be configured correctly.. That's the mess.

I'm on the way to solve this problem, but I did not yet accomplish this miracle !

Any help welcome on my topic on how stop & restart BLE stack before & after led strip update !
http://www.disk91.com - website
https://twitter.com/disk_91 - follow me on twitter

mkay

  • RFduino Team
  • *****
  • Posts: 405
  • Karma: +15/-0
    • View Profile
Re: Digital rgb ledstrip driven by RFDuino
« Reply #16 on: January 29, 2014, 02:48:04 PM »
Hi the library I posted uses the while (RFduinoBLE.radioActive) loop in some areas to keep that from happening. Give it a whirl and let me know if it works for you.

You may also need to add that to the colorWipe function in the strandtest example:

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
(RFduinoBLE.radioActive)
;
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

edorphy

  • RFduino Full Member
  • ***
  • Posts: 86
  • Karma: +0/-0
    • View Profile
Re: Digital rgb ledstrip driven by RFDuino
« Reply #17 on: January 29, 2014, 06:56:39 PM »
Horray horray!!

Thanks for the post. Will try it out soon!

disk91

  • RFduino Jr. Member
  • **
  • Posts: 24
  • Karma: +1/-0
    • View Profile
    • www.disk91.com
Re: Digital rgb ledstrip driven by RFDuino
« Reply #18 on: January 30, 2014, 12:57:46 AM »
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
(RFduinoBLE.radioActive)
;
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}
as one show() required to be nointerrupt(), I think it is better to have this :
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
(RFduinoBLE.radioActive)
;
      strip.show();
      delay(wait);
  }
}

matter is : if you have too much led in your strip, BLE will crash sometime after show finished.
http://www.disk91.com - website
https://twitter.com/disk_91 - follow me on twitter

mkay

  • RFduino Team
  • *****
  • Posts: 405
  • Karma: +15/-0
    • View Profile
Re: Digital rgb ledstrip driven by RFDuino
« Reply #19 on: February 03, 2014, 12:59:10 PM »
The connection interval for iOS is around 30ms. The radio is active for ~5ms during each connection interval, so you have about 25ms of time to get done what you need before the BLE takes over again.

don

  • RFduino Newbie
  • *
  • Posts: 14
  • Karma: +2/-0
    • View Profile
Re: Digital rgb ledstrip driven by RFDuino
« Reply #20 on: March 23, 2014, 01:58:21 PM »
I'm having trouble with mkay's library (http://forum.rfduino.com/index.php?topic=30.msg1036#msg1036) and neopixels. When the pixels are initialized, they are very bright instead of off.

Any ideas how to fix this?

Code: [Select]
#include <RFduinoBLE.h> //RFduino support
#include <Adafruit_NeoPixel.h>

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
}

Window 8.1
Arduino IDE 1.5.6-r2
RFduino
16 NeoPixel ring

I got similar results on OS X and Linux with Arduino IDE 1.5.5 and 1.5.4. And similar result with 3.3v and 5v power.

tolson

  • Global Moderator
  • *****
  • Posts: 860
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Digital rgb ledstrip driven by RFDuino
« Reply #21 on: March 24, 2014, 12:23:05 AM »
Hi Disk91.

if it can help people, take a look to this article in my website, you'll find de C/asm code I used to get WS2812b lighting with rfduino :) enjoy !
http://www.disk91.com/2014/technology/hardware/rgb123-256-leds-and-rfduino-first-hacks/

Your test_rfduino_rgb.ino with assembler code works nicely with multiple strings of WS2812's.
http://www.disk91.com/wp-content/uploads/2014/01/test_rfduino_rgb.ino_.zip
I modified your test_rfduino_rgb.ino sketch to work with variable size X by Y matrix instead of just 16x16. For example 1 string of 60 (60x1) or 2 strings of 30 (30x2). Here is a diff file of the changes I made.

Code: [Select]
39a40,44
> #define MATRIX_X 30
> #define MATRIX_Y 2
>
> long timestart,timeend;
>
41c46
< int led1 = 6;
---
> int led1 = 3;
43c48
< int toRGB = 2;
---
> int toRGB = 6;
46a52
>   Serial.begin(9600);
49c55
<   rgb123_256_init(toRGB);
---
>   rgb123_matrix_init(toRGB);
54c60
<   for ( int y = 0 ; y < 16 ; y ++ ) {
---
>   for ( int y = 0 ; y < MATRIX_Y ; y ++ ) {
57c63
<     for ( int x = 0 ; x < 18 ; x++ ) {
---
>     for ( int x = 0 ; x < MATRIX_X+2 ; x++ ) {
59c65
<       rgb123_256_setPixel(x-1, y, 0, 0x85, 0);
---
>       rgb123_256_setPixel(x-1, y, 0, 0x85, 0);
60a67,68
>
> timestart=millis();
61a70,72
> timeend=millis();
> Serial.print("Time to show pixels: ");
> Serial.println(timeend-timestart);
74c85
< uint32_t rgb123_256_pixels[256];
---
> uint32_t rgb123_256_pixels[MATRIX_X * MATRIX_Y];
79c90
<   if ( x > 15 || y > 15 ) return;
---
>   if ( x > MATRIX_X-1 || y > MATRIX_Y-1 ) return;
90,91c101,102
<   uint32_t _x = (y & 1 != 0)?15-x:x;
<   rgb123_256_pixels[16*y+_x] = v;
---
>   uint32_t _x = (y & 1 != 0)?MATRIX_X-1-x:x;
>   rgb123_256_pixels[MATRIX_X*y+_x] = v;
97c108
<   for (int i = 0 ; i < 256 ; i++) rgb123_256_pixels[i] = 0;
---
>   for (int i = 0 ; i < MATRIX_X * MATRIX_Y ; i++) rgb123_256_pixels[i] = 0;
118c129
<   uint32_t * _end    = &rgb123_256_pixels[256];   
---
>   uint32_t * _end    = &rgb123_256_pixels[MATRIX_X * MATRIX_Y];   
911c922
<     delay(200);
---
> //    delay(200);
915c926
< void rgb123_256_init( uint32_t pin ) {
---
> void rgb123_matrix_init( uint32_t pin ) {

« Last Edit: March 24, 2014, 01:33:01 AM by tolson »

tolson

  • Global Moderator
  • *****
  • Posts: 860
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Digital rgb ledstrip driven by RFDuino
« Reply #22 on: March 24, 2014, 10:24:56 PM »
I'm having trouble with mkay's library (http://forum.rfduino.com/index.php?topic=30.msg1036#msg1036) and neopixels. When the pixels are initialized, they are very bright instead of off.

Any ideas how to fix this?

Code: [Select]
#include <RFduinoBLE.h> //RFduino support
#include <Adafruit_NeoPixel.h>

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
}

I got similar results on OS X and Linux with Arduino IDE 1.5.5 and 1.5.4. And similar result with 3.3v and 5v power.

The problem with the Adafruit library with the RFduino mods that MKAY made available is that the if-else tests take too long for the for the positive pulse of the ZERO sequence.
Example.
          NRF_GPIO->OUTSET = (1UL << pin);
                if (pix & 0x80) {KHZ800_ONE}
                else {KHZ800_ZERO}
 
So I reversed the test like this which reduced the positive positive pulse to within specs.

                NRF_GPIO->OUTSET = (1UL << pin);
                if (pix & 0x80) {KHZ800_ZERO}
                else {KHZ800_ONE}

Doing that will cause all zero data to be sent for ONEs and ONES sent for ZERO.

To fix that...
     uint8_t pix = *p++;
to
     uint8_t pix = ~*p++;

Voila!
Here is the diff file for the changes to the file... Adafruit_NeoPixel.cpp

Code: [Select]
129,130d128
<                               " NOP\n\t" \
<                               " NOP\n\t" \
203,206c201,204
<      uint8_t pix = *p++;
<         NRF_GPIO->OUTSET = (1UL << pin);
<               if (pix & 0x80) {KHZ800_ONE}
<               else {KHZ800_ZERO}
---
>      uint8_t pix = ~*p++;
>               NRF_GPIO->OUTSET = (1UL << pin);
>               if (pix & 0x80) {KHZ800_ZERO}
>               else {KHZ800_ONE}
208,209c206,207
<         if (pix & 0x40) {KHZ800_ONE}
<               else {KHZ800_ZERO}
---
>               if (pix & 0x40) {KHZ800_ZERO}
>               else {KHZ800_ONE}
211,212c209,210
<               if (pix & 0x20) {KHZ800_ONE}
<               else {KHZ800_ZERO}
---
>               if (pix & 0x20) {KHZ800_ZERO}
>               else {KHZ800_ONE}
214,215c212,213
<               if (pix & 0x10) {KHZ800_ONE}
<               else {KHZ800_ZERO}
---
>               if (pix & 0x10) {KHZ800_ZERO}
>               else {KHZ800_ONE}
217,218c215,216
<               if (pix & 0x08) {KHZ800_ONE}
<               else {KHZ800_ZERO}
---
>               if (pix & 0x08) {KHZ800_ZERO}
>               else {KHZ800_ONE}
220,221c218,219
<               if (pix & 0x04) {KHZ800_ONE}
<               else {KHZ800_ZERO}
---
>               if (pix & 0x04) {KHZ800_ZERO}
>               else {KHZ800_ONE}
223,224c221,222
<               if (pix & 0x02) {KHZ800_ONE}
<               else {KHZ800_ZERO}
---
>               if (pix & 0x02) {KHZ800_ZERO}
>               else {KHZ800_ONE}
226,227c224,225
<               if (pix & 0x01) {KHZ800_ONE}
<               else {KHZ800_ZERO}
---
>               if (pix & 0x01) {KHZ800_ZERO}
>               else {KHZ800_ONE}


I haven't made any changes to the NEO_KHZ400 modes.

Here is the zip file...

Adafruit_NeoPixel_tolsonMod.zip


[NOTE:] This mod is for Arduino 1.5.6. It will was broken by 1.5.7+
« Last Edit: October 29, 2014, 07:50:03 AM by tolson »

tolson

  • Global Moderator
  • *****
  • Posts: 860
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Digital rgb ledstrip driven by RFDuino
« Reply #23 on: March 24, 2014, 11:24:00 PM »
Here's a video of the RFduino driving the string of 60 WS2812 RGB LEDs...

<a href="http://www.youtube.com/v/ExC0_VoaS1E/" target="_blank" class="new_win">http://www.youtube.com/v/ExC0_VoaS1E/</a>
« Last Edit: July 04, 2014, 02:22:25 PM by tolson »

mkay

  • RFduino Team
  • *****
  • Posts: 405
  • Karma: +15/-0
    • View Profile
Re: Digital rgb ledstrip driven by RFDuino
« Reply #24 on: March 25, 2014, 01:39:55 PM »
Nice job tolson  :)

fortolano

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Digital rgb ledstrip driven by RFDuino
« Reply #25 on: May 08, 2014, 02:29:27 PM »
Hi Tolson,
Great job by helping us out with your library.
I've downloaded, and it compiled and uploaded just fine to my RFDuino.
The problem that I've encountered is that I am using the Adafruit NeoPixel 12 LED ring... much smaller than a LED strip. So I've adjusted the number of LEDs from 60 down to 12 on the arduino code, but the issue is that the LEDs are way brighter (extremely!!!) than usual when using your library.  When using the Adafruit library on an Arduino Uno, the LED ring brights up really nicely, but using your library with RFduino, all LEDS become pretty much WHITE and super bright all the time... you can barely see any animation (rainbow, etc etc) going.

Any ideas on how to fix this?

Thanks in advance
Flavio

Christian

  • RFduino Newbie
  • *
  • Posts: 10
  • Karma: +1/-0
    • View Profile
Re: Digital rgb ledstrip driven by RFDuino
« Reply #26 on: May 08, 2014, 02:42:25 PM »
Hi Flavio,

Have you tried setBrightness() method ?

tolson

  • Global Moderator
  • *****
  • Posts: 860
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Digital rgb ledstrip driven by RFDuino
« Reply #27 on: May 08, 2014, 02:46:06 PM »
Hi Tolson,
Great job by helping us out with your library.
I've downloaded, and it compiled and uploaded just fine to my RFDuino.
The problem that I've encountered is that I am using the Adafruit NeoPixel 12 LED ring... much smaller than a LED strip. So I've adjusted the number of LEDs from 60 down to 12 on the arduino code, but the issue is that the LEDs are way brighter (extremely!!!) than usual when using your library.  When using the Adafruit library on an Arduino Uno, the LED ring brights up really nicely, but using your library with RFduino, all LEDS become pretty much WHITE and super bright all the time... you can barely see any animation (rainbow, etc etc) going.

Any ideas on how to fix this?

Thanks in advance
Flavio
Hi Flavio,
Can you post your sketch?

fortolano

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Digital rgb ledstrip driven by RFDuino
« Reply #28 on: May 08, 2014, 02:54:21 PM »
Sure,
my code is exactly the one from the Example folder of your library, my only change is this line:

From
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
to
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);

(thanks in advance)
----------------------------------------------------------------

#include <RFduinoBLE.h> //RFduino support
#include <Adafruit_NeoPixel.h>

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
  rainbow(20);
  rainbowCycle(20);
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}


tolson

  • Global Moderator
  • *****
  • Posts: 860
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Digital rgb ledstrip driven by RFDuino
« Reply #29 on: May 08, 2014, 03:06:54 PM »
Do you get the color wipes. Or are all the LEDs on white all the time?