FadeLed
FadeLed copied to clipboard
ESP32 support
Hi, I must say, what a great library! I have used it with ESP8266 and it worked great. But can you please make it compatible with ESP32? I am currently getting this error, while using Atom + PlatformIO: lib\FadeLed\src/FadeLed.h:20:28: fatal error: avr/pgmspace.h: No such file or directory
Also, ESP32 PWM works with ledcWrite(), but your library does analogWrite() ? I'm not 100% ,maybe now ESP32 also supports analogWrite(), but I have used ledcWrite(). I just wanted to guide your attention to this difference.
Thank you in advance!
Thanks!
But yeah, support for other micro's isn't that great. Mostly because I don't use them as much. Would like to but yeah, time...
But I thought I could just add ESP32 next to the ESP8266 support. But man! What a can of worms! π© Indeed it has no analogWrite() function... So supporting it isn't that simple. I think I can do that somewhere this week. Think I'll just use ledcWrite() instead of analofWrite() on an ESP32. So it will not take care of the rest of the ledc stuff. Should not be to hard but it needs some changes in the code, library.properties, add a new example to show how it works and find an ESP32 to test it... π
I'll keep you posted!
Mm, as you might have noticed this will take me a little longer... Still would really like to include ESP32 support!
Hi! Sorry for late reply! I am super thankful that you are planning to add ESP32 support! Take your time, no need to rush things. As I was writing this issue last time, I was trying out new things and had a lot other stuff to do also. That was the reason I forgot to answer. But I still feel this library is the way to go! Works really well with esp8266! If you need I can test the code with esp32 after you have made changes and report back to you.
Hi Septillion-git, I come to join the request of franzuu. It would be really cool if FadeLed could be adapted to the ESP32. It is really a useful library that releases the main loop for other treatments and brings a real comfort of use for the user. I am currently working on a model car wifi control and FadeLed simulates the inertia of filaments of incandescent bulbs. I think ESP32 will be more and more present in object applications. You do a great job. If you manage to adapt FadeLed to the ESP32, it will be really SUPER. Congratulations in advance!
@franzuu @joelv1964 Sorry it took a while. I made an attempt to add simple ESP32 support. See the branch eb527daf22f176ce6a6a5a5aeb2917119ad84295.
It's a little bit different than on an Uno or ESP8266 because you pass a ledc channel rather than a pin. FadeLed does not assign a ledc channel. 1) Because that was simpler to implement. But 2) because doing it in the library would not give you insight in which ledc channels are used otherwise. This would make the library less transparent. I added an example (FadeLedESP32) to "show" how to use it.
And I say "show" because besides compiling I was unable to test it π I can't find my ESP32... I will order one but if one would like to test it, great! Do you know how to install the version from the branch?
Couple of questions:
- Does it work?
- What is the default pin of the LED on which board?
- And if you really want to get exotic, does 16-bit mode work? (for this you do have to edit stuff. Might make an example later.
Hi, I'm happy to read your answer. I have installed the version from the branch. I just tried on an ESP32, it's great! The example works perfectly. On my ESP32 board LEDbuilt is on GPIO1, but my board is Chinese cheap π... I don't need the 16-bit mode but maybe others will need it. I quickly see if all the functions work like on the ESP8266. You did a great job!
Joel
That's great news!
I'll try to make a 16-bit example this week as well. If that's fine (can you test that for me? Still waiting for my ESP32) I'll try to make a release this week. :smile:
And nothing wrong with China ESP32. That's what I buy. Can you show me which version you have? Because would make sense to pick a pin which has already an LED connected. But I might just use LED_BUILTIN now I think of it.
Hi,
No problem for 16-bit PWM test π. I saw that according to the manufacturer of the ESP32 board, the LED_BUILTIN could be connected to GPIO1, GPIO2 on many boards, or GPIO9.
My ESP32 boards are this model.
Have a Good day
After struggling a while I made an 16-bit example. Why was I struggling? Because I made an error last time! I never set the PWM to 10-bit (in FadeLed.h) like I said so it was initialized to 8-bit. And you showed that also works fine π See a4f0521dd36af91d84192a9f34ab08664ab77e6b
But okay, fixed that an added an example in the branch for 16-bit. I'll probably make all gamma tables (all bit depths) available in code when I release it. Makes it even easier to change the bit depth (no need to generate new table for the 2,3 gamma).
New test: c18f9e2f1233405512654e0b9f22b6e3df205c23 Also use LED_BUILTIN in it. Which board do you select in the IDE to make it work?
Hi, Good news: with errors FadeLed works! :joy: I will not be able to test your new code before this week, but I will test it! In my IDE, the board selected is "ESP32 Dev Module". Do you want to publish a single FadeLed version compatible ESP8266 / ESP32 or 2 different versions? JoΓ«l
That's fine! I might change the example again πΌ
It's going to be a single release π That's most of the work, keep it compatible with everything π I also made some changes in the master branch. So this is going to be 1.6.0 if all done and tested π .
I'll keep you updated!
Great. I could not wait this week to test. I am experiencing a compilation error :worried:: "'LED_BUILTIN' was not declared in this scope". I think that we should define the pin2 as output directly in the example, "LED_BUILTIN" is obviously not recognized by the ESP32.
Yeah, I saw that error now as well. The ESP32 Dev Module has no LED_BUILTIN. I committed changes to the branch again including a fix for the error. See 9015743d9e1673ac0744a328856f15ff92d1a3b1
Whoooohooo, 100 commits π
OK, I tested the new example. I just replaced "LED_BUILTIN" with "1" for my board. It's perfect :ok_hand: The fade is more clean with 10-Bit Pwm compared to 8-Bit Pwm. The result is the same as on ESP8266. Many Thanks :wink:
Yep, 8-bit is a bit borderline for dimming light(/LEDs). Or actually, just plain to little π 10-bit is quite okay if you just have a single color. Although 16-bit should be even better but with little difference compaired to 12-bit. But you could increase the number of steps from 101 (0 to 100, default) to for example 256 with 16-bit. Which isn't useful with 10-bit and plain silly with 8-bit.
And funny, there is no board definition with 'LED_BUILTIN' defined as 1 π But okay, not to hard to change and I do tell it in the comments βΊοΈ
Alright, think I'll release it next weekend or so βΊοΈ Then you can use the one from the library manager again.
Hi,
How are you? I had a problem last night π. I need 8 FadeLed channels in the same project with an ESP32.
The ESP32 has a curious behavior. Only 5 channels made correctly with FadeLed. I think I understood, but I did not have time to try. In FadeLed.h, at line 63, there is "#define FADE_LED_MAX_LED 6". On the ESP32, 16 channels are usable (0 to 15). Should not be Fade_LED_MAX_LED to "16" in the case of using an ESP32?
#if defined (ESP8266) #define FADE_LED_MAX_LED 6 #else #define FADE_LED_MAX_LED 16 #end if
Tanks in advance for your reply.
Ahh, yeah, the max led problem. Not only an issue for the ESP32 even, you can also have it on a ESP8266 now I think about it. But it has less pins so it's less likely. But the mean reason to limit it is memory usage. An ESP8266 or ESP32 is less critical than a Uno or ATtiny but think I'll try it to do it neat:
#ifndef FADE_LED_MAX_LED
#if defined(ESP8266)
#define FADE_LED_MAX_LED 14
#elif defined(ESP32)
#define FADE_LED_MAX_LED 16
#elif defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
#define FADE_LED_MAX_LED 15
#else
#define FADE_LED_MAX_LED 6
#endif
#endif
I think max ever on a ESP8266 is 14 pins. And this also increases it for a Mega (both 2560 and 1280 which I think both have max 15 PWM pins). Probably there still are types which support more but default to less but also the other way around π It's a start π
Made a commit including the changes (including case for Uno/Nano/Pro Mini. d5197aa6abc9c8aefe32a1af272b46eba4403d92
Cool :smile:, I try this new code in 2 or 3 days. I will tell you if it works properly. Bye
No problem! Good to get the bugs out before release anyway π
Hi As promised I come back to you (with a little delay π) After replacing FadeLed. h with your changes, everything works perfectly. That's greatπ! If you need any special tests before you publish the update, do not hesitate to ask me. Have a Good day !
Great! All I need is some time to go over all the documentation :roll_eyes: Hope I can do that this weekend.
Wow, I really thought I already did all this! Should implement this!
Hi, any update on this ?