-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FR]: Use hardware PWM using rpi_hardware_pwm #6
Comments
Adding support for HW PWM is somewhere on the ToDo list for this plugin, but I'm currently not actively developing new features at the moment. Thanks for the link to the In the meantime I'm open to PRs, should you wish to add the feature yourself 😉 |
Hi, any update on adding the HW PWM? |
Apologies for the delay. I no longer have a working setup using a Raspberry PI so my development efforts on implementing Hardware PWM stalled some time ago. I've published the changes I made back then and drafted an RC release for you to check out. Feel free to check out these changes by switching release channels to |
Out of interest and somewhat offtopic, what do you use nowadays instead of the RPi setup? EDIT: I will definitely test the branch, thanks. |
I run Octoprint as a Docker container with a bunch of other services on a single mini server (basically a Nuc). |
I've installed the dev version but unfortunately the LEDs are still flickering. The version still shows up as 0.4.2 and keeps asking for update, but I believe that is because the version has not been updated in setup.py. Judging from the log the installed version is in fact 0.4.3rc1.
I have configured PWM on pin 12 in RasPi's config file and I don't see any errors in the log, so I'm assuming the HW PWM is actually enabled.
I'll try to measure pin 12 PWM output the signal analyzer to exclude any potential issue with my MOSEFT module used to control the LEDs and report back. |
Ah damn, forgot to bump the version number. That should be fixed in RC2. |
So I tested this. I added When I play with the light controls and I monitor I did play around with the frequency quite a bit but I do not see my lights coming back though the sysfs tells me something is definitely happening. Any ideas? |
I debugged further using sysfs as documented here and for some reason I can't get any output at all using hardware PWM even though all the values look good. I also looked up that I actually have a clock running to drive the PWM:
However, on the bright side, it seems this plugin uses the hardware PWM correctly. Not sure where to go from here. Some further research: The pin is definitely not "broken" as EDIT: As it turns out, when I set From a quick glance, it doesn't appear like RPi.GPIO even supports setting a pin mode other than |
I'm proposing #7 to fix my findings. |
@RoboMagus What do you think? |
Thanks for the PR! |
@RoboMagus Looks like the version in setup.py has not been updated... Other that that it works without flickering with one corner case - when you switch the light from non-PWM mode to PWM mode in LightControls settings without restarting the OctoPrint, the light will not work. Thanks @svenstaro, @RoboMagus! |
The reason is that the pin then gets set into a wrong mode and won't be reset to the |
@RoboMagus I think the README should also mention the config necessary for the hardware PWM to work. I think the bare minimum is
Otherwise the pin won't be set to the right mode. Also the bottom of the README still has the hardware PWM feature suggestion. |
For completeness it would be good to also mention configuration for all exposed HW PWM capable pins
Then it would be good to mention in the setup menu that the restart is required in such case, so people don't get confused |
I'll update the readme once the feature gets merged into main. But adding details regarding the overlay requirements is something that should definately be included. Regarding the required restart of Octoprint to get |
Well, you can manually set it using |
I've added some info to the Settings menu and this time actually bumped the RC version for a new release 😅 |
Looks good, although I think this page gives a better explanation of the HW PWM config |
Can't this be closed? It's working really nicely for me. |
I don't think it was merged to the main branch yet... |
@RoboMagus Wanna cut a release with this? I've been using this daily and it's totally fine. |
Thanks for your inputs everyone! As there have not been any changes to this feature in a while I've now released it as stable. |
Hi RoboMagus, I've given it a try, will work great for me on a single output, but if I try two, only the first one specified works. I have also tried dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func2=4 from https://github.com/dotnet/iot/blob/main/Documentation/raspi-pwm.md#enabling-hardware-pwm to no avail. Maybe I'm doing something wrong? |
@Damien0505, could you share what your complete dtoverlay is, as well as what pins you're trying to configure for this plugin? |
Hardware PWM for lightsdtoverlay=pwm,pin=12,func=4 Pins 12 and 13, have tried the two single channel dtoverlay statements, and the dual channel one. Reboot has ben performed after each change. Regards, |
Ok, so at least those 2 pins should not clash on the same function and the configuration should be applied as per the reboots, so that should be all fine. Can you provide the output of e.g. Also, could you enable debug logging for this plugin, restart octoprint and then provide the debug logging? Perhaps that'll have some additional infor that can indicate what's going on. |
As requested: pi@octopi:~ $ raspi-gpio get pi@octopi:~ $ gpio readall I'll enable debug for the plugin..... from raspi-gpio get does that mean it isn't setting the pins to PWM? |
Just noticed I didn't have rpi-hardware-pwm installed...... Now I'm getting: pi@octopi:~/.octoprint/logs $ raspi-gpio get From /home/pi/.octoprint/logs/octoprint.log | grep LightControls 2023-08-28 22:34:01,967 - octoprint.plugins.LightControls - DEBUG - LightControls gpio_cleanup, pin: 13 ### Manual adjustment of both pins via Octoprint Interface below ### 2023-08-28 22:35:16,927 - octoprint.plugins.LightControls - DEBUG - SendingLightValues |
All fixed!!! GPIO 12: level=0 fsel=4 alt=0 func=PWM0 Changed back the config to dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func2=4 Many thanks for your assistance! Love the plugin!! :) |
Ah, very well. I noticed that only one of the alt functions was actually active: |
Is your feature request related to a problem? Please describe.
Currently, this plugin is using software PWM which leads to flickering in LEDs.
Describe the solution you'd like
A simple solution to this problems exists in using rpi_hardware_pwm which allows for easy access to hardware PWM.
Describe alternatives you've considered
There is pigpio but it's inconvenient in comparison.
Additional context
#2.
The text was updated successfully, but these errors were encountered: