Skip to content

ESP32 + FastLED #504

Closed
Closed

Description

@PhilColbert

Struggling to get this working ?

Have a setup with the 8266 working perfectly.

Using the same code and wiring setup, just the first 2 LED's light up white and the 3rd LED flickers.

Using 72 APA102 LED's and standard ESP32 dev board.

Wired directly to 5V, no level converter as it wasnt needed on the esp8266 board

Any ideas or anyone got this working yet ?

Thanks

Activity

  1. focalintent commented on Sep 27, 2017

    @focalintent
    Contributor

    @samguyer any thoughts for @PhilColbert? I don't have any esp32 based setups here to test with, so I'm mostly relying on sam's pull request :)

  2. samguyer commented on Sep 27, 2017

    @samguyer
    Contributor

    @PhilColbert Which pin are you using? I have found that the ESP32 is very finicky about the pins.

  3. PhilColbert commented on Sep 27, 2017

    @PhilColbert
    Author

    Hi

    Thanks for the reply, tried 13,14 and 25,26 so far....

    Seemingly same result, first 2 leds on white, 3rd flashes....

    Thanks

  4. gnkarn commented on Sep 27, 2017

    @gnkarn

    You should try the level converter first , also in an ESP 8266 before anything else .

  5. PhilColbert commented on Sep 27, 2017

    @PhilColbert
    Author

    Yes, will do :)

    thanks

  6. focalintent commented on Sep 27, 2017

    @focalintent
    Contributor

    Also, as a sanity check - make sure you haven’t gotten clock and data wired backwards (the behavior you’re describing is not dissimilar to what happens when the clock and data lines have been swapped)

  7. PhilColbert commented on Sep 27, 2017

    @PhilColbert
    Author

    :) Tried it both ways.... first thing to check that one, been there done that before several times, with them reversed, nothing comes out.

    Thanks tho, will try Level converter soon first.

  8. samguyer commented on Sep 27, 2017

    @samguyer
    Contributor

    The code that I pushed for the ESP32 is mainly for clockless chips, like the WS2812 family. It was adapted directly from the ESP8266 code, with modifications mainly to handle interrupts. I would not expect to see problems with LEDs that have an explicit clock signal, but I'm pretty new to this stuff (and to hacking FastLED).

  9. samguyer commented on Sep 27, 2017

    @samguyer
    Contributor

    Also: the pins you're using should be fine, but there are so many weird exceptions on this processor. I have gotten things to work reliably on GPIO 18 and 19.

  10. PhilColbert commented on Sep 27, 2017

    @PhilColbert
    Author

    Ok, will give it a try , thanks.

  11. PhilColbert commented on Sep 27, 2017

    @PhilColbert
    Author

    Tried with level converter, works just the same on the 8266 with level converter.

    With the esp32 and a level converter using pins 18 and 19, works exactly the same, first 2 led's are white and then third flickers.
    ( tried switching clock and data line to make sure its correct - no colour the other way )

    Using FastLED version 3.001.006
    "No hardware SPI pins defined. All SPI access will default to bitbanged output"

    Any idea where to start looking for the issue ?

    Thanks

  12. samguyer commented on Sep 27, 2017

    @samguyer
    Contributor

    Do you have another strip, or a different kind of strip you can try?

  13. samguyer commented on Sep 29, 2017

    @samguyer
    Contributor

    OK, I think I've made some improvements to the ESP32 support.
    @focalintent: do you want me submit another pull request?

  14. 218 remaining items

  15. samguyer commented on Aug 10, 2018

    @samguyer
    Contributor

    @HorstBaerbel That is strange. Let me try out your code, and I'll get back to you soon.

  16. samguyer commented on Aug 14, 2018

    @samguyer
    Contributor

    @HorstBaerbel I was not able to reproduce the problem on my setup. Can you tell me about the hardware you're using?

  17. HorstBaerbel commented on Aug 14, 2018

    @HorstBaerbel

    Thanks for trying. I use a WEMOS Lolin32 clone and a 30A 5V power supply. All 18 strips have 5V and GND individually fed in from the strip start. The script ran on an ESP8266 (ModeMCU clone), but it was flickering etc. like hell because of interrupts. I wanted to use WiFi / Websockets, so figured I should try with an ESP32 to get a stable display. I don't use a level converter, but all my other projects (that have less LEDs though and no parallel output) never needed one...
    I have commented out everything except the LED driving code in my script.

    // LED strip setup
    #define CALIBRATION_TEMPERATURE TypicalLEDStrip
    #define MAX_BRIGHTNESS 255 // 0-255
    #define LED_PIN_STRIP1 19 // Define LED data port pin for upper half strip
    #define LED_PIN_STRIP2 23 // Define LED data port pin for lower half strip
    //initialise LED-array
    #define NUM_STRIPS 2 // We have two strips, one for the upper half, one for the lower
    #define NUM_LEDS_WIDTH 30
    #define NUM_LEDS_HEIGHT 18
    #define NUM_LEDS (NUM_LEDS_WIDTH*NUM_LEDS_HEIGHT) // Number of LEDs (my configuration is 30*18=540)
    #define NUM_LEDS_PER_STRIP (NUM_LEDS/NUM_STRIPS) // 30*18/2=270 LEDs per strip
    #define MAX_FRAME_RATE 30 // Maximum 30Hz update rate
    CRGB leds[NUM_LEDS];
    
    void setupLEDs() {
      // clear led color buffer to black
      memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
      // initialize FastLed library for the WS2812B strip
      FastLED.addLeds<WS2812B, LED_PIN_STRIP1, GRB>(leds, 0, NUM_LEDS_PER_STRIP); // first half is at pin 19 and starts at array index 0
      FastLED.addLeds<WS2812B, LED_PIN_STRIP2, GRB>(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP); // second half is at pin 23 and starts at array index 270
      FastLED.setTemperature(CALIBRATION_TEMPERATURE);
      FastLED.setBrightness(MAX_BRIGHTNESS);
      FastLED.setDither(DISABLE_DITHER);
    }
    
    void initialLEDflash() {
      LEDS.showColor(CRGB(127, 0, 0));
      delay(333);
      LEDS.showColor(CRGB(0, 127, 0));
      delay(333);
      LEDS.showColor(CRGB(0, 0, 127));
      delay(333);
      LEDS.showColor(CRGB(0, 0, 0));
    }
    
    void setup() {
      setupLEDs();
      initialLEDflash();
    }
    
    void loop() {
      // update display if new data arrived, but only with max. 30Hz
      EVERY_N_MILLISECONDS(1000 / MAX_FRAME_RATE) {
        LEDS.showColor(CHSV(led_color++, 255, 128));
      }
    }
    
  18. samguyer commented on Aug 14, 2018

    @samguyer
    Contributor

    @HorstBaerbel Can you try something out for me? Instead of using showColor, can you call fill_solid to set the color, then call FastLED.show() separately.

  19. HorstBaerbel commented on Aug 14, 2018

    @HorstBaerbel

    I found the problem using my (handheld, small and crappy) oscilloscope. I seem to have shorted out pin 19 to GND on the prototype board and were no signals on pin 19. Thanks for the help and sorry for the hassle!
    Parallel mode with 540 LEDs is pretty smooth now on the ESP32. Without frame rate limiting (no "EVERY_N_MILLISECONDS") I see a flicker every ~20-30s, but at 60Hz it seems to be gone. Nice work!

  20. samguyer commented on Aug 15, 2018

    @samguyer
    Contributor

    @HorstBaerbel That's great! Glad to hear you fixed the problem (and that it wasn't some terrible bug in the library!)

  21. hamburgtech commented on Aug 20, 2018

    @hamburgtech

    Hi guys,

    I am working on a POV project, that is using 4 single strips of apa102 leds rotation around the core.
    The used controller is a ESP32, because it's quite cheap and offers a good performance and Bluetooth + Wifi. We are using 4 different strips to display a 70 x 200 image, because of the 4 different stripes we can run at lower RPM and therefore have less noise, but still have a flicker free and bright image.

    The issue that we are facing is, that we had to realise, that we can't display 70 x 200 at around 320 RPM, we were only getting to 109 columns displayed. We checked everything to find the reason for this. Then we found out that we had only 6 MHz speed for updating the LEDs... The SPI for the ESP32 seems not to be supported by the FastLED library :-(

    With other ways it was possible to get a high SPI rate with the ESP32, but we would still like to use the FastLED library, because we are used to it and it makes things more easy :-)

    Is there any chance that the SPI support for the ESP32 will be added?

    Thanks a lot.

    Cheers,
    Nils

  22. focalintent commented on Aug 20, 2018

    @focalintent
    Contributor

    Adding hardware SPI for esp32 is on the “will eventually get done” list - but I don’t have a timeframe for it yet (and no one has submitted support for it)

  23. hamburgtech commented on Aug 20, 2018

    @hamburgtech

    Adding hardware SPI for esp32 is on the “will eventually get done” list - but I don’t have a timeframe for it yet (and no one has submitted support for it)

    @focalintent Thanks for your quick reply.
    Okay sad to hear that it's officially not supported. Is there any known branch that have SPI support for the ESP32?
    The ESP32 is a perfect platform for POV project, it's cheap, has a lot of performance, BT and Wifi and so on. But without that SPI support it can't be used like that with FastLED.

    Well I will try to get into it and create some ESP32 solution for FastLED, but I think I could need some support for this.

    Thanks so far.

    Cheers,
    Nils

  24. hamid-elaosta commented on Aug 20, 2018

    @hamid-elaosta

    @hamburgtech I tried to add hardware SPI but FastLED is a big project and I'm not familiar with its code base. I ended up writing a simple sketch for ESP32 to take advantage of hardware SPI for my purposes (Hyperion) as the APA102s I'm using are really simple to control over SPI.

  25. focalintent commented on Aug 20, 2018

    @focalintent
    Contributor

    From https://github.com/FastLED/FastLED/blob/master/PORTING.md

    == Porting fastspi.h ==
    
    This is where you define the low level interface to the hardware SPI system (including a writePixels method that does a bunch of housekeeping for writing led data). Use the fastspi_nop.h file as a reference for the methods that need to be implemented. There are ofteh other useful methods that can help with the internals of the SPI code, I recommend taking a look at how the various platforms implement their SPI classes.
    

    The AVR example of how to do this is presets straightforward and can be used as a reference - https://github.com/FastLED/FastLED/blob/master/platforms/avr/fastspi_avr.h - also the teensy 3.2’s support, though that’s a bit more complex - https://github.com/FastLED/FastLED/blob/master/platforms/arm/k20/fastspi_arm_k20.h

    The biggest part will be getting the control registers for configuring the SPI output and determining the right register settings for various clock speeds and then writing data into the registers.

    As far as I know, no one has done this for the esp’s yet.

  26. NZSmartie commented on Aug 30, 2018

    @NZSmartie

    I got myself a strip of 150 SK9822 LEDs and this #504 (comment) fixed the issue for me

    // write the BIT'th bit out via spi, setting the data pin then strobing the clcok
    	template <uint8_t BIT> __attribute__((always_inline, hot)) inline static void writeBit(uint8_t b) {
    		//cli();
    		if(b & (1 << BIT)) {
    			FastPin<DATA_PIN>::hi();
    #ifdef ESP32
                            FastPin<CLOCK_PIN>::lo(); // kick a different register, block premature optimizations?
    #endif
    			FastPin<CLOCK_PIN>::hi(); CLOCK_HI_DELAY;
    			FastPin<CLOCK_PIN>::lo(); CLOCK_LO_DELAY;
    		} else {
    			FastPin<DATA_PIN>::lo();
    			FastPin<CLOCK_PIN>::hi(); CLOCK_HI_DELAY;
    			FastPin<CLOCK_PIN>::lo(); CLOCK_LO_DELAY;
    		}
    		//sei();
    	}
  27. haaslukas commented on Sep 3, 2018

    @haaslukas

    Same here. I'm working with SK9822 LEDs and #504 fixed the issue when using a LOLIN32. Interestingly, I didn't need to add this register kick-in hack when programing an LOLIN32 Lite. Maybe it's due to a different chip version?

  28. focalintent commented on Jan 20, 2019

    @focalintent
    Contributor

    Closing this off - just checked in a more reliable version of this fix.

    @haaslukas what platforms you do and don't need it on depends heavily on what the hi/lo methods in FastLED compile down to, in terms of low level statements/IR as well as how I/o registers are defined/implemented. My guess is on the esp32 the adjacent FastPin<DATA_PIN>::hi() and FastPin<CLOCK_PIN>::hi() (which both write to the same register) resulted in something that was literally:

        (*out_reg) = 0x01;
        (*out_reg) = 0x02;
    

    It's possible that the compiler version you were using with the LOLIN32 lite either had slightly different register definitions that didn't create this situation, and/or had slightly different compiler versions (or options defined in the platform) that didn't quite so aggressively optimize out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions