Skip to content

ESP8266 SPI - #936

Merged
samguyer merged 3 commits into
FastLED:masterfrom
BenoitAnastay:master
Mar 28, 2022
Merged

samguyer merged 3 commits into
FastLED:masterfrom
BenoitAnastay:master

Conversation

@BenoitAnastay

Copy link
Copy Markdown
Contributor

Implementation of SPI for ESP8266

@hberntsen

hberntsen commented Jan 8, 2020 •

Copy link
Copy Markdown

To use it:

#define FASTLED_ALL_PINS_HARDWARE_SPI
#define ESP8266_SPI

#include <FastLED.h>

I had some glitches with a 160MHz CPU speed, lowering it to 80MHz fixed that.

@kriegsman

Copy link
Copy Markdown
Member

@samguyer: Could you take a look at this PR? Looks interesting

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

I do not think that I respect the way the library should be structured but it does works

@CRCinAU

CRCinAU commented Apr 17, 2020

Copy link
Copy Markdown

Just to check, is this the same method as using NeoPixelBrightnessBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin); with NeoPixelBus?

I've tried for many months to try and stop the watchdog resets on my code using FastLED - yet NeoPixelBus can stay operational for days at a time with no resets. However because of the better maths support in FastLED, I'd like to try and move back - without the watchdog resets...

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

@CRCinAU I don't know about NeoPixelBus, but it's the same SPI implementation as for others ESP in FastLED

@CRCinAU

CRCinAU commented Apr 19, 2020 •

Copy link
Copy Markdown

Thanks for the reply. I can't see it specified anywhere - so does this use GPIO3 on the ESP8266? aka the RX pin?

EDIT: I think I'm getting a bit confused here - as the DMA method seems to use GPIO3. @coryking did a fork here to add DMA mode: https://github.com/coryking/FastLED

This is probably better as far as fixing the hardware resets that always occur on the ESP8266 chips... I wonder if he'd be interested in bringing it up to date and trying to merge things? It sure would make life easier for people...

@CRCinAU

CRCinAU commented Apr 27, 2020

Copy link
Copy Markdown

Just wondering if there is any further details on this - specifically which pin needs to be used, and if it is expected that this would work around the constant hardware watchdog resets with the ESP8266?

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

@CRCinAU I do use the defaults SPI pins, there is a schematics on my project

Diagram

@CRCinAU

CRCinAU commented Apr 27, 2020

Copy link
Copy Markdown

Ok, good to know... I'm currently testing the DMA support via the RX pin on a D1 Mini - and it seems to do very well... My current uptime is 0 days 06:11:20.255 - which is more than I can normally stay up using the stock bit-banging with FastLED...

This is the DMA repo: https://github.com/coryking/FastLED

I wonder what the status is for FastLED in accepting patches / PRs these days - as there doesn't seem to be a lot of movement of late...

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

Native SPI can work very fast as well, I choosed a frequency that work well to drive my 576 APA102 strip but the frequency should be a constent so may be defined by user, I should fix it but I guess there is a couple issue to assert before merging.

The PR is more a beta/proof of concept so I'm waiting for instruction to do it with the proper FastLED way

I do not have any crash issue even with my messy Home Asistant MQTT setup, the only issue I have is the wifi wich is not stable

@CRCinAU

CRCinAU commented Apr 28, 2020

Copy link
Copy Markdown

Ah - Wifi having problems is easy fixed... Use WiFi.setSleepMode(WIFI_MODEM_SLEEP); in setup().

My main problem has been having watchdog resets when using FastLED in bit banging mode...

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

Mine can run for hours, the only watchdog reset I have is with my UDP control, I think a buffer overflow or a interuption issue but FastLED with SPI per se is not causing any reset, my wifi issue I guess it's the presence of multiple access points, I didn't try to use the BSSID but thank for the tip

@girlpunk

girlpunk commented May 4, 2020

Copy link
Copy Markdown

Can this be used for clockless LEDs, such as the WS2812B?

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

@cyberjacob I don't have them to test it but it should work

@CRCinAU

CRCinAU commented May 8, 2020

Copy link
Copy Markdown

Yeah - I only use WS2812 LEDs - hence the DMA option is better for me - and I can confirm that it works perfectly via the RX pin...

@WhichKatieDid

Copy link
Copy Markdown

Out of curiosity, why #if defined(ESP8266_SPI) instead of #if defined(ESP8266) && defined(FASTLED_ALL_PINS_HARDWARE_SPI) ?

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

@BlainHamon I hadn't thought about code consitency, norm ect ....

I was just doing fast prototyping, so I know there is somes fixes/rewrte to do, before merging but I do not really know the project and how to integrate this code properly, but in the meanwhile the code is already available to use by others

@domiko96

Copy link
Copy Markdown

Hey there,
I'm trying to use an APA102 strip with an ESP8266 (on GPIO5 and GPIO16) on a custom board (https://github.com/Yottabits/espled still in development). I was wondering whether the APA102 are supported on the current Master (8c458a2) or whether one needs these changes to use them on the esp8266.
I tried both but couldn't get them to work. On the wiki page https://github.com/FastLED/FastLED/wiki/ESP8266-notes there is by now no explanation for the new defines so I assume the APA102s should be already working with the ESP8266?
I would be super happy if I get a reply from somebody more experienced. Keep up the great work ;)

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

@domiko96 This patch is not merged, if you want to use it you'll need to aply this patch on your library and use thoses headers as mentioned above by h3ndrik

#define FASTLED_ALL_PINS_HARDWARE_SPI
#define ESP8266_SPI

#include <FastLED.h>

If you use the FastLED master it will use a bitbanging method that is overly laggy and thus not able to drive as much leds as the SPI method

@13rac1

13rac1 commented Mar 18, 2021

Copy link
Copy Markdown

Thanks @BenoitAnastay Works great! I have 240 SK6822 LEDs attached to a HiLetGo ESP8266 using pins 13/14 running at 6mhz without issue. Example config with PlatformIO if anyone else needs:

platformio.ini

[platformio]
env_default = nodemcuv2

[env:nodemcuv2]
platform = espressif8266
framework = arduino
board = nodemcuv2
lib_deps =
  https://github.com/BenoitAnastay/FastLED#master

main.cpp

#define FASTLED_ESP8266_RAW_PIN_ORDER
//#define FASTLED_ESP8266_NODEMCU_PIN_ORDER
//#define FASTLED_ESP8266_D1_PIN_ORDER

// Enable FastLED SPI for ESP8266 using https://github.com/BenoitAnastay/FastLED
#define FASTLED_ALL_PINS_HARDWARE_SPI
#define ESP8266_SPI

#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define DATA_PIN 13
#define CLK_PIN 14
#define LED_TYPE SK6822
#define COLOR_ORDER RGB

void setup() {
  FastLED
      .addLeds<LED_TYPE, DATA_PIN, CLK_PIN, COLOR_ORDER, DATA_RATE_MHZ(6)>(
          leds, NUM_LEDS)
      .setCorrection(TypicalLEDStrip);
}

@LennyPenny

Copy link
Copy Markdown

are there any plans of this being merged any time soon?

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

I'm not maintening this PR but anyone is free to update and cleanup this.

@samguyer was assigned to this PR by @kriegsman but he do net left any comment ... 🤷

@heX16

heX16 commented Dec 24, 2021

Copy link
Copy Markdown
Contributor

Why hasn't this PR been applied yet? "FastLED" is not fast without it ...

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

Why hasn't this PR been applied yet? "FastLED" is not fast without it ...

I don't know, they did merged the one for ESP32 but not this one.

Nowaday there is conflicts but the logics works great.

Im still waiting after a project admin to review the code

@samguyer

Copy link
Copy Markdown
Contributor

Hi all! Apologies for the delay. I will prioritize this PR and try to get it in as soon as possible.

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

I'll not be able to maintain the PR because I don't have any ESP board today.

But since the logic was working I guess that there is only the need to fix the conflicts and check if it's respect the good practices

@samguyer

samguyer commented Jan 2, 2022

Copy link
Copy Markdown
Contributor

@BenoitAnastay I want to merge this work today. Any chance you can look at the conflicts and get the PR to the point I can merge it? I'm happy to look over the changes after that and do testing on actual ESP hardware.

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

@samguyer I'll try to fix the conflicts (and respect the files location) by the 5th.

Basicaly there is just the same changes as the one for the ESP32 (which was bases on my PR, itself based on another SPI intégration of FastLED).

@davidpanic

Copy link
Copy Markdown

The 5th of what? June? Could you please fix this ASAP, this would be awesome to have merged into FastLED.

@samguyer

Copy link
Copy Markdown
Contributor

@psrcek I'll try to get this merged in soon. I think the goal was January 5, but hey, we've all got day jobs!

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

Sorry I was a lot busy, I'll do that ASAP, I do not have ESP board but I'll just try to fix conflits since the logic was working well

@samguyer

Copy link
Copy Markdown
Contributor

@BenoitAnastay That would be great. If you can resolve the conflicts, I can do the testing and any debugging.

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

I tried to update the PR, I did the same changes as the ones that was merged for the ESP32, hope it'll work

The original one is here : d88b124

@BenoitAnastay BenoitAnastay reopened this Mar 27, 2022
@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

I'm able to build Blink.ino with

#define FASTLED_ALL_PINS_HARDWARE_SPI
#include <FastLED.h>

@samguyer

Copy link
Copy Markdown
Contributor

@BenoitAnastay Fantastic! Thank you for all your work on this contribution!

@samguyer
samguyer merged commit 77e2414 into FastLED:master Mar 28, 2022
@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

Is it still working on hardware ?

I was only able tu build it, not test it on real hardware

@samguyer

Copy link
Copy Markdown
Contributor

I'll do some testing. I just wanted to get the code in there.

// select the SPI output (TODO: research whether this really means hi or lo. Alt TODO: move select responsibility out of the SPI classes
// entirely, make it up to the caller to remember to lock/select the line?)
void select() {
SPI.beginTransaction(SPISettings(3200000, MSBFIRST, SPI_MODE0));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need to replace hardcoded speed by SPI_SPEED, 32Mhz was fine for my project driving 576 APA102

Comment thread src/fastspi.h
#define DATA_RATE_MHZ(X) (((48000000L / 1000000L) / X))
#define DATA_RATE_KHZ(X) (((48000000L / 1000L) / X))
#elif defined(FASTLED_TEENSY4) || (defined(ESP32) && defined(FASTLED_ALL_PINS_HARDWARE_SPI))
#elif defined(FASTLED_TEENSY4) || (defined(ESP32) && defined(FASTLED_ALL_PINS_HARDWARE_SPI)) || (defined(ESP8266) && defined(FASTLED_ALL_PINS_HARDWARE_SPI))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not change that in my original PR, the consistency should be checked

@dbu

dbu commented Nov 25, 2023

Copy link
Copy Markdown
Contributor

FTR (because i was a bit confused after ending up here):
With current versions (i tried with 3.6.0) this works, and you only need to #define FASTLED_ALL_PINS_HARDWARE_SPI to enable. ESP8266_SPI does not hurt but does not do anything, the parameter no longer exists in the code.

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

@dbu looking at my precedent comment I guess you have to define ESP8266

@dbu

dbu commented Nov 26, 2023

Copy link
Copy Markdown
Contributor

i think that constant is defined by the arduino env when you select an ESP8266 board. i did not define it but the pragma warning went away when defining only the FASTLED_ALL_PINS_HARDWARE_SPI.

@BenoitAnastay

Copy link
Copy Markdown
Contributor Author

My initial commit was working for sure, I had to update it and make it consistent with other PRs made after but I wasn't able to test it myself since I do not have the hardware.

You can have a look into this merge to check changes https://github.com/FastLED/FastLED/compare/18fccac9a20df0824c52b12831ffc0dbd12ee929..4d73cddfe4bd2b370ee882b6f68769bf7f8309f4

Since the logic hasn't changed it might be a loading issue. this should be displayed in the build logs
#pragma message "ESP8266 Hardware SPI support added"

Another thing that might cause issue it if you are using GPIO ports because of a label differences between your board and mine

I put a diagram here
#936 (comment)

@dbu

dbu commented Nov 26, 2023

Copy link
Copy Markdown
Contributor

yes, i do get the pragma message that hardware spi is added, and the LEDs blink nicely as they should :-D
thats why i wanted to confirm it works and note that no additional #define is needed anymore.

thanks for the contribution btw, i am really enjoying the FastLED library.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.