Author Topic: NeoPixel library and pin names  (Read 16424 times)

cpetito

  • Newbie
  • *
  • Posts: 22
NeoPixel library and pin names
« on: February 04, 2016, 09:30:32 am »
I've been playing with my new OAK with neopixels and found an interesting issue with pin names using this library: https://github.com/Makuna/NeoPixelBus.  I believe that the Adafruit library will behave the same: https://github.com/adafruit/Adafruit_NeoPixel

The neopixel data line is connected to my OAK on pin 5.

The issue is that the NeoPixelBus library uses pinMode() and digitalWrite() to configure the OAK pin 5 port for output properly, but then requires the ESP8266 GPIO pin 4 to transmit the data on this pin.

My fix was to remove the library port setup and do it in the sketch setup() using the OAK pin name (5) and using the GPIO pin name (4) in the NeoPixelBus constructor.

Comments and/or a better solution will be appreciated.

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: NeoPixel library and pin names
« Reply #1 on: February 04, 2016, 11:27:00 am »
Is the issue related to this statement in the library files...
"Arduino NeoPixel library

ESP8266 CUSTOMERS PLEASE READ: While this branch does work with the esp8266, due to the latest SDK releases it will not function reliably when WiFi is being used. Therefore I suggest you use the DmaDriven or UartDriven branches, which both include solutions that will work with WiFi on. Further they contains enhancements that just can't be supported on AVR platform. Including HslColor object and an enhanced animator manager."

If so, have you tried the other branches?

I have used the Adafruit NeoPixel lib on other other non-wireless platforms. The only wireless one that I've used prior to Oak is the DigiX. If the ESP8266 requires a work around, I would love to see what you have done to make it work as I'm sure other would too.


DeuxVis

  • Full Member
  • ***
  • Posts: 107
Re: NeoPixel library and pin names
« Reply #2 on: February 05, 2016, 06:35:26 am »
I'm not sure if the FastLed library will help there, but they support ESP8266 and neopixels so it might be worth giving it a try : https://github.com/FastLED/FastLED

cpetito

  • Newbie
  • *
  • Posts: 22
Re: NeoPixel library and pin names
« Reply #3 on: February 05, 2016, 09:24:26 am »
I am no expert here. I'm a "jack of all trades and master of none", so weigh the following accordingly.

I found that the neopixel libraries referenced previously set up the control pin with the standard Arduino pinMode() and digitalWrite() functions and using the OAK port numbers work as expected, but that the ESP8266 implementation of the transmit data uses the GPIO port names.

Looking at pins_arduino.h in the OakCore/variants/oak/ repository I found the following mapping comment:

                                                       ///0, 1, 2, 3, 4, 5,   6,    7,  8,   9, 10, 11
//uint8_t esp8266_pinToGpio[12] = {2, 5, 0, 3, 1, 4, 15, 13, 12, 14, 16, 17};

Using this mapping it told me that if I wanted to connect the neopixels to OAK pin 5, the corresponding ESP8266 GPIO designation was 4.

With this information I believe that the following will work without any modification to the libraries,  For example, using the Adafruit library.

Assuming that you are using OAK pin 5 to control the neopixels, call the constructor with the corresponding GPIO port number, 4 (see mapping above):

  Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, 4, NEO_RGB + NEO_KHZ800);

Then in setup() make OAK pin 5 an output and restore OAK pin 4 back to an input if desired:

  pinMode ( 5, OUTPUT );
  digitalWrite ( 5, 0 );


  strip.begin();
 
  pinMode ( 4, INPUT ); //the constructor and begin will set this up as an output, change it back to an input if desired
   
  strip.show(); // Initialize all pixels to 'off'
 
The above changes worked with Adafruit's strandtest example.

And if you are interested in controlling neopixels via WIFI, check out: http://pance.mk/index.php/wifi-light-with-esp8266-and-arduino-code/

Again, comments, corrections and/or a better solution will be appreciated!

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: NeoPixel library and pin names
« Reply #4 on: February 05, 2016, 10:24:42 am »
cpetito,

Thanks for the info. I was poking around trying to understand the issue after your initial post and did see the pin to gpio mapping for ESP8266.

Thanks for the detail. As soon as I get my Oak running, this will be on my list to try.

ajpowell

  • Newbie
  • *
  • Posts: 11
Re: NeoPixel library and pin names
« Reply #5 on: February 06, 2016, 08:00:28 am »
Hi guys,

I was reading this with interest as I had tried to compile the example code that is given in the DigiLED tutorial and upload to one of my Oaks - it would compile, but the DigiiLED wouldn't change - with the additional info that @cppetito had found, I finally got the code working - the DigiLED has the option of working with Oak pin 1 (default) or Oak pin 5 - both options are covered in my updated code here (will update the tutorial shortly): https://github.com/ajpowell/OakSamples

I may refine the code a little - could easily perform the map in an array, so you specify the Oak pin, but it works out the GPIO port in code.

emardee

  • Full Member
  • ***
  • Posts: 135
Re: NeoPixel library and pin names
« Reply #6 on: February 09, 2016, 04:53:22 am »
Great to see some discussions on Digital Pixel LED strips being controlled by OAK via various libraries.

I'm still waiting for my OAKs to arrive, but keen to start reading up on my options ready.

Does anyone know which of these libraries already support RGBW strips? (32bit per pixel instead of 24bit). I figure if my preferred library doesn't already support it, I could hopefully cannibalise it to work alright, but better to start with existing proper supported code if possible by choosing my library carefully at the start! (how do I pick?)

Is anyone here using any of these libraries with the Oak Level shifter shield?

Anyone planning to use any of these libraries with Blynk to get wifi control over the colours, patterns and speeds?

Finding out which libraries are most popular here with OAK users, and will work for my needs (RBGW strip, Blynk & Level Shifter), and being used by others here for similar needs, might help me pick between the libraries, and mean more of us can help each other.

Can't wait to get my Oaks!

Mike

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: NeoPixel library and pin names
« Reply #7 on: February 14, 2016, 11:31:48 am »
Has anyone successfully run the Adafruit NeoPixel strand test on their Oak? Tried but failed. BTW, I was using the Level Shifter 3 pin screw terminal that brings out Pin 5 for DIN, PWR and GND for the strip. Powered the Oak and Level Shifter (at 5v) through the 2 pin screw terminal. In this configuration I was able to run a simple LED flash sketch but not the NeoPixel strand test. I'm using an RGB-123 8 LED RGB strip on a PCB. I've run this successfully on an UNO in the past.

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: NeoPixel library and pin names
« Reply #8 on: February 14, 2016, 07:33:28 pm »
NeoPixel strandtest running successfully (and using the Level Shifter shield)...

Config:
Oak BETA 3 firmware, 0.9.3 package.
Adafruit NeoPixel 1.0.4 lib. Turns out I was running an older version of the lib when I thought it was the latest. Was only made aware of this because the Arduino IDE informs which lib it's using when multiple are found.
Level Shifter and Oak powered through Level Shifter 2 pin screw terminal PWR and GND via a 5V 750mA wall wart.
Connection to RGB LED strip through Level Shifter 3 pin screw terminal 5V - P5 (to DIN) - GND.
An finally the part I don't get, using the workaround posted by cpetito http://digistump.com/board/index.php/topic,1984.msg8888.html#msg8888
I don't get that part, I thought that pins_arduino.h for the Oak variant was suppose to make this transparent.

In any case no brick.

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: NeoPixel library and pin names
« Reply #9 on: February 14, 2016, 08:03:44 pm »
Oh well... Update: I think it's bricked after running for 15 minutes straight. What post had Erik's dump instructions? I would like to verify that it is indeed bricked, dump memory and provide the dump and sketch to digistump.

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: NeoPixel library and pin names
« Reply #10 on: February 14, 2016, 08:17:06 pm »
FALSE ALARM... Cycled power and it started again. Going to look into why it may have stopped.  loop() is forever right? ???

ripred

  • Newbie
  • *
  • Posts: 13
Re: NeoPixel library and pin names
« Reply #11 on: February 14, 2016, 08:32:31 pm »
In theory yes.  Curiously I have an Oak set up to allow controlling two servo motors.  To invoke the change I use curl.  The output I get back includes json that has an item called "connected" which is always either true or false.  Curiously I have noticed that after an hour (or some indeterminate time so far) it starts returning "false" for this item.  The strange thing is that the servos correctly move to the new position I sent so it is obviously connected.  Not sure what this field exactly represents.  Another question I have had is whether you can place the code you have inside loop() { ... } inside a while (1) { ... } clause.  Sometimes this can shave off a few cycles inside the loop by not wasting a constant exit of loop() and consequent wrapping call back into it.  I haven't been brave enough yet to try this yet on an Oak to see  ;)

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: NeoPixel library and pin names
« Reply #12 on: February 14, 2016, 08:48:56 pm »
That's interesting. If you going to use while() inside loop(), why not just put a while() in setup and never leave setup() or enter loop(). Don't know the background but perhaps setup() and loop() in the Arduino world are just there to provide a simple construct for initialization and running code forever.

ripred

  • Newbie
  • *
  • Posts: 13
Re: NeoPixel library and pin names
« Reply #13 on: February 14, 2016, 08:55:00 pm »
Totally agree.  On the semantic level that we all understand setup() and loop() what you suggest works great (and does on original uno's although you need to supply the (declared but undefined) loop() definition even if it's empty).  But am I am curious as things start to become "Arduino compatible" with serious amounts of non-Arduino activity possibly going on in between, whether this will become a frailty in the future due to unknown but required processing that goes on in-between the calls to loop().

« Last Edit: February 14, 2016, 09:06:03 pm by ripred »

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: NeoPixel library and pin names
« Reply #14 on: February 15, 2016, 07:57:13 am »
NeoPixel strantest ran overnight. On to trying the DS18S20 Temperature probe and Particle.variable to for logging on particle.io.