libretiny: PWM implementation appears broken

Colours are often getting randomly screwed up over PWM.

I’ve been trying to debug this for a while now, and thought ESPHome was transforming colour values somehow before delivering them over PWM to an RGB bulb I had, but after logging inside libretiny_pwm.cpp, I can see that all the duty cycle values are correct, yet somehow the bulb is often the wrong colour or in the wrong state.

Sometimes I can get the bulb in a state where max duty sent to red channel only and others zero will show a bright red light as expected. And other times, the same values sent over PWM will result in the light being off.

Is there some kind of state that’s not being managed in the chipset? I know these chips have on-board PWM - is this not being managed correctly?

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Reactions: 2
  • Comments: 23 (11 by maintainers)

Most upvoted comments

any tips for that

Install Visual Studio Code with PlatformIO add-on. Clone libretiny repository into ~/.platformio/platforms/libretiny (remove it if it’s already there). Create a new PlatformIO project with LibreTiny platform (in VSCode). Add both the LibreTiny directory and the PIO project to a single VSCode workspace, open the workspace. Let it refresh indexes. Copy (or symlink) the .vscode/c_cpp_properties.json file from the PIO project to LibreTiny directory. Make sure to backup your code frequently - PIO might remove/reinstall it if you use version: dev/recommended in ESPHome. To be safe, set version: latest in your YAML. If you don’t have ESPHome yet, git clone it and install with pip install -e .. Then run it as usual: esphome compile xxx.yaml.