ESP32 and NeoPixel don't work

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
sanyafifa1
Normal user
Posts: 3
Joined: 18 Jan 2020, 17:51

ESP32 and NeoPixel don't work

#1 Post by sanyafifa1 » 29 Aug 2020, 22:11

Hello. Thanks for a great project.

I connect WS2812 to ESP-WROOM-32 board with ESP_Easy_mega_20200829_test_ESP32_4M316k firmware
And it doesn't give any result. I also tried with other firmwares.
When I connect these LEDs to the NodeMcu board everything is ok.

I ask for help, thanks
photo_2020-08-29_22-59-58.jpg
photo_2020-08-29_22-59-58.jpg (101.81 KiB) Viewed 15772 times
photo_2020-08-29_23-00-08.jpg
photo_2020-08-29_23-00-08.jpg (243.75 KiB) Viewed 15772 times
Wire connection
Wire connection
photo_2020-08-29_23-00-17.jpg (92.02 KiB) Viewed 15772 times

TD-er
Core team member
Posts: 5506
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 and NeoPixel don't work

#2 Post by TD-er » 29 Aug 2020, 22:33

Just to be sure, measure the voltage on the 5V pin of that board.
Not saying the NeoPixel will work on ESP32 as I have never tested it myself.
But those ESP32 NodeMCU like boards do have some issues with the voltage regulators.

sanyafifa1
Normal user
Posts: 3
Joined: 18 Jan 2020, 17:51

Re: ESP32 and NeoPixel don't work

#3 Post by sanyafifa1 » 30 Aug 2020, 14:22

Just to be sure, measure the voltage on the 5V pin of that board.
yes, the voltage on the neopixel is 5.05 volts.

Perhaps this board needs a different specific pin?
Who can test for themselves, please

martinus
Normal user
Posts: 115
Joined: 15 Feb 2020, 16:57

Re: ESP32 and NeoPixel don't work

#4 Post by martinus » 02 Sep 2020, 15:34

I tried this a while ago on M5Stack modules (ESP32). If i remember correctly, it didn't work properly using Adafruit library. The FastLED worked but it was not so easy to implement in ESP Easy with runtime configurable pin selection.
I also found a small library that was specifically build for ESP32 and uses some hardware components from the MCU to control the Neopixels.
I'm currently using it on M5Stack Atom modules.

sanyafifa1
Normal user
Posts: 3
Joined: 18 Jan 2020, 17:51

Re: ESP32 and NeoPixel don't work

#5 Post by sanyafifa1 » 02 Sep 2020, 15:42

martinus wrote: 02 Sep 2020, 15:34 I tried this a while ago on M5Stack modules (ESP32). If i remember correctly, it didn't work properly using Adafruit library. The FastLED worked but it was not so easy to implement in ESP Easy with runtime configurable pin selection.
I also found a small library that was specifically build for ESP32 and uses some hardware components from the MCU to control the Neopixels.
I'm currently using it on M5Stack Atom modules.
Thanks for the answer.
Can you tell me how to use FastLED in Espeasy?

martinus
Normal user
Posts: 115
Joined: 15 Feb 2020, 16:57

Re: ESP32 and NeoPixel don't work

#6 Post by martinus » 07 Sep 2020, 13:17

As said not so easy because it uses a specific template for each pin to be defined.

I was working on a demo/test plugin to verify 3 different drivers options:

Code: Select all

#ifdef USES_P038
//#######################################################################################################
//#################################### Plugin 038: NeoPixel Basic #######################################
//#######################################################################################################

// List of commands:
// NeoPixel <led nr>, <red 0-255>, <green 0-255>, <blue 0-255>
// NeoPixelRange <start led nr>, <end led nr>, <red 0-255>, <green 0-255>, <blue 0-255>
// NeoPixelAll <red 0-255>, <green 0-255>, <blue 0-255>

#if defined(ESP8266)
  #define USE_ADAFRUIT
#endif
//#define USE_FASTLED
#if defined(ESP32)
  #define USE_ESP32RMTNEO
#endif

#ifdef USE_ADAFRUIT
  #include <Adafruit_NeoPixel.h>
  Adafruit_NeoPixel *Plugin_038_pixels;
#endif
#ifdef USE_FASTLED
  #include <FastLED.h>
  CRGB leds[25];
#endif
#ifdef USE_ESP32RMTNEO
  // lib from: https://github.com/MartyMacGyver/ESP32-Digital-RGB-LED-Drivers
  #include "esp32_digital_led_lib.h"
  // Create strand struct with default settings
  strand_t strand = {.rmtChannel = 0, .gpioNum = 27, .ledType = LED_WS2812B_V1, .brightLimit = 20, .numPixels = 25};
  // Create pointer array to strand object (we use only one)
  strand_t * STRANDS [] = { &strand };
#endif

#define PLUGIN_038
#define PLUGIN_ID_038         38
#define PLUGIN_NAME_038       "Output - NeoPixel (Basic)"
#define PLUGIN_VALUENAME1_038 ""

int P038_ledCount = 25;
boolean P038_Init = false;
#if defined(ESP8266)
  byte P038_driver = 1;
#endif
#if defined(ESP32)
  byte P038_driver = 3;
#endif

boolean Plugin_038(byte function, struct EventStruct *event, String& string)
{
  boolean success = false;

  switch (function)
  {

    case PLUGIN_DEVICE_ADD:
      {
        Device[++deviceCount].Number = PLUGIN_ID_038;
        Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
        Device[deviceCount].Custom = true;
        Device[deviceCount].TimerOption = false;
        break;
      }

    case PLUGIN_GET_DEVICENAME:
      {
        string = F(PLUGIN_NAME_038);
        break;
      }

    case PLUGIN_GET_DEVICEVALUENAMES:
      {
        strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_038));
        break;
      }

    case PLUGIN_WEBFORM_LOAD:
      {
      	addFormNumericBox(F("Led Count"), F("p038_leds"), PCONFIG(0),1,999);
      	addFormPinSelect(F("GPIO"), F("taskdevicepin1"), CONFIG_PIN1);
        addFormNumericBox(F("Driver"), F("p038_driver"), PCONFIG(7),1,3);
      	success = true;
        break;
      }

    case PLUGIN_WEBFORM_SAVE:
      {
        PCONFIG(0) = getFormItemInt(F("p038_leds"));
        PCONFIG(7) = getFormItemInt(F("p038_driver"));
        success = true;
        break;
      }

    case PLUGIN_INIT:
      {
        if(!P038_Init)
        {
          P038_Boot(PCONFIG(7), CONFIG_PIN1, PCONFIG(0), 25);
        }
        success = true;
        break;
      }

    case PLUGIN_WRITE:
      {
        if(P038_Init)
        {
          String cmd = parseString(string, 1);

          if (cmd.equalsIgnoreCase(F("NeoPixelClear")))
          {
            #ifdef USE_ADAFRUIT
              Plugin_038_pixels->clear();
              Plugin_038_pixels->show();
            #endif
            success = true;
          }

          if (cmd.equalsIgnoreCase(F("NeoPixel")))
          {
            P038_pixel(event->Par1-1, event->Par2, event->Par3, event->Par4);
            success = true;
          }

          if (cmd.equalsIgnoreCase(F("NeoPixelAll")))
				  {
            P038_pixelRange(0, P038_ledCount-1, event->Par1, event->Par2, event->Par3);
					  success = true;
          }

          if (cmd.equalsIgnoreCase(F("NeoPixelRange")))
          {
            P038_pixelRange(event->Par1-1, event->Par2-1, event->Par3, event->Par4, event->Par5);
            success = true;
          }

          if (cmd.equalsIgnoreCase(F("NeoPixelTest")))
          {
            for (int i = 0; i < P038_ledCount; i++)
            {
              P038_pixel(i, 0,0,80);
              delay(50);
              P038_pixel(i, 0,0,0);
              delay(50);
            }
            success = true;
          }
          
        }
        break;
      }

  }
  return success;
}


void P038_Boot(byte driver, byte pin, int ledCount, byte brightness){

  if(P038_Init)
    return;

  P038_Init = true;
  P038_driver = driver;
  P038_ledCount = ledCount;

  pinMode(pin,OUTPUT);

  switch(P038_driver){
            
    case 1:
      #ifdef USE_ADAFRUIT
        Plugin_038_pixels = new Adafruit_NeoPixel(P038_ledCount, pin, NEO_GRB + NEO_KHZ800);
        Plugin_038_pixels->begin();
        P038_pixelRange(0, 4, 25, 25, 25);
      #endif
      break;
                
    case 2:
      #ifdef USE_FASTLED
        if(pin == 16)
          FastLED.addLeds<NEOPIXEL, 16>(leds, P038_ledCount); // Wemos D1 Mini
        if(pin == 26)
          FastLED.addLeds<NEOPIXEL, 26>(leds, P038_ledCount); // NEOPIXEL module on grove for M5-Atom
        if(pin == 27)
          FastLED.addLeds<NEOPIXEL, 27>(leds, P038_ledCount); // Built-in ATOM NEOPIXEL
        if(pin == 32)
          FastLED.addLeds<NEOPIXEL, 32>(leds, P038_ledCount); // NEOPIXEL module on grove for M5-StickC
        FastLED.setBrightness(50);
        P038_pixelRange(0, 4, 25, 25, 25);
      #endif
      break;

    case 3:
      #ifdef USE_ESP32RMTNEO
        strand.gpioNum = pin;
        strand.numPixels = P038_ledCount;
        digitalLeds_initDriver();
        gpioSetup(strand.gpioNum, OUTPUT, LOW);
        digitalLeds_addStrands(STRANDS, 1);
        digitalLeds_resetPixels(STRANDS, 1);
        delay(500);
        P038_pixelRange(0, 4, 25, 25, 25);
      #endif
      break;

  }
}


void P038_Show(){

  switch(P038_driver){
    case 1:
      #ifdef USE_ADAFRUIT
        if(Plugin_038_pixels){
          Plugin_038_pixels->show();
        }
      #endif
      break;
      
    case 2:
      #ifdef USE_FASTLED
        FastLED.show();
      #endif
      break;

    case 3:
      #ifdef USE_ESP32RMTNEO
        digitalLeds_drawPixels(STRANDS, 1);
        delay(1); // mvdbro todo bug ? wordclock resettoback/write does not seem to work without this
      #endif
      break;
  }
}

void P038_pixelRange(byte start, byte end, byte red, byte green , byte blue){
  for (int i = start; i <= end; i++)
    P038_pixel(i,red,green,blue,false);
  P038_Show();
}


void P038_pixel(byte led, byte red, byte green , byte blue){
  P038_pixel(led, red, green , blue, true);
}

void P038_pixel(byte led, byte red, byte green , byte blue, boolean update){

  if(led >= P038_ledCount) // do not allow write outside allocated buffer!
    return;
    
  switch(P038_driver){
    case 1:
      #ifdef USE_ADAFRUIT
        if(Plugin_038_pixels){
        Plugin_038_pixels->setPixelColor(led, Plugin_038_pixels->Color(red,green,blue));
      }
      #endif
      break;

    case 2:
      #ifdef USE_FASTLED
        leds[led].r = red;
        leds[led].g = green;
        leds[led].b = blue;
      #endif
      break;

    case 3:
      #ifdef USE_ESP32RMTNEO
        strand.pixels[led] = pixelFromRGB(red, green, blue);
      #endif
      break;
    
  }

  if(update)
    P038_Show();
}

#endif // USES_P038
This is the part that needs some work. Maybe not even possible with the stock library. I'm not familiar with templates in C:

if(pin == 16)
FastLED.addLeds<NEOPIXEL, 16>(leds, P038_ledCount); // Wemos D1 Mini
if(pin == 26)
FastLED.addLeds<NEOPIXEL, 26>(leds, P038_ledCount); // NEOPIXEL module on grove for M5-Atom
if(pin == 27)
FastLED.addLeds<NEOPIXEL, 27>(leds, P038_ledCount); // Built-in ATOM NEOPIXEL
if(pin == 32)
FastLED.addLeds<NEOPIXEL, 32>(leds, P038_ledCount); // NEOPIXEL module on grove for M5-StickC

TD-er
Core team member
Posts: 5506
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 and NeoPixel don't work

#7 Post by TD-er » 07 Sep 2020, 15:07

Just keep in mind that using templates like that, you effectively create a new object (or function) definition, which also needs to be compiled.
Thus every combination of different template variables will increase the build size (and build time).

So if you do know the parameters at compile time, then it makes sense to only have the needed one compiled.

martinus
Normal user
Posts: 115
Joined: 15 Feb 2020, 16:57

Re: ESP32 and NeoPixel don't work

#8 Post by martinus » 08 Sep 2020, 12:54

TD-er wrote: 07 Sep 2020, 15:07 Just keep in mind that using templates like that, you effectively create a new object (or function) definition, which also needs to be compiled.
Thus every combination of different template variables will increase the build size (and build time).

So if you do know the parameters at compile time, then it makes sense to only have the needed one compiled.
For these reasons, i ended up using only the ESP32 RMT specific library on ESP32 modules. Compile time hardcoded pin numbers are so against ESP Easy design...

TD-er
Core team member
Posts: 5506
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 and NeoPixel don't work

#9 Post by TD-er » 08 Sep 2020, 13:34

martinus wrote: 08 Sep 2020, 12:54 [...]
Compile time hardcoded pin numbers are so against ESP Easy design...
Totally agree.
But I thought I just mention it as you stated not to have a lot of experience with template design in C++.

kimot
Normal user
Posts: 184
Joined: 12 Oct 2017, 20:46

Re: ESP32 and NeoPixel don't work

#10 Post by kimot » 03 Dec 2020, 21:12

sanyafifa1 wrote: 30 Aug 2020, 14:22
Just to be sure, measure the voltage on the 5V pin of that board.
yes, the voltage on the neopixel is 5.05 volts.

Perhaps this board needs a different specific pin?
Who can test for themselves, please
Neopixel spec:
Min datapin input voltage for high level = 0.7Vdd = 0,7*5 = 3,5V
How do you reach 3,5V with 3,3V I/O of ESP32?

Yes, Internet is full of these diagrams with direct connection Neopixel and ESP32 or ESP8266.
Sometimes it works, sometimes no.
It is random.
Use level shifter....

grundy
Normal user
Posts: 6
Joined: 01 Jul 2019, 22:08

Re: ESP32 and NeoPixel don't work

#11 Post by grundy » 09 Apr 2021, 23:28

any news about this case? i tried the latest version on an esp32 and still no output no matter wich io pin i try ( checked with scope, pins stay low even with 10k pull up).

Fab
Normal user
Posts: 6
Joined: 03 Dec 2020, 17:29
Location: Germany
Contact:

Re: ESP32 and NeoPixel don't work

#12 Post by Fab » 11 Apr 2021, 19:10

Hey guys,
I'm interested in that as well. Actually I'm trying to make my pxlBlck-plugin running again which uses the neomatrix/neopixel library of adafruit. meanwhile the plugin compiles successfully but it seems that none of the plugins that are based on the neopixel library manages to output any data on the specified GPIO.

I'm very open to investigate this and would be very thankful about any infos how the GPIO "reservation" is handled (or should handled) right now. It looks like the GPIO reservation changed a bit in the last time (regarding the other plugins).
For example some plugins use "savePortStatus()" and "createKey()" functions wich seem to be related with the "portStatusStruct". Some other plugins do not use this kind of GPIO reservation. Could you give me some infos whats the "official intended" way to reserve a GPIO? :)

Also I'm very thankful for any tip where to search first or what changed recently that could be related to this. :)

Best regards
Fab
🧑‍🔧Me: Full time nerd in a world with too many projects for too little time
🌍Nerdiy.de: Detailed HowTos

grundy
Normal user
Posts: 6
Joined: 01 Jul 2019, 22:08

Re: ESP32 and NeoPixel don't work

#13 Post by grundy » 02 Sep 2021, 10:31

still no luck with 20210802, does anyone have more info or a hint what i can do to fix it? im not so deep into programming thats why i use espeasy :roll: everything runs on the 8266 but its a little too slow so i was hoping to get it on the esp32, but after a year it seems the neopixel still dont work. please repair the neopixel function in the esp32 version, ill definetly send more coffees then 8-)

Fab
Normal user
Posts: 6
Joined: 03 Dec 2020, 17:29
Location: Germany
Contact:

Re: ESP32 and NeoPixel don't work

#14 Post by Fab » 19 Sep 2021, 14:15

Hey,
try to upgrade the arduino neopixel library to the latest version. For me this fixed the issue. :)
Hope it helps you too.
Have a nice day
Fab
🧑‍🔧Me: Full time nerd in a world with too many projects for too little time
🌍Nerdiy.de: Detailed HowTos

TD-er
Core team member
Posts: 5506
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32 and NeoPixel don't work

#15 Post by TD-er » 19 Sep 2021, 15:52

Hmm I was doing the same (and it is now merged into the 'mega' branch) for adding support to the ESP32-S2 as the "ESP32-s2-saola" board I have here does have such a LED on it.

So consider this now fixed for ESP32**

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests