FadeLed icon indicating copy to clipboard operation
FadeLed copied to clipboard

ESP32 support

Open franzuu opened this issue 6 years ago β€’ 24 comments

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!

franzuu avatar Oct 28 '18 15:10 franzuu

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!

septillion-git avatar Oct 28 '18 19:10 septillion-git

Mm, as you might have noticed this will take me a little longer... Still would really like to include ESP32 support!

septillion-git avatar Dec 02 '18 16:12 septillion-git

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.

franzuu avatar Dec 03 '18 08:12 franzuu

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!

joelv1964 avatar Dec 04 '18 19:12 joelv1964

@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.

septillion-git avatar Jan 19 '19 13:01 septillion-git

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

joelv1964 avatar Jan 19 '19 17:01 joelv1964

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.

septillion-git avatar Jan 21 '19 10:01 septillion-git

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

joelv1964 avatar Jan 21 '19 16:01 joelv1964

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?

septillion-git avatar Jan 22 '19 16:01 septillion-git

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

joelv1964 avatar Jan 22 '19 17:01 joelv1964

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!

septillion-git avatar Jan 22 '19 17:01 septillion-git

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.

joelv1964 avatar Jan 22 '19 18:01 joelv1964

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 πŸ˜‹

septillion-git avatar Jan 22 '19 18:01 septillion-git

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:

joelv1964 avatar Jan 22 '19 19:01 joelv1964

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.

septillion-git avatar Jan 22 '19 19:01 septillion-git

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.

joelv1964 avatar Jan 28 '19 12:01 joelv1964

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 πŸ˜„

septillion-git avatar Jan 28 '19 13:01 septillion-git

Made a commit including the changes (including case for Uno/Nano/Pro Mini. d5197aa6abc9c8aefe32a1af272b46eba4403d92

septillion-git avatar Jan 28 '19 13:01 septillion-git

Cool :smile:, I try this new code in 2 or 3 days. I will tell you if it works properly. Bye

joelv1964 avatar Jan 28 '19 17:01 joelv1964

No problem! Good to get the bugs out before release anyway πŸ˜„

septillion-git avatar Jan 28 '19 17:01 septillion-git

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 !

joelv1964 avatar Feb 06 '19 06:02 joelv1964

Great! All I need is some time to go over all the documentation :roll_eyes: Hope I can do that this weekend.

septillion-git avatar Feb 06 '19 09:02 septillion-git

Wow, I really thought I already did all this! Should implement this!

septillion-git avatar Feb 01 '21 13:02 septillion-git

Hi, any update on this ?

littlej956 avatar Jun 19 '22 09:06 littlej956