RFduino Forum

RFduino => Interesting Uses and Applications => Topic started by: PeterS on November 07, 2013, 04:36:22 PM

Title: Digital rgb ledstrip driven by RFDuino
Post by: PeterS on November 07, 2013, 04:36:22 PM
(Post should be in 'Interesting Uses and Applications' but could make a new topic over there  :(   )
Dear all,

I'm thinking about a project to control a digital RGB ledstrip with the RFDuino.
(I would like to start using the RFDuinos & NeoPixels in (next years) halloween props)

The ledstrip I had in mind is the "Adafruit NeoPixel Digital RGB LED Weatherproof Strip" (http://learn.adafruit.com/adafruit-neopixel-uberguide (http://learn.adafruit.com/adafruit-neopixel-uberguide)) or any compatible WS2812B LED with build in WS2811 IC

But some questions before I buy those strips (or 'Breadboard-friendly RGB Smart NeoPixel')
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: kos on November 10, 2013, 11:08:14 AM
Peter,

I would think it should work just fine. The reason the rpi and similar will not work is because they are not "real-time". I have a NeoPixel Ring and I'm using a Teensy 2.0 with it at the moment without issue. I anticipate once I receive my RFduinos it should be fine.

Now for the 3.3v question, I know that the power source for the NeoPixel VCC needs to be 5V, and I believe DIN must be as well. You may need a voltage step-up and a logic level converter to interface a 3.3v device with a 5V device. If you want to try parsing through the datasheet for the controller on that strip, here's a link: http://www.adafruit.com/datasheets/WS2811.pdf It looks like you may be able to get away without a logic level converter in this case.

I'm very curious about this as well, since I am planning to use an RFduino for my NeoPixel project. I'll let you know what I find out.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: PeterS on November 13, 2013, 01:17:38 PM
Kos,

I installed the adafruit_neopixel library but when compiling for the RFDuino board I receive a page full of compile errors
ie
xx\libraries\Adafruit_NeoPixel\Adafruit_NeoPixel.cpp: In member function 'void Adafruit_NeoPixel::show()':
xx\libraries\Adafruit_NeoPixel\Adafruit_NeoPixel.cpp:788: error: 'Pio' was not declared in this scope
xx\libraries\Adafruit_NeoPixel\Adafruit_NeoPixel.cpp:788: error: 'port' was not declared in this scope
xx\libraries\Adafruit_NeoPixel\Adafruit_NeoPixel.cpp:789: error: expected initializer before '*' token
...
(similar to what Josh is describing in a 'RGB' post in the Getting Started section)

Library is correctly installed because when compiling for the UNO board I have 0 errors.

=> somewhere the adafruit libraries a (not yet) ready for the RFDuino (or RFDuino not reay for the Adafruit libraries  ;) )
Unclear to me if tweaking is need in the adafruit libraries.
or that something should be improved in the definition of the RFDuino


resources :
http://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use/arduino-libraries
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: PeterS on November 13, 2013, 03:13:41 PM
Similar issues with the fastSPI_LED2 library  (https://code.google.com/p/fastspi/)

Compile errors when compiled for RFDuino.
NO compile errors when same sample file (FirstLight) is compiled for Arduino UNO
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: PeterS on November 15, 2013, 03:50:54 AM
Looks like the rfduino is already on the radar of the fastled.io (fastspi_led) community. https://plus.google.com/102282558639672545743/posts/craCLvj4629
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: dale3h on November 21, 2013, 01:00:24 AM
From what I understand, it will require modifications to the RFduino libraries. Let's hope someone out there can make these modifications because I am highly interested in running my Adafruit NeoPixel 144 and NeoPixel 60 strips with RFduino.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: RFadmin on December 04, 2013, 12:31:49 PM
We are looking at this library and will try to add support soon  ;)
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: PeterS on December 19, 2013, 11:16:43 AM
RFadmin,
Any progress in the support for the fastled.io libray ?

Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: mkay on December 20, 2013, 02:04:02 PM
Hi, we haven't used the fastio library, but we have been able to use the WS2812 library with modifications to drive the led strings. We are still testing it, but we should have a video and more info soon.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: akbsteam on January 06, 2014, 05:03:31 AM
mkay: is there an alpha version of that code I can try playing with?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: disk91 on January 11, 2014, 07:28:00 AM
Hi, we haven't used the fastio library, but we have been able to use the WS2812 library with modifications to drive the led strings. We are still testing it, but we should have a video and more info soon.

Hello, I'm trying to manage this kind of leds, but my timing seems to not be really good :( can you share your code ?
Are you driving the control of led with 3.3V or 5V ? if 5V what translator are you using ?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: disk91 on January 12, 2014, 09:24:52 AM
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/ (http://www.disk91.com/2014/technology/hardware/rgb123-256-leds-and-rfduino-first-hacks/)
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: sgilroy on January 27, 2014, 05:49:45 AM
Has any progress been made with adding support for RFduino to either the FastLED or NeoPixel libraries? It looks like @RFadmin has not been active in the RFduino forum since December. Thanks!
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: zonker on January 29, 2014, 09:20:29 AM
  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.  :-)

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/ (http://www.disk91.com/2014/technology/hardware/rgb123-256-leds-and-rfduino-first-hacks/)
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: mkay on January 29, 2014, 12:40:13 PM
Hi guys, this is not an official release, but it is a modified version of the Adafruit neopixel library with RFduino support.

Its working well on my end, let me know if you guys have any trouble with it.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: disk91 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 !
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: mkay 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);
  }
}
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: edorphy on January 29, 2014, 06:56:39 PM
Horray horray!!

Thanks for the post. Will try it out soon!
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: disk91 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.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: mkay 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.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: don 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 (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.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson 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/ (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 (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 ) {

Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson 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 (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 (http://thomasolson.com/PROJECTS/BLE/RFduino/files/Adafruit_NeoPixel_tolsonMod.zip)


[NOTE:] This mod is for Arduino 1.5.6. It will was broken by 1.5.7+
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on March 24, 2014, 11:24:00 PM
Here's a video of the RFduino driving the string of 60 WS2812 RGB LEDs...

http://www.youtube.com/v/ExC0_VoaS1E/
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: mkay on March 25, 2014, 01:39:55 PM
Nice job tolson  :)
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: fortolano 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
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: Christian on May 08, 2014, 02:42:25 PM
Hi Flavio,

Have you tried setBrightness() method ?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson 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?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: fortolano 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);
  }
}

Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on May 08, 2014, 03:06:54 PM
Do you get the color wipes. Or are all the LEDs on white all the time?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: fortolano on May 08, 2014, 03:23:42 PM
Hi Tolson,
For the colorwipe, the LEDS flick a bit, so you can tell there is some sort of animation going, but the LEDs are still super super bright (almost white).
I am attaching a video that I've just recorded from with my phone (pardon the bad production)

Thanks again.
Flavio
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on May 08, 2014, 03:31:24 PM
I can't play your quicktime movie. However, from what you descripe you are not using my modifications.

After you unzip my zip file you need to rename the folder to  Adafruit_NeoPixel without my name attached.
What appears to be happening is your script is accessing the actual Adafruit library in the unmodified Adafruit folder.

You need to replace that folder with mine.


Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: mark_n on June 11, 2014, 08:22:57 PM
Hi,

So I downloaded this mod to try it out, but it won't compile. I've also tried the Tolsonmod but same issues. The errors I'm getting are basically that nothing is in scope. I'm not sure what the issue is, because if I switch the board to say "Uno" it compiles.

Any ideas?

Thank you!

Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on June 11, 2014, 09:11:44 PM
Need more Input!

What Arduino version?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on June 11, 2014, 09:19:07 PM
Hi,

So I downloaded this mod to try it out, but it won't compile. I've also tried the Tolsonmod but same issues. The errors I'm getting are basically that nothing is in scope. I'm not sure what the issue is, because if I switch the board to say "Uno" it compiles.

Any ideas?

Thank you!

OK, looking at your errors, you are not using the version for the RFduino.
The line numbers for the errors you are getting do not contain those commands in my version.
So you must still be accessing the un-modified versions.

Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: mark_n on June 11, 2014, 10:18:14 PM
Turns out it was a naming conflict.

So if you're using one library (tolson mod, or the mkay mod) you have to remove the original neo-pixel library. Small thing, but good to find out. Complies and works now.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: foobar on July 17, 2014, 08:36:34 PM
@fortolano: Have you found a solution yet?

@others: I have the same problem as Flavio/fortolano (i.e., I always see white + color instead of the color I actually set it to) and I would appreciate any help. Here's the due diligence I have done so far. Like fortolano, I am also using the Adafruit Neopixel 12-LED ring. (I have also tried it on a strip of 7 neopixels and got the same problem.)

1) Used tolson's library and renamed it as Adafruit_Neopixel.
2) Only change to the example sketch is to change the number of pixels and the output pin (pin 2).
3) Used mkay's library and still got the same symptoms.
4) I know for sure that the LED strip/ring is fine because it works on teensy 3.1 and on the ATTiny85 (both with original Neopixel library).
5) I do not have any naming issues... I only keep one version of the library when testing.
---
Added later: I'm using Arduino 1.5.7 and RFDuino 2.1.
I'm running the RFDuino on USB power (via the USB shield) and powering the LED strips via a LiPo battery.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on July 18, 2014, 12:54:05 PM
Hi foobar,
Yes, the neopixel issue was resolved in the previous versions of Arduino 1.5.6-r2 with any version of RFduino prior to version 2.1.

I can confirm that the new beta Arduino 1.5.7 is slower than 1.5.6. At least in the time it takes to do if-else calls and returns. This results in stretching the critical timing required for neo pixel strips. I have confirmed that this occurs regardless of which RFduino version is used.

As far as ATTiny85 and Teensy 3.1... I think Teensy 3.1 only uses Aduino 1.0.x so far. Not sure how far the ATTiny85 has come with 1.5.x. But it doesn't matter. The timing code in the pixel library does different things specific for each microprocessor type, so you can't compare the three results. But, I realize you are probably just saying you are confirming that the strip isn't broken because it does work elsewhere. Cool!

Anyways, back to the drawing board. Either we need to figure out a speed optimize flag for the new compiler to return the compiled code back to faster code, or do more of the timing in Assembler instead of a mix of C and Assembler. I suspect the push to make the compiler produce smaller object code resulted in slower code for some functions.

In the mean time, if it is urgent to use neopixels (WS2812(B)) LEDs, I am going to continue using Arduino 1.5.6-r2 with RFduino-2.0.3. It looks to me like most of what changed in 2.1 was just to point to the changes in 1.5.7 naming and paths.

Arduino calls their 1.5.x versions BETA versions, meaning things may break with every revision. This is one good example.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on July 19, 2014, 02:15:04 AM
OK, got my old test program working again using the Arduino IDE 1.5.7 and the RFduino version 2.1.

http://www.youtube.com/v/i_N1K8oJ85M/

Try this code...

Code: [Select]
// WS2812_RFduino_Test
// By Thomas Olson
// teo20140220.01
// teo20140719.01 Modified for Arduino 1.5.7
// 20141022.. verified works with Arduino 1.5.8
// No complicated Pixel Library needed.
// Tested with WS2812B 4 pin versions.

const int ws2812pin = 6;

const int nPIXELS = 60;

const int nLEDs = nPIXELS * 3;
uint8_t ledBar[nLEDs];


void setup() {

  pinMode(ws2812pin, OUTPUT);
  digitalWrite(ws2812pin, LOW);
  // Initialize the ledBar array - all LEDs OFF.
  for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    ledBar[wsOut] = 0x00;
  }
  loadWS2812();
 
  delay(1);
}

void loop() {
   
 for(int wsOut = 0; wsOut < nLEDs; wsOut+=3){ // green
    ledBar[wsOut] = 0x3c;
    loadWS2812();
   
    delay(10);
   
    ledBar[wsOut] = 0x00;
    loadWS2812();
  }

 for(int wsOut = 1; wsOut < nLEDs; wsOut+=3){ // red
    ledBar[wsOut] = 0x3c;
    loadWS2812();
   
    delay(10);
   
    ledBar[wsOut] = 0x00;
    loadWS2812();
  }
 
   for(int wsOut = 2; wsOut < nLEDs; wsOut+=3){ // blue
    ledBar[wsOut] = 0x3c;
    loadWS2812();
   
    delay(10);
   
    ledBar[wsOut] = 0x00;
    loadWS2812();
  }


}

void loadWS2812(){
 
  noInterrupts();

  for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    for(int x=7; x>=0; x--){
      NRF_GPIO->OUTSET = (1UL << ws2812pin);
      if(ledBar[wsOut] & (0x01 << x)) {
        __ASM ( \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              );
        NRF_GPIO->OUTCLR = (1UL << ws2812pin);
     
      }else{
        NRF_GPIO->OUTCLR = (1UL << ws2812pin);
        __ASM ( \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              );     
      }
    }
  }
  delayMicroseconds(50); // latch and reset WS2812.
  interrupts(); 
}


[EDIT] Verified works with Arduino 1.5.8
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: foobar on July 19, 2014, 08:34:32 PM
@tolson, Thanks a lot. I really appreciate your help. I will try out the new version and get back to you. 

And yes, my only point in bringing up the Teensy and ATTiny85 was that the LED strip was okay. (I am indeed using both Teensy 3.1 and ATTiny85 with Arduino 1.0.5.)
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: foobar on July 20, 2014, 07:59:05 AM
The new sketch works. Thanks a lot.

Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: mkay on August 26, 2014, 06:44:51 PM
Nice sketch tolson it works well.  :)

I made a change to the modified Adafruit library again and this one seems to work for me with Arduino v1.5.7. Only tested the 800khz speed. Let me know if it works for you guys also.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: gotnull on September 16, 2014, 12:51:19 AM
Hi guys, this is not an official release, but it is a modified version of the Adafruit neopixel library with RFduino support.

Its working well on my end, let me know if you guys have any trouble with it.

I'm using this but I'm still getting errors compiling:

Arduino: 1.5.7 (Mac OS X), Board: "RFduino"

Using library RFduinoBLE in folder: /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/libraries/RFduinoBLE (legacy)
Using library Adafruit_NeoPixel in folder: /Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel (legacy)

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-builtin -mcpu=cortex-m0 -DF_CPU=16000000 -DARDUINO=157 -mthumb -D__RFduino__ -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/cores/arduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/variants/RFduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/libraries/RFduinoBLE -I/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/system/RFduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/system/RFduino/Include -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/system/CMSIS/CMSIS/Include /var/folders/b6/pnpkh4cd7dj0xcbygbdw9mph0000gn/T/build7271153727973197368.tmp/strandtest_rfduino.cpp -o /var/folders/b6/pnpkh4cd7dj0xcbygbdw9mph0000gn/T/build7271153727973197368.tmp/strandtest_rfduino.cpp.o
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-builtin -mcpu=cortex-m0 -DF_CPU=16000000 -DARDUINO=157 -mthumb -D__RFduino__ -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/cores/arduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/variants/RFduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/libraries/RFduinoBLE -I/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/libraries/RFduinoBLE/utility -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/system/RFduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/system/RFduino/Include -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/system/CMSIS/CMSIS/Include /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/libraries/RFduinoBLE/RFduinoBLE.cpp -o /var/folders/b6/pnpkh4cd7dj0xcbygbdw9mph0000gn/T/build7271153727973197368.tmp/RFduinoBLE/RFduinoBLE.cpp.o
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-builtin -mcpu=cortex-m0 -DF_CPU=16000000 -DARDUINO=157 -mthumb -D__RFduino__ -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/cores/arduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/variants/RFduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/libraries/RFduinoBLE -I/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel -I/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/utility -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/system/RFduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/system/RFduino/Include -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/system/CMSIS/CMSIS/Include /Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp -o /var/folders/b6/pnpkh4cd7dj0xcbygbdw9mph0000gn/T/build7271153727973197368.tmp/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp.o
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp: In member function 'void Adafruit_NeoPixel::show()':
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:748:3: error: 'Pio' was not declared in this scope
   Pio            *port;
   ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:748:19: error: 'port' was not declared in this scope
   Pio            *port;
                   ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:749:12: error: 'WoReg' does not name a type
   volatile WoReg *portSet, *portClear, *timeValue, *timeReset;
            ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:752:29: error: 'pmc_set_writeprotect' was not declared in this scope
   pmc_set_writeprotect(false);
                             ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:753:35: error: 'TC3_IRQn' was not declared in this scope
   pmc_enable_periph_clk((uint32_t)TC3_IRQn);
                                   ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:753:43: error: 'pmc_enable_periph_clk' was not declared in this scope
   pmc_enable_periph_clk((uint32_t)TC3_IRQn);
                                           ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:754:16: error: 'TC1' was not declared in this scope
   TC_Configure(TC1, 0,
                ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:755:5: error: 'TC_CMR_WAVE' was not declared in this scope
     TC_CMR_WAVE | TC_CMR_WAVSEL_UP | TC_CMR_TCCLKS_TIMER_CLOCK1);
     ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:755:19: error: 'TC_CMR_WAVSEL_UP' was not declared in this scope
     TC_CMR_WAVE | TC_CMR_WAVSEL_UP | TC_CMR_TCCLKS_TIMER_CLOCK1);
                   ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:755:38: error: 'TC_CMR_TCCLKS_TIMER_CLOCK1' was not declared in this scope
     TC_CMR_WAVE | TC_CMR_WAVSEL_UP | TC_CMR_TCCLKS_TIMER_CLOCK1);
                                      ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:755:64: error: 'TC_Configure' was not declared in this scope
     TC_CMR_WAVE | TC_CMR_WAVSEL_UP | TC_CMR_TCCLKS_TIMER_CLOCK1);
                                                                ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:756:18: error: 'TC_Start' was not declared in this scope
   TC_Start(TC1, 0);
                  ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:758:15: error: 'g_APinDescription' was not declared in this scope
   pinMask   = g_APinDescription[pin].ulPin; // Don't 'optimize' these into
               ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:760:3: error: 'portSet' was not declared in this scope
   portSet   = &(port->PIO_SODR);            // burn a few cycles after
   ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:761:3: error: 'portClear' was not declared in this scope
   portClear = &(port->PIO_CODR);            // starting timer to minimize
   ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:762:3: error: 'timeValue' was not declared in this scope
   timeValue = &(TC1->TC_CHANNEL[0].TC_CV);  // the initial 'while'.
   ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:763:3: error: 'timeReset' was not declared in this scope
   timeReset = &(TC1->TC_CHANNEL[0].TC_CCR);
   ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:787:18: error: 'TC_CCR_CLKEN' was not declared in this scope
     *timeReset = TC_CCR_CLKEN | TC_CCR_SWTRG;
                  ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:787:33: error: 'TC_CCR_SWTRG' was not declared in this scope
     *timeReset = TC_CCR_CLKEN | TC_CCR_SWTRG;
                                 ^
/Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp:797:17: error: 'TC_Stop' was not declared in this scope
   TC_Stop(TC1, 0);
                 ^
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on September 16, 2014, 07:42:37 AM
Hi guys, this is not an official release, but it is a modified version of the Adafruit neopixel library with RFduino support.

Its working well on my end, let me know if you guys have any trouble with it.

I'm using this but I'm still getting errors compiling:

Arduino: 1.5.7 (Mac OS X), Board: "RFduino"

Using library RFduinoBLE in folder: /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/RFduino/libraries/RFduinoBLE (legacy)
Using library Adafruit_NeoPixel in folder: /Users/fulvio/Documents/Arduino/libraries/Adafruit_NeoPixel (legacy)

* * *

Hi gotnull,

From the quote I assume you are using the mod file provided with that comment. Is that right? If so, that may be the problem. mkay as provided an updated mod2 file for the 1.5.7 / 2.1.x  IDE. Can you confirm which you are using?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: zabowsky on October 19, 2014, 02:02:42 PM
Nice sketch tolson it works well.  :)

I made a change to the modified Adafruit library again and this one seems to work for me with Arduino v1.5.7. Only tested the 800khz speed. Let me know if it works for you guys also.

This library is not working for me. I get the same results using this or the original mod, which is that all my LEDs simply stay bright white no matter what I send.

I'm using Arduino 1.5.7 - I've also tried 1.5.8 -, RFduino 2.1.2, and a 16 LED ring.

With tolson's updated example sketch, modified for my LED ring size, I see one of my 16 LEDs cycle through colors properly, and the other 15 remain bright white.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on October 19, 2014, 08:28:34 PM
Can you describe your hardware setup?

Is it the first LED in the chain that works?

What voltage source are you using to supply Vcc to the LED chain?

Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: zabowsky on October 20, 2014, 07:29:34 PM
Nothing special about my setup, I don't think. I've got a 16x NeoPixel Ring hooked up to pin 6 of an RFduino board; nothing else. I was initially powering the ring from the 3.3V board supply, but have now switched to using a dedicated 5V supply, with the same results.

I messed around some more and got some different results with the _tolsenMod.zip lib. With those files I can get strandtest to do what I expect it to do, looping through colors and rainbows (woo). The LEDs are quite bright in this configuration, though, and setting a value any lower than max results in all white, and doesn't actually lower the brightness.

With the _mod2.zip files I always get all bright white LEDs from strandtest.

The non-library sample sketch results in one functional LED and the rest all bright white. I can't tell for sure if the one that cycles through the colors is the first or last in the ring...it's next to the Data Out pin (which I'm not using).
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on October 22, 2014, 06:45:44 PM
Hi zabowsky,

Nothing special about my setup, I don't think. I've got a 16x NeoPixel Ring hooked up to pin 6 of an RFduino board; nothing else. I was initially powering the ring from the 3.3V board supply, but have now switched to using a dedicated 5V supply, with the same results.
 * * *
The non-library sample sketch results in one functional LED and the rest all bright white. I can't tell for sure if the one that cycles through the colors is the first or last in the ring...it's next to the Data Out pin (which I'm not using).

Do you have ground connected between the RFduino and the Ring?

The one that works would be the first one in the chain. Each LED passes the signal from its DI to it DO by re-syncing and buffering the pulses. So anything not working past the last working one is do to lost of sync.

Just verified the test sketch for Arduino 1.5.7 still works on Arduino 1.5.8.
http://forum.rfduino.com/index.php?topic=30.msg2526#msg2526

Can you describe your exact wiring configuration?
Can you post your entire sketch, so I can run it.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: zabowsky on October 22, 2014, 07:17:38 PM
At the moment I've got the DataIn pin of my NeoPixel ring connect to GPIO6 of an RFduino board. The ground pin of the ring is connected to ground on the RFduino and the power connected to the 3.3V pin on the RFduino. The RFduino is being powered over USB, and nothing else is connected. I've alternately tried powering the ring with a dedicated 5V supply (old wall wart), with the same results.

Here's the sketch which produces 1x working LED and 15x bright white LEDs - the only modification to the earlier post is to set nPIXELS = 16:

Code: [Select]
// WS2812_RFduino_Test
// By Thomas Olson
// teo20140220.01
// teo20140719.01 Modified for Arduino 1.5.7
// 20141022.. verified works with Arduino 1.5.8
// No complicated Pixel Library needed.
// Tested with WS2812B 4 pin versions.

const int ws2812pin = 6;

const int nPIXELS = 16;

const int nLEDs = nPIXELS * 3;
uint8_t ledBar[nLEDs];


void setup() {

  pinMode(ws2812pin, OUTPUT);
  digitalWrite(ws2812pin, LOW);
  // Initialize the ledBar array - all LEDs OFF.
  for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    ledBar[wsOut] = 0x00;
  }
  loadWS2812();
 
  delay(1);
}

void loop() {
   
 for(int wsOut = 0; wsOut < nLEDs; wsOut+=3){ // green
    ledBar[wsOut] = 0x3c;
    loadWS2812();
   
    delay(10);
   
    ledBar[wsOut] = 0x00;
    loadWS2812();
  }

 for(int wsOut = 1; wsOut < nLEDs; wsOut+=3){ // red
    ledBar[wsOut] = 0x3c;
    loadWS2812();
   
    delay(10);
   
    ledBar[wsOut] = 0x00;
    loadWS2812();
  }
 
   for(int wsOut = 2; wsOut < nLEDs; wsOut+=3){ // blue
    ledBar[wsOut] = 0x3c;
    loadWS2812();
   
    delay(10);
   
    ledBar[wsOut] = 0x00;
    loadWS2812();
  }


}

void loadWS2812(){
 
  noInterrupts();

  for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    for(int x=7; x>=0; x--){
      NRF_GPIO->OUTSET = (1UL << ws2812pin);
      if(ledBar[wsOut] & (0x01 << x)) {
        __ASM ( \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              );
        NRF_GPIO->OUTCLR = (1UL << ws2812pin);
     
      }else{
        NRF_GPIO->OUTCLR = (1UL << ws2812pin);
        __ASM ( \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              );     
      }
    }
  }
  delayMicroseconds(50); // latch and reset WS2812.
  interrupts(); 
}


Thanks for the assistance!
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on October 22, 2014, 07:41:59 PM
Using your sketch for 16 pixels it works on my chain.
Which model neopixel ring do you have? Brand? Part Number?
Can you determine is it the 6pin (WS2812) or the 4pin (WS2812B) chips.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: zabowsky on October 22, 2014, 07:58:00 PM
I'm using this guy: https://www.sparkfun.com/products/12664 (https://www.sparkfun.com/products/12664)

It's stamped with WS2812 and there are 6 pins per LED (despite the picture on sparkfun showing 4 pins).
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: gcgasson on October 27, 2014, 01:27:18 AM
Hi Tolson,

I have the same problem between the Arduino Uno and the RFDuino. The Uno works great but I seem to have a problem with the RFDuino.

What I have noticed on my oscilloscope and maybe this could point you into the problem. I find that the first bit of every byte is out of spec (Meaning the first BIT is 920ns and the total length of the first 0 & 1 is 2.12us) but the rest is fine and in spec.

So if I send a r=0,g=0 and b=0 and this should turn the LED to OFF I get very bright white LED shinning.

Please could help to tell me where to look to try and fix this problem.

Best Regards,

Gary
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on October 27, 2014, 07:28:54 AM

What I have noticed on my oscilloscope and maybe this could point you into the problem. I find that the first bit of every byte is out of spec (Meaning the first BIT is 920ns and the total length of the first 0 & 1 is 2.12us) but the rest is fine and in spec.
Gary

Hi Gary,
Are those measurements using one of the sketches that use one of the modified libraries. Or is it for my bare minimum sketch that does not use a library. Can you provide measurements for the latter.
Tom
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on October 27, 2014, 09:35:35 AM
Hi Zaboswky and Gary,

Can you try this hex file. It works on my ring for 16 NeoPixels.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: gcgasson on October 27, 2014, 10:43:25 AM
Hi Tolson,

I have used your Adafruit_NeoPixel_tolsonMod.zip and replaced the original. First removed original then replaced it.

I have a 24 LED Neoplix Ring and my Sketch is as follows:

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

#define PIN 5

Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

  // this is the data we want to appear in the advertisement
  // (if the deviceName and advertisementData are too long to fix into the 31 byte
  // ble advertisement packet, then the advertisementData is truncated first down to
  // a single byte, then it will truncate the deviceName)
//  Serial.begin(9600);
//  while (!Serial) {
//    ; // wait for serial port to connect. Needed for Leonardo only
//  }
//  Serial.println("We have started");

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

  //RFduinoBLE.advertisementData = "rgb";

  //start the BLE stack
  //RFduinoBLE.begin();


}

void loop() {
  // switch to lower power mode
  //RFduino_ULPDelay(INFINITE);
  colorWipe(strip.Color(0, 0, 0), 50);
  //colorWipe(strip.Color(0, 255, 0), 50);
  //colorWipe(strip.Color(0, 0, 255), 50);
}

void RFduinoBLE_onConnect() {
  // the default starting color on the iPhone is white
  colorWipe(strip.Color(0, 0, 0), 50);
//  Serial.println("We have connected");
}

void RFduinoBLE_onDisconnect() {
  // turn all leds off on disconnect and stop pwm
  colorWipe(strip.Color(0, 0, 0), 50);
}

void RFduinoBLE_onReceive(char *data, int len) {
  // each transmission should contain an RGB triple
  if (len >= 3)
  {
    // get the RGB values
    uint8_t r = data[0];
    uint8_t g = data[1];
    uint8_t b = data[2];

    colorWipe(strip.Color(r, g, b), 50);
  }
}

// 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);
  }
}
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: gcgasson on October 27, 2014, 10:48:50 AM
How do I upload the hex file to the RFDuino?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on October 27, 2014, 10:52:35 AM
Hi Tolson,

I have used your Adafruit_NeoPixel_tolsonMod.zip and replaced the original. First removed original then replaced it.


My modifided Adafruit library is only good for Arduino 1.5.6. It is broken under 1.5.7 and 1.5.8.

To test the timing specific for RFduino and Arduino 1.5.[7-8] can you report on my  non-library sketch.
The hex file above will work on the 24 pixel device as well... just lighting up the first 16 pixels. The hex loader is called RFDLoader and it is in the RFduino folder. There are versions for windows, 32bit mac and 64 bit mac.


Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: gcgasson on October 27, 2014, 01:27:19 PM
Non library sketch worked after a little tweeking. Thank you.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on October 27, 2014, 01:31:37 PM
Non library sketch worked after a little tweeking. Thank you.

What did you tweak?????
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: zabowsky on October 27, 2014, 04:50:55 PM
Hi Zaboswky and Gary,

Can you try this hex file. It works on my ring for 16 NeoPixels.

I just pushed the hex file to my board and got the same result as with the standalone sketch. One LED cycling through colors at an appropriate brightness, and the others all bright white.

...and then I accidentally disconnect the ground pin from the ring and it started working perfectly!...I'm not yet sure what to make of that. I suspected a bad solder joint, but there's nothing obviously shorted when I look closely.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: zabowsky on October 27, 2014, 05:06:39 PM

I just pushed the hex file to my board and got the same result as with the standalone sketch. One LED cycling through colors at an appropriate brightness, and the others all bright white.

...and then I accidentally disconnect the ground pin from the ring and it started working perfectly!...I'm not yet sure what to make of that. I suspected a bad solder joint, but there's nothing obviously shorted when I look closely.

I cleaned up and re-soldered the ring connections and get the same behavior. It looks great when GND is disconnected. Bright white with it connected.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: gcgasson on October 27, 2014, 09:43:13 PM
Non library sketch worked after a little tweeking. Thank you.

What did you tweak?????

Hi, I have the Neopixel Ring 24Led which uses the 4pin WS2412B which timing is slightly different. If I use your non library unit then I can run with max 20 leds but it is if the sync goes out then all hell breaks loose. So finally I remove two of the NOP lines at Zero and One and that made it better but still not perfect. So finally I reduced the voltage to about 3.6V and all started working 100%

So my findings are that VCC and datalines need to be at the same voltage. Well I will try it this morning as the RFDuino is 3V dataline and I was running the Ring at 5V so I will build a shift level converter.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on October 29, 2014, 08:03:43 AM
Non library sketch worked after a little tweeking. Thank you.

What did you tweak?????

Hi, I have the Neopixel Ring 24Led which uses the 4pin WS2412B which timing is slightly different. If I use your non library unit then I can run with max 20 leds but it is if the sync goes out then all hell breaks loose. So finally I remove two of the NOP lines at Zero and One and that made it better but still not perfect. So finally I reduced the voltage to about 3.6V and all started working 100%

So my findings are that VCC and datalines need to be at the same voltage. Well I will try it this morning as the RFDuino is 3V dataline and I was running the Ring at 5V so I will build a shift level converter.

Yes, it is good idea to have a level shifter if you are going to run the string at 5 volts while running the controller at 3.3v. I have not had any loss of  sync using 3.3 volts on long strings of 60+. Can you verify that your long string works OK if all is supplied with 3.3 volts instead of 5 volts?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: gcgasson on October 29, 2014, 09:10:01 AM
Non library sketch worked after a little tweeking. Thank you.

What did you tweak?????

Hi, I have the Neopixel Ring 24Led which uses the 4pin WS2412B which timing is slightly different. If I use your non library unit then I can run with max 20 leds but it is if the sync goes out then all hell breaks loose. So finally I remove two of the NOP lines at Zero and One and that made it better but still not perfect. So finally I reduced the voltage to about 3.6V and all started working 100%

So my findings are that VCC and datalines need to be at the same voltage. Well I will try it this morning as the RFDuino is 3V dataline and I was running the Ring at 5V so I will build a shift level converter.

Yes, it is good idea to have a level shifter if you are going to run the string at 5 volts while running the controller at 3.3v. I have not had any loss of  sync using 3.3 volts on long strings of 60+. Can you verify that your long string works OK if all is supplied with 3.3 volts instead of 5 volts?

Hi, my 24 LED works perfect when I run it at 3.3V.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: reconbot on November 15, 2014, 06:40:55 PM
Any luck getting the library working on the 1.5.8 ide?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: lsnyman on December 01, 2014, 08:02:33 PM
I have some inventory of RGB LED strips with 144 WS2812B per/m similar to Adafruit http://www.adafruit.com/products/1507 (http://www.adafruit.com/products/1507)
price is $39.95 plus shipping.
PM me if anyone is interested
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on December 02, 2014, 03:08:53 PM
Any luck getting the library working on the 1.5.8 ide?

Do you really need the library?  For a dedicated application and the simplicity of the RFduino I find the subroutine function good enough. And takes up less storage, if that is an issue. and less interfering with other sensors / libraries.

How are you planning to use the LEDs?

Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: lemonade on December 18, 2014, 03:22:42 PM
I recently updated my Arduino IDE to 1.5.7 and my RFDuino library to the latest 2.2.2.

I am using a single Adafruit NeoPixel.  When I upload my code the LED remains at half brightness and never turns off.  I have seen this issue mentioned before, but could not find a solution to the problem.

I'm using the Tolson mod of Adafruit_NeoPixel.h.

It still works fine if I use Arduino 1.5.6-r2, but I need the newer version of the IDe.

Anyone experience this and have a solution?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on December 18, 2014, 10:11:04 PM
I recently updated my Arduino IDE to 1.5.7 and my RFDuino library to the latest 2.2.2.

I am using a single Adafruit NeoPixel.  When I upload my code the LED remains at half brightness and never turns off.  I have seen this issue mentioned before, but could not find a solution to the problem.

I'm using the Tolson mod of Adafruit_NeoPixel.h.

It still works fine if I use Arduino 1.5.6-r2, but I need the newer version of the IDe.

Anyone experience this and have a solution?
The Tolson mod is only for 1.5.6-r2.
No library needed. Especially for just 1 pixel.
Try this and adapt it to your needs.

Code: [Select]
// WS2812_RFduino_Test
// By Thomas Olson
// teo20140220.01
// teo20140719.01 Modified for Arduino 1.5.7
// 20141022.. verified works with Arduino 1.5.8
// No complicated Pixel Library needed.
// Tested with WS2812B 4 pin versions.

int ws2812pin = 2; // WS2812B bus is pin 2

const int nPIXELS = 1; // The dongle has 1 WS2812B

const int nLEDs = nPIXELS * 3;
uint8_t ledBar[nLEDs];


void setup() {

  pinMode(ws2812pin, OUTPUT);
  digitalWrite(ws2812pin, LOW);
  // Initialize the ledBar array - all LEDs OFF.
  // W.C. clear 60 pixels
//  nLEDs = 180;
 
  for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    ledBar[wsOut] = 0x00;
  }
  loadWS2812();
 
  delay(1);
}

void loop() {

//  timetest0s();   
  chaser();
 
}

void timetest0s(void){
 for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    ledBar[wsOut] = 0x00;
  }
  loadWS2812();
}

void timetest1s(void){
 for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    ledBar[wsOut] = 0xFF;
  }
  loadWS2812();
}


void chaser(void){
   
 for(int wsOut = 0; wsOut < nLEDs; wsOut+=3){ // green
    ledBar[wsOut] = 0x3c;
    loadWS2812();
   
    delay(10 * 60/nPIXELS);
   
    ledBar[wsOut] = 0x00;
    loadWS2812();
  }

  delay(10 * 60/nPIXELS);
 
 for(int wsOut = 1; wsOut < nLEDs; wsOut+=3){ // red
    ledBar[wsOut] = 0x3c;
    loadWS2812();
   
    delay(10 * 60/nPIXELS);
   
    ledBar[wsOut] = 0x00;
    loadWS2812();
  }
 
  delay(10 * 60/nPIXELS);
 
   for(int wsOut = 2; wsOut < nLEDs; wsOut+=3){ // blue
    ledBar[wsOut] = 0x3c;
    loadWS2812();
   
    delay(10 * 60/nPIXELS);
   
    ledBar[wsOut] = 0x00;
    loadWS2812();
  }

  delay(10 * 60/nPIXELS);
 
}

void loadWS2812(){
 
  noInterrupts();

  for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    for(int x=7; x>=0; x--){
      NRF_GPIO->OUTSET = (1UL << ws2812pin);
      if(ledBar[wsOut] & (0x01 << x)) {
        __ASM ( \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              );
        NRF_GPIO->OUTCLR = (1UL << ws2812pin);
     
      }else{
        NRF_GPIO->OUTCLR = (1UL << ws2812pin);
        __ASM ( \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              );     
      }
    }
  }
  delayMicroseconds(50); // latch and reset WS2812.
  interrupts(); 
}
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: lemonade on December 22, 2014, 04:16:17 PM
Great!  Thank you.  I modified your sketch a bit to accommodate a fading animation.  I've included it here in case anyone is interested.

I hope this will also solve timing issues that were forcing the BLE radio to time out when connected to an iOS app.  I had to make heavy use of while(RFduinoBLE.radioActive) when using the Adafruit library.

Code: [Select]
//PAIRING
const uint8_t amb_PR[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
const uint8_t amb_PG[] = { 255, 255, 255, 254, 254, 253, 253, 252, 251, 250, 249, 248, 247, 246, 244, 243, 241, 240, 238, 236,
                           234, 232, 230, 228, 226, 223, 221, 218, 216, 213, 210, 207, 204, 201, 198, 194, 191, 187, 184, 180,
                           176, 173, 169, 164, 160, 156, 152, 147, 143, 138, 133, 129, 124, 119, 114, 108, 103, 98, 92, 87, 81,
                           75, 69, 64, 57, 51, 45, 39, 32, 26, 19, 13, 6, 0, 6, 12, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 78,
                           84, 89, 94, 100, 105, 110, 115, 120, 124, 129, 134, 138, 143, 147, 151, 156, 160, 164, 168, 171, 175,
                           179, 182, 186, 189, 193, 196, 199, 202, 205, 208, 211, 214, 216, 219, 221, 224, 226, 228, 230, 232,
                           234, 236, 238, 239, 241, 243, 244, 245, 247, 248, 249, 250, 251, 252, 252, 253, 253, 254, 254, 255,
                           255, 255, 255 };
const uint8_t amb_PB[] = { 255, 255, 255, 254, 254, 253, 253, 252, 251, 250, 249, 248, 247, 246, 244, 243, 241, 240, 238, 236,
                           234, 232, 230, 228, 226, 223, 221, 218, 216, 213, 210, 207, 204, 201, 198, 194, 191, 187, 184, 180,
                           176, 173, 169, 164, 160, 156, 152, 147, 143, 138, 133, 129, 124, 119, 114, 108, 103, 98, 92, 87, 81,
                           75, 69, 64, 57, 51, 45, 39, 32, 26, 19, 13, 6, 0, 6, 12, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 78,
                           84, 89, 94, 100, 105, 110, 115, 120, 124, 129, 134, 138, 143, 147, 151, 156, 160, 164, 168, 171, 175,
                           179, 182, 186, 189, 193, 196, 199, 202, 205, 208, 211, 214, 216, 219, 221, 224, 226, 228, 230, 232,
                           234, 236, 238, 239, 241, 243, 244, 245, 247, 248, 249, 250, 251, 252, 252, 253, 253, 254, 254, 255,
                           255, 255, 255 };

//LED lighitng
uint8_t REDS[255];
uint8_t GREENS[255];
uint8_t BLUES[255];
uint8_t TABLE_SIZE;
uint16_t UPDATE;

uint8_t red;
uint8_t green;
uint8_t blue;

//STATES
const int OFF = 0; 
uint8_t state = OFF;

//TIMING
const int AMBIENT_PAIRING_TABLE_SIZE = (sizeof(amb_PR));
const int AMBIENT_PAIRING_CYCLE    = 5067;
const int AMBIENT_PAIRING_UPDATE    = (AMBIENT_PAIRING_CYCLE / AMBIENT_PAIRING_TABLE_SIZE);

//ANIMATION VARIABLES
uint32_t lastUpdate = 0;
uint8_t animIndex = 0;

//WS2812
int ws2812pin = 2; // WS2812B bus is pin 2
const int nPIXELS = 2; // The dongle has 1 WS2812B
const int nLEDs = nPIXELS * 3;
uint8_t ledBar[nLEDs];


void setup()
{
  pinMode(ws2812pin, OUTPUT);
  digitalWrite(ws2812pin, LOW);
  // Initialize the ledBar array - all LEDs OFF.
  // W.C. clear 60 pixels
//  nLEDs = 180;
 
  for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    ledBar[wsOut] = 0x00;
  }
  loadWS2812();
 
  //SETUP ANIMATION TABLES AND INFO
  TABLE_SIZE = AMBIENT_PAIRING_TABLE_SIZE;
  UPDATE = AMBIENT_PAIRING_UPDATE;
 
  REDS[TABLE_SIZE] = {}; 
  memcpy( REDS, amb_PR, TABLE_SIZE );
 
  GREENS[TABLE_SIZE] = {}; 
  memcpy( GREENS, amb_PG, TABLE_SIZE );
 
  BLUES[TABLE_SIZE] = {}; 
  memcpy( BLUES, amb_PB, TABLE_SIZE );
 
  delay(1);
}

void loop()
{
  //timetest0s();   
  //chaser();
  animate();
}

void animate()
{
  int i;
 
  if ((millis() - lastUpdate) > UPDATE)
  {
    lastUpdate = millis();

    //WS2812
    for (i = 0; i < nLEDs; i++)
    {
      red = (127 * REDS[animIndex]) / 256;
      green = (127 * GREENS[animIndex]) / 256;
      blue = (127 * BLUES[animIndex]) / 256;
     
      for(int wsOut = 0; wsOut < nLEDs; wsOut+=3)
      {
        ledBar[wsOut] = green;
        ledBar[wsOut+1] = red;
        ledBar[wsOut+2] = blue;
      }
    }
   
    loadWS2812();
     
    animIndex++;
    if (animIndex >= TABLE_SIZE)
    {
      animIndex = 0;
    }
  }
}

void timetest0s(void){
 for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    ledBar[wsOut] = 0x00;
  }
  loadWS2812();
}

void timetest1s(void){
 for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    ledBar[wsOut] = 0xFF;
  }
  loadWS2812();
}


void chaser(void){
 for(int wsOut = 0; wsOut < nLEDs; wsOut+=3){ // red
    ledBar[wsOut] = 0;
    ledBar[wsOut+1] = 255;
    ledBar[wsOut+2] = 0;
    loadWS2812();
   
    delay(10 * 60/nPIXELS);
   
    ledBar[wsOut] = 0;
    ledBar[wsOut+1] = 0;
    ledBar[wsOut+2] = 0;
    loadWS2812();
  }

  delay(10 * 60/nPIXELS);
 
 for(int wsOut = 0; wsOut < nLEDs; wsOut+=3){ // green
    ledBar[wsOut] = 255;
    ledBar[wsOut+1] = 0;
    ledBar[wsOut+2] = 0;
    loadWS2812();
   
    delay(10 * 60/nPIXELS);
   
    ledBar[wsOut] = 0;
    ledBar[wsOut+1] = 0;
    ledBar[wsOut+2] = 0;
    loadWS2812();
  }
 
  delay(10 * 60/nPIXELS);
 
  for(int wsOut = 0; wsOut < nLEDs; wsOut+=3){ // blue
    ledBar[wsOut] = 0;
    ledBar[wsOut+1] = 0;
    ledBar[wsOut+2] = 255;
    loadWS2812();
   
    delay(10 * 60/nPIXELS);
   
    ledBar[wsOut] = 0;
    ledBar[wsOut+1] = 0;
    ledBar[wsOut+2] = 0;
    loadWS2812();
  }

  delay(10 * 60/nPIXELS);
 
}

void loadWS2812(){
 
  noInterrupts();

  for(int wsOut = 0; wsOut < nLEDs; wsOut++){
    for(int x=7; x>=0; x--){
      NRF_GPIO->OUTSET = (1UL << ws2812pin);
      if(ledBar[wsOut] & (0x01 << x)) {
        __ASM ( \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              );
        NRF_GPIO->OUTCLR = (1UL << ws2812pin);
     
      }else{
        NRF_GPIO->OUTCLR = (1UL << ws2812pin);
        __ASM ( \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              );     
      }
    }
  }
  delayMicroseconds(50); // latch and reset WS2812.
  interrupts(); 
}
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: cromas on January 09, 2015, 01:07:02 PM
No library needed. Especially for just 1 pixel.
Try this and adapt it to your needs.

Thank you thank you thank you! This is so fantastic, and way better than the huge, LGPL-chained Adafruit library. This worked on the first try for me (w/ Arudino 1.5.8 + RFDuino 2.2.2). That happens approximately NEVER in engineering. I am so pleased! :D
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: cromas on January 09, 2015, 05:28:57 PM
Code: [Select]
    for(int x=7; x>=0; x--){
      NRF_GPIO->OUTSET = (1UL << ws2812pin);
      if(ledBar[wsOut] & (0x01 << x)) {
        __ASM ( \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              );
        NRF_GPIO->OUTCLR = (1UL << ws2812pin);
     
      }else{
        NRF_GPIO->OUTCLR = (1UL << ws2812pin);
        __ASM ( \
              " NOP\n\t" \
              " NOP\n\t" \
              " NOP\n\t" \
              );     
      }
    }

I'm seeing behavior where a sequence flashing (255,0,0)->delay(4656µs)->(0,0,0)->delay(4656µs) is coming out with uneven timing -- every sixth (I think) red flash is ~2x longer than it should be. I've eliminated all other possibilities from my code:

So I'm down to wondering if the serial protocol is occasionally failing to update and thus the LED is "sticking" on for a cycle.

Could you help me understand what's going on in the code here? I'm assuming the NOPs here are for the µs-critical timing for the serial waveform. But I'm confused why you're setting the pin high before you check if the next bit is high. And I'd like to understand how you determined 5 NOPs and 3 NOPs to be appropriate, especially because the duty cycle is supposed to be different between a 1 and a 0.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on January 09, 2015, 05:46:47 PM
The whole routine is involved in the critical timing. Setting the pin high before testing is because it has to be set high anyways and it is a way to get a head start on it while the test is happening to decide when to set it low. It also depends on how the compiler creates assembler. Changing optimizations flags on the compiler will also affect the timing. The subroutine works with the default RFduino compiler settings.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: cromas on January 09, 2015, 06:00:04 PM
The whole routine is involved in the critical timing. Setting the pin high before testing is because it has to be set high anyways and it is a way to get a head start on it while the test is happening to decide when to set it low. It also depends on how the compiler creates assembler. Changing optimizations flags on the compiler will also affect the timing. The subroutine works with the default RFduino compiler settings.

It seems then that we ought to remove the compiler from the equation and put the whole routine into assembly. I believe the guide at http://www.instructables.com/id/Bitbanging-step-by-step-Arduino-control-of-WS2811-/ covers this pretty well (just found it). I'm going to work on it a little and see if I can get it working exactly, because I think I've exhausted other potential locations of the problem (see my edit on my last reply). However, I'm not very familiar with pins/ports and assembly yet, so please let me know if you have any advice on this or think the code there isn't portable for some reason.

EDIT: nevermind, this is a Cortex M0, which (please correct me if I'm wrong) is an entirely different instruction set. My understanding then is that this article can be applied to RFDuino, but the assembly code will be totally different.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: cromas on January 09, 2015, 06:33:56 PM
Also, while I agree that the routine works until a certain threshold, I have the strong suspicion that it's "only just" working and that the tolerances may need to be improved for the speed I'm updating at. 215 updates/sec should be well-within the capabilities of the board and LED controller.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on January 09, 2015, 08:15:38 PM
Right, this is an ARM. The ideal situation would be to do the whole routine in assembly. The routine also has limitations based on if you are using the radio. Even though the routine is wrapped in no-interrupts the nRF51822 radio has priority even over that. There are other tricks to play when the radio is active.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: cromas on January 09, 2015, 09:43:23 PM
I attached a digital logic analyzer @ 24MHz (i.e. sampling rate of 41.666ns), transferred 0xFF 0x00 0x00, here were the results.

(https://dlnmh9ip6v2uc.cloudfront.net/r/400-400/assets/b/a/2/9/c/51f04d33ce395f687c000001.png)

T0H: 0.500µs. Extreme tolerance of spec (350ns ± 150ns)
T0L: 0.937µs. Inconclusive whether this is in-spec (800ns ± 150ns) or not, but if it is, it's extremely close. (This one fell on the edge of my sampler, so the results alternated between 0.9583µs and 0.9167µs; I took the average)

T1H: 0.6666µs -- this is probably actually 0.6250µs (aka 10 16MHz cycles). Easily in-spec (700ns ± 150ns)
T1L: 0.9583µs. Out-of-spec by 208.3ns (600ns ± 150ns)


I'm quite rusty in assembly and a complete newcomer to ARM. tolson, is there anything we can do with the existing code to get this in-spec?
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: cromas on January 10, 2015, 12:55:41 PM
I suppose it's possible that the issue here is not a protocol issue but a higher-level timing issue. The pattern I'm using is 21.2Hz for the whole pattern, with ten segments within the pattern, so I'm sending 212 updates/second. I was under the impression that this was well within the performance range of the WS2812, but perhaps I am mistaken. Or perhaps the issue is that I'm updating "mid-cycle" somehow for the WS2812, and I need to find a way to align my updates to avoid the behavior I'm seeing.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: cromas on January 10, 2015, 09:57:53 PM
If you're thinking about doing anything with WS2811, WS2812, WS2812B, NeoPixel, etc., this is a must-read:

https://cpldcpu.wordpress.com/2014/01/14/light_ws2812-library-v2-0-part-i-understanding-the-ws2812/
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on January 11, 2015, 03:20:53 PM
I attached a digital logic analyzer @ 24MHz (i.e. sampling rate of 41.666ns), transferred 0xFF 0x00 0x00, here were the results.

(https://dlnmh9ip6v2uc.cloudfront.net/r/400-400/assets/b/a/2/9/c/51f04d33ce395f687c000001.png)

T0H: 0.500µs. Extreme tolerance of spec (350ns ± 150ns)
T0L: 0.937µs. Inconclusive whether this is in-spec (800ns ± 150ns) or not, but if it is, it's extremely close. (This one fell on the edge of my sampler, so the results alternated between 0.9583µs and 0.9167µs; I took the average)

T1H: 0.6666µs -- this is probably actually 0.6250µs (aka 10 16MHz cycles). Easily in-spec (700ns ± 150ns)
T1L: 0.9583µs. Out-of-spec by 208.3ns (600ns ± 150ns)


I'm quite rusty in assembly and a complete newcomer to ARM. tolson, is there anything we can do with the existing code to get this in-spec?

The waveform and specification you are using are for the WS2812 and are tight. The WS2812B is different.
You can manipulate the number and positions of the NOPs to get it to work with your setup and/or convert more of the subroutine to assembler.  For the WS2812B the T1L measured is even more so out of spec, while the others are OK.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on February 21, 2015, 03:43:31 PM
I'm adding a new twist to the digital RGB LED strip issues. I finally got around to playing with the APA104 clone of the WS2812B. According to the Chinese timing specs for the APA104 the timing should be way off compared to either the WS2812 or WS2812B. But, I found that it works fine with my loadWS2812B() subroutine. What's up with that?! I don't know. But here is the video of it working...


http://www.youtube.com/v/DoEngksCe5w/

I am having an issue with the APA104 strip though, in that upon applying power, all LEDs come on BLUE. To test if is was a timing issue like the WS2812(B) had earlier, I grounded the Data IN pin to the LED strip and cycled the power on and off. The BLUEs all come on. Hmm! So it is important to send zeros out to all the LEDs in the array as soon as possible during power on bootup. Anybody else seeing this with the APA104 LEDs?

http://www.youtube.com/v/gNNepE1uvBY/


Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: cromas on February 21, 2015, 04:24:15 PM
tolson yes the blue-on-power is in the spec, somewhere. "By design."

The wordpress link I posted before explains much of how the protocol actually works. The LEDs have a 400 or 800 Khz internal oscillator. The weird protocol essentially comes down to latching bits after some multiple of cycles.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on February 21, 2015, 05:06:06 PM
Yep, I know how they work. If you come across where the BLUE is suppose comes on "by design" please forward the reference. I suspect it is more like "oops". Does the "by design" spec say at what PWM level they come on at. Could really play badly with a power supply not expecting to run all the LEDs at the same time.

Thanks
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: cromas on February 21, 2015, 05:19:55 PM
I will definitely send it if I can find it, but it's only a vague recollection. I'm sure you know there are more than a few poorly-translated "data sheets" for these, each claiming different timing specs. I could be mis-remembering some other forum post about them being blue on power-on, but I feel like I did see it at least described in one of those sheets. Maybe not "design" but at least "expected". But I hear you on the power-up concerns.

You might try contacting Daniel Garcia of FastLED fame. He knows these better than just about anyone I've spoken with. He might know.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: randymgn on May 24, 2015, 08:55:18 AM
APA104 (http://www.ledlightinghut.com/apa104-digital-intelligent-rgb-led-strip.html) have the same shape as ws2812b,ws2811, can be compatible as ws2812b,ws2811, can be use same control with ws2812b". So mainly, APA104 are for maintaining compatibility with older strips while the APA102 (http://www.ledlightinghut.com/apa102-digital-led-strip-144-led-per-meter.html) are not.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: SamDecrock on September 08, 2015, 09:08:50 AM
Hi,

I updated Thomas Olson's code so that it resembles the NeoPixel API but without using the actual NeoPixel library. It works on RFDuino using the latest Arduino IDE (Arduino 1.6.5):

https://gist.github.com/SamDecrock/80e30c9bae734858d50d


Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: bikemule on September 08, 2015, 01:34:38 PM
I got the gist above working with 400Mhz WS2812Bs by doubling the NOPs, but if I call RFduinoBLE.begin() any time before, I only get 0-5 LEDs lit.
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: digitalledcolor1 on June 10, 2016, 02:02:06 AM
I'm adding a new twist to the digital RGB LED strip issues. I finally got around to playing with the APA104 clone of the WS2812B. According to the Chinese timing specs for the APA104 the timing should be way off compared to either the WS2812 or WS2812B. But, I found that it works fine with my loadWS2812B() subroutine. What's up with that?! I don't know. But here is the video of it working...


http://www.youtube.com/v/DoEngksCe5w/

I am having an issue with the APA104 strip though, in that upon applying power, all LEDs come on BLUE. To test if is was a timing issue like the WS2812(B) had earlier, I grounded the Data IN pin to the LED strip and cycled the power on and off. The BLUEs all come on. Hmm! So it is important to send zeros out to all the LEDs in the array as soon as possible during power on bootup. Anybody else seeing this with the APA104 LEDs?

http://www.youtube.com/v/gNNepE1uvBY/
   APA104 have based color ,when you power them without signal ,it turn on blue , and when it start ,it also have blue color ,but it is fast, normally if you don't pay attention , you will not see it , and ws2812b and WS2813 led (http://www.szledcolor.com/productshow.asp?id=965&sid=199) Will not have this situation .
Title: Re: Digital rgb ledstrip driven by RFDuino
Post by: tolson on June 24, 2016, 10:36:28 AM
  APA104 have based color ,when you power them without signal ,it turn on blue , and when it start ,it also have blue color ,but it is fast, normally if you don't pay attention , you will not see it , and ws2812b and WS2813 led (http://www.szledcolor.com/productshow.asp?id=965&sid=199) Will not have this situation .

Experiment show that if you don't pay attention they stay on forever. You have to intentionally programatically turn them off as soon as possible in your program. If you do not, they never  go out. Not good for a power supply not expecting to supply maximum power for entire chain.