Skip to content
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

Closed
svenstaro opened this issue Dec 11, 2022 · 32 comments
Closed

[FR]: Use hardware PWM using rpi_hardware_pwm #6

svenstaro opened this issue Dec 11, 2022 · 32 comments
Labels
enhancement New feature or request

Comments

@svenstaro
Copy link
Contributor

svenstaro commented Dec 11, 2022

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.

@RoboMagus
Copy link
Owner

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 rpi_hardware_pwm module. This indeed looks much more easy to integrate into the current codebase than switching over to pigpio. Perhaps in the comming months I might be able to take a look...

In the meantime I'm open to PRs, should you wish to add the feature yourself 😉

@RoboMagus RoboMagus added the enhancement New feature or request label Dec 11, 2022
@pawelsky
Copy link

Hi, any update on adding the HW PWM?

@RoboMagus
Copy link
Owner

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.
Note that I have not been able to test these changes myself!

Feel free to check out these changes by switching release channels to Development and report back to me.
If you do, please keep an eye on your logs. If there are any issues creating a HW PWM channel it'll report an error and fallback to the software based PWM controls.

@svenstaro
Copy link
Contributor Author

svenstaro commented Jun 21, 2023

Out of interest and somewhat offtopic, what do you use nowadays instead of the RPi setup?

EDIT: I will definitely test the branch, thanks.

@RoboMagus
Copy link
Owner

what do you use nowadays instead of the RPi setup?

I run Octoprint as a Docker container with a bunch of other services on a single mini server (basically a Nuc).

@pawelsky
Copy link

pawelsky commented Jun 22, 2023

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.

image

2023-06-21 12:04:12,939 - octoprint.plugins.softwareupdate - INFO - Starting update of LightControls to 0.4.3rc1...
2023-06-21 12:04:28,345 - octoprint.plugins.softwareupdate - INFO - Update of LightControls to 0.4.3rc1 successful!

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.

2023-06-22 00:17:31,814 - octoprint.plugins.LightControls - DEBUG - LightControls settings initialized: '[{'frequency': '100', 'inverted': False, 'ispwm': True, 'name': 'Prusa Lights', 'onConnectValue': '25', 'onDisconnectValue': '0', 'onOctoprintStartValue': '10', 'onPrintEndValue': '25', 'onPrintPausedValue': '50', 'onPrintResumedValue': '100', 'onPrintStartValue': '100', 'pin': 12}]'
2023-06-22 00:17:31,815 - octoprint.plugins.LightControls - DEBUG - Running RPi.GPIO version 0.7.0
2023-06-22 00:17:31,815 - octoprint.plugins.LightControls - DEBUG - LightControls gpio_startup, pin: 12, settings: {'frequency': '100', 'inverted': False, 'ispwm': True, 'name': 'Prusa Lights', 'onConnectValue': '25', 'onDisconnectValue': '0', 'onOctoprintStartValue': '10', 'onPrintEndValue': '25', 'onPrintPausedValue': '50', 'onPrintResumedValue': '100', 'onPrintStartValue': '100', 'pin': 12}
2023-06-22 00:17:31,816 - octoprint.plugins.LightControls - DEBUG - LightControls pruned settings after initialize: '[{'frequency': '100', 'inverted': False, 'ispwm': True, 'name': 'Prusa Lights', 'onConnectValue': '25', 'onDisconnectValue': '0', 'onOctoprintStartValue': '10', 'onPrintEndValue': '25', 'onPrintPausedValue': '50', 'onPrintResumedValue': '100', 'onPrintStartValue': '100', 'pin': 12}]'
|  LightControls (0.4.2) = /home/pi/oprint/lib/python3.7/site-packages/octoprint_LightControls
2023-06-22 20:38:15,856 - octoprint.plugins.LightControls - DEBUG - Running RPi.GPIO version 0.7.0
2023-06-22 20:38:15,859 - octoprint.plugins.LightControls - DEBUG - LightControls gpio_startup, pin: 12, settings: {'frequency': '100', 'inverted': False, 'ispwm': True, 'name': 'Prusa Lights', 'onConnectValue': '25', 'onDisconnectValue': '0', 'onOctoprintStartValue': '10', 'onPrintEndValue': '25', 'onPrintPausedValue': '50', 'onPrintResumedValue': '100', 'onPrintStartValue': '100', 'pin': 12}
2023-06-22 20:38:15,859 - octoprint.plugins.LightControls - DEBUG - LightControls gpio_cleanup, pin: 12
2023-06-22 20:38:15,860 - octoprint.plugins.LightControls - DEBUG - LightControls pin(12).setValue(10), inverted: False
2023-06-22 20:38:38,363 - octoprint.plugins.LightControls - DEBUG - LightControls pin(12).setValue(25), inverted: False
2023-06-22 20:39:22,575 - octoprint.plugins.LightControls - DEBUG - SendingLightValues
2023-06-22 20:39:25,148 - octoprint.plugins.LightControls - DEBUG - LightControls pin(12).setValue(25), inverted: False

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.

@RoboMagus
Copy link
Owner

Ah damn, forgot to bump the version number. That should be fixed in RC2.

@svenstaro
Copy link
Contributor Author

So I tested this. I added dtoverlay=pwm,pin=12,func=4 to /boot/config.txt. This breaks my previous LED behavior completely and I don't see any lights coming up compared to software PWM. Also, there are no errors in the logs. This tells me that it's using hardware PWM for sure.

When I play with the light controls and I monitor watch cat /sys/class/pwm/pwmchip0/pwm0/duty_cycle, I do see a change happening there in the value. That tells me it's interacting with the hardware PWM driver.

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?

@svenstaro
Copy link
Contributor Author

svenstaro commented Jun 26, 2023

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:

vcgencmd measure_clock pwm
frequency(25)=99997560

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 gpio -g write 12 1 works just fine. I'd also like to note that if I use gpio -g mode 12 pwm and then gpio -g pwm 12 500, I get a very nice and steady like and gpio readall shows the pin to be in ALT0 mode.

EDIT: As it turns out, when I set gpio -g mode 12 pwm it works just fine, that's all I have to do. Sadly the pin mode gets overridden and reset by LightControls when I save the settings, I'll continue investigating. However, it definitely is the case that something doesn't set the pin to be in PWM mode.

From a quick glance, it doesn't appear like RPi.GPIO even supports setting a pin mode other than IN and OUT.

@svenstaro
Copy link
Contributor Author

I'm proposing #7 to fix my findings.

@svenstaro
Copy link
Contributor Author

@RoboMagus What do you think?

@RoboMagus
Copy link
Owner

Thanks for the PR!
I've bumped the RC release to include your changes.

@pawelsky
Copy link

pawelsky commented Jul 5, 2023

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

@svenstaro
Copy link
Contributor Author

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.

The reason is that the pin then gets set into a wrong mode and won't be reset to the ALT0 mode that it needs to be in. This can be verified via gpio readall.

@svenstaro
Copy link
Contributor Author

svenstaro commented Jul 5, 2023

@RoboMagus I think the README should also mention the config necessary for the hardware PWM to work. I think the bare minimum is

dtoverlay=pwm,pin=12,func=4

Otherwise the pin won't be set to the right mode.

Also the bottom of the README still has the hardware PWM feature suggestion.

@pawelsky
Copy link

pawelsky commented Jul 5, 2023

For completeness it would be good to also mention configuration for all exposed HW PWM capable pins

dtoverlay=pwm,pin=12,func=4
dtoverlay=pwm,pin=18,func=2
dtoverlay=pwm,pin=13,func=4
dtoverlay=pwm,pin=19,func=2

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.

The reason is that the pin then gets set into a wrong mode and won't be reset to the ALT0 mode that it needs to be in. This can be verified via gpio readall.

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

@RoboMagus
Copy link
Owner

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 ALT modes for Gpio to work, I wonder if there is any other way to enforce it. Have either of you tried this?

@svenstaro
Copy link
Contributor Author

Well, you can manually set it using gpio -g write 12 1 or by writing to the right place in the dev fs.

@RoboMagus
Copy link
Owner

I've added some info to the Settings menu and this time actually bumped the RC version for a new release 😅

@pawelsky
Copy link

pawelsky commented Jul 6, 2023

Looks good, although I think this page gives a better explanation of the HW PWM config
https://github.com/dotnet/iot/blob/main/Documentation/raspi-pwm.md#enabling-hardware-pwm

@svenstaro
Copy link
Contributor Author

Can't this be closed? It's working really nicely for me.

@pawelsky
Copy link

I don't think it was merged to the main branch yet...

@svenstaro
Copy link
Contributor Author

@RoboMagus Wanna cut a release with this? I've been using this daily and it's totally fine.

@RoboMagus
Copy link
Owner

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.

@Damien0505
Copy link

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?
Kind regards,
Damien

@RoboMagus
Copy link
Owner

@Damien0505, could you share what your complete dtoverlay is, as well as what pins you're trying to configure for this plugin?

@Damien0505
Copy link

Hardware PWM for lights

dtoverlay=pwm,pin=12,func=4
dtoverlay=pwm,pin=13,func=4
#dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func2=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,
Damien

@RoboMagus
Copy link
Owner

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. raspi-gpio get or gpio readall (depending on the utilities that you have available) to check if the pins are correctly setup?

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.

@Damien0505
Copy link

As requested:

pi@octopi:~ $ raspi-gpio get
BANK0 (GPIO 0 to 27):
GPIO 0: level=1 fsel=0 func=INPUT
GPIO 1: level=1 fsel=0 func=INPUT
GPIO 2: level=1 fsel=0 func=INPUT
GPIO 3: level=1 fsel=0 func=INPUT
GPIO 4: level=1 fsel=0 func=INPUT
GPIO 5: level=1 fsel=0 func=INPUT
GPIO 6: level=1 fsel=0 func=INPUT
GPIO 7: level=1 fsel=0 func=INPUT
GPIO 8: level=1 fsel=0 func=INPUT
GPIO 9: level=0 fsel=0 func=INPUT
GPIO 10: level=0 fsel=0 func=INPUT
GPIO 11: level=0 fsel=0 func=INPUT
GPIO 12: level=1 fsel=1 func=OUTPUT
GPIO 13: level=1 fsel=1 func=OUTPUT

GPIO 14: level=0 fsel=0 func=INPUT
GPIO 15: level=1 fsel=0 func=INPUT
GPIO 16: level=0 fsel=0 func=INPUT
GPIO 17: level=0 fsel=0 func=INPUT
GPIO 18: level=0 fsel=0 func=INPUT
GPIO 19: level=0 fsel=0 func=INPUT
GPIO 20: level=0 fsel=0 func=INPUT
GPIO 21: level=0 fsel=0 func=INPUT
GPIO 22: level=0 fsel=0 func=INPUT
GPIO 23: level=0 fsel=0 func=INPUT
GPIO 24: level=0 fsel=0 func=INPUT
GPIO 25: level=0 fsel=0 func=INPUT
GPIO 26: level=0 fsel=0 func=INPUT
GPIO 27: level=0 fsel=0 func=INPUT
BANK1 (GPIO 28 to 45):
GPIO 28: level=1 fsel=0 func=INPUT
GPIO 29: level=0 fsel=1 func=OUTPUT
GPIO 30: level=0 fsel=7 alt=3 func=CTS0
GPIO 31: level=0 fsel=7 alt=3 func=RTS0
GPIO 32: level=1 fsel=7 alt=3 func=TXD0
GPIO 33: level=1 fsel=7 alt=3 func=RXD0
GPIO 34: level=1 fsel=0 func=INPUT
GPIO 35: level=1 fsel=0 func=INPUT
GPIO 36: level=1 fsel=0 func=INPUT
GPIO 37: level=1 fsel=0 func=INPUT
GPIO 38: level=1 fsel=0 func=INPUT
GPIO 39: level=1 fsel=0 func=INPUT
GPIO 40: level=0 fsel=4 alt=0 func=PWM0
GPIO 41: level=0 fsel=4 alt=0 func=PWM1
GPIO 42: level=0 fsel=4 alt=0 func=GPCLK1
GPIO 43: level=1 fsel=4 alt=0 func=GPCLK2
GPIO 44: level=1 fsel=0 func=INPUT
GPIO 45: level=1 fsel=0 func=INPUT
BANK2 (GPIO 46 to 53):
GPIO 46: level=1 fsel=0 func=INPUT
GPIO 47: level=1 fsel=1 func=OUTPUT
GPIO 48: level=0 fsel=4 alt=0 func=SD0_CLK
GPIO 49: level=1 fsel=4 alt=0 func=SD0_CMD
GPIO 50: level=1 fsel=4 alt=0 func=SD0_DAT0
GPIO 51: level=1 fsel=4 alt=0 func=SD0_DAT1
GPIO 52: level=1 fsel=4 alt=0 func=SD0_DAT2
GPIO 53: level=1 fsel=4 alt=0 func=SD0_DAT3
pi@octopi:~ $

pi@octopi:~ $ gpio readall
+-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5v | | |
| 3 | 9 | SCL.1 | IN | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 0 | IN | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | IN | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | IN | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | IN | 0 | 23 || 24 | 1 | IN | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 1 | IN | CE1 | 11 | 7 |
| 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 |
| 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | |
| 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 1 | OUT | GPIO.26 | 26 | 12 |
| 13 | 23 | GPIO.23 | OUT | 1 | 33 || 34 | | | 0v | | |
| 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 |
| 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 |
| | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+
pi@octopi:~ $

I'll enable debug for the plugin..... from raspi-gpio get does that mean it isn't setting the pins to PWM?

@Damien0505
Copy link

Damien0505 commented Aug 28, 2023

Just noticed I didn't have rpi-hardware-pwm installed......

Now I'm getting:

pi@octopi:~/.octoprint/logs $ raspi-gpio get
BANK0 (GPIO 0 to 27):
GPIO 0: level=1 fsel=0 func=INPUT
GPIO 1: level=1 fsel=0 func=INPUT
GPIO 2: level=1 fsel=0 func=INPUT
GPIO 3: level=1 fsel=0 func=INPUT
GPIO 4: level=1 fsel=0 func=INPUT
GPIO 5: level=1 fsel=0 func=INPUT
GPIO 6: level=1 fsel=0 func=INPUT
GPIO 7: level=1 fsel=0 func=INPUT
GPIO 8: level=1 fsel=0 func=INPUT
GPIO 9: level=0 fsel=0 func=INPUT
GPIO 10: level=0 fsel=0 func=INPUT
GPIO 11: level=0 fsel=0 func=INPUT
GPIO 12: level=0 fsel=0 func=INPUT
GPIO 13: level=0 fsel=4 alt=0 func=PWM1

GPIO 14: level=0 fsel=0 func=INPUT
GPIO 15: level=1 fsel=0 func=INPUT
GPIO 16: level=0 fsel=0 func=INPUT
GPIO 17: level=0 fsel=0 func=INPUT
GPIO 18: level=0 fsel=0 func=INPUT
GPIO 19: level=0 fsel=0 func=INPUT
GPIO 20: level=0 fsel=0 func=INPUT
GPIO 21: level=0 fsel=0 func=INPUT
GPIO 22: level=0 fsel=0 func=INPUT
GPIO 23: level=0 fsel=0 func=INPUT
GPIO 24: level=0 fsel=0 func=INPUT
GPIO 25: level=0 fsel=0 func=INPUT
GPIO 26: level=0 fsel=0 func=INPUT
GPIO 27: level=0 fsel=0 func=INPUT
BANK1 (GPIO 28 to 45):
GPIO 28: level=1 fsel=0 func=INPUT
GPIO 29: level=0 fsel=1 func=OUTPUT
GPIO 30: level=0 fsel=7 alt=3 func=CTS0
GPIO 31: level=0 fsel=7 alt=3 func=RTS0
GPIO 32: level=1 fsel=7 alt=3 func=TXD0
GPIO 33: level=1 fsel=7 alt=3 func=RXD0
GPIO 34: level=1 fsel=0 func=INPUT
GPIO 35: level=1 fsel=0 func=INPUT
GPIO 36: level=1 fsel=0 func=INPUT
GPIO 37: level=1 fsel=0 func=INPUT
GPIO 38: level=1 fsel=0 func=INPUT
GPIO 39: level=1 fsel=0 func=INPUT
GPIO 40: level=0 fsel=4 alt=0 func=PWM0
GPIO 41: level=0 fsel=4 alt=0 func=PWM1
GPIO 42: level=1 fsel=4 alt=0 func=GPCLK1
GPIO 43: level=0 fsel=4 alt=0 func=GPCLK2
GPIO 44: level=1 fsel=0 func=INPUT
GPIO 45: level=1 fsel=0 func=INPUT
BANK2 (GPIO 46 to 53):
GPIO 46: level=1 fsel=0 func=INPUT
GPIO 47: level=1 fsel=1 func=OUTPUT
GPIO 48: level=0 fsel=4 alt=0 func=SD0_CLK
GPIO 49: level=1 fsel=4 alt=0 func=SD0_CMD
GPIO 50: level=1 fsel=4 alt=0 func=SD0_DAT0
GPIO 51: level=1 fsel=4 alt=0 func=SD0_DAT1
GPIO 52: level=1 fsel=4 alt=0 func=SD0_DAT2
GPIO 53: level=1 fsel=4 alt=0 func=SD0_DAT3

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
2023-08-28 22:34:01,968 - octoprint.plugins.LightControls - DEBUG - LightControls gpio_cleanup, pin: 12
2023-08-28 22:34:01,970 - octoprint.plugins.LightControls - DEBUG - LightControls shutdown
2023-08-28 22:34:21,168 - octoprint.plugins.LightControls - DEBUG - LightControls settings initialized: '[{'frequency': '320', 'inverted': False, 'ispwm': True, 'name': 'Right LEDs', 'onConnectValue': '', 'onDisconnectValue': '', 'onOctoprintStartValue': '', 'onPrintEndValue': '0', 'onPrintPausedValue': '', 'onPrintResumedValue': '', 'onPrintStartValue': '100', 'pin': 13}, {'frequency': '320', 'inverted': False, 'ispwm': True, 'name': 'Left LEDs', 'onConnectValue': '', 'onDisconnectValue': '', 'onOctoprintStartValue': '', 'onPrintEndValue': '0', 'onPrintPausedValue': '', 'onPrintResumedValue': '', 'onPrintStartValue': '100', 'pin': 12}]'
2023-08-28 22:34:21,168 - octoprint.plugins.LightControls - DEBUG - Running RPi.GPIO version 0.7.1
2023-08-28 22:34:21,168 - octoprint.plugins.LightControls - DEBUG - LightControls gpio_startup, pin: 13, settings: {'frequency': '320', 'inverted': False, 'ispwm': True, 'name': 'Right LEDs', 'onConnectValue': '', 'onDisconnectValue': '', 'onOctoprintStartValue': '', 'onPrintEndValue': '0', 'onPrintPausedValue': '', 'onPrintResumedValue': '', 'onPrintStartValue': '100', 'pin': 13}
2023-08-28 22:34:21,175 - octoprint.plugins.LightControls - DEBUG - Setup hardware PWM succeded!
2023-08-28 22:34:21,178 - octoprint.plugins.LightControls - DEBUG - LightControls gpio_startup, pin: 12, settings: {'frequency': '320', 'inverted': False, 'ispwm': True, 'name': 'Left LEDs', 'onConnectValue': '', 'onDisconnectValue': '', 'onOctoprintStartValue': '', 'onPrintEndValue': '0', 'onPrintPausedValue': '', 'onPrintResumedValue': '', 'onPrintStartValue': '100', 'pin': 12}
2023-08-28 22:34:21,181 - octoprint.plugins.LightControls - DEBUG - Setup hardware PWM succeded!
2023-08-28 22:34:21,183 - octoprint.plugins.LightControls - DEBUG - LightControls pruned settings after initialize: '[{'frequency': '320', 'inverted': False, 'ispwm': True, 'name': 'Right LEDs', 'onConnectValue': '', 'onDisconnectValue': '', 'onOctoprintStartValue': '', 'onPrintEndValue': '0', 'onPrintPausedValue': '', 'onPrintResumedValue': '', 'onPrintStartValue': '100', 'pin': 13}, {'frequency': '320', 'inverted': False, 'ispwm': True, 'name': 'Left LEDs', 'onConnectValue': '', 'onDisconnectValue': '', 'onOctoprintStartValue': '', 'onPrintEndValue': '0', 'onPrintPausedValue': '', 'onPrintResumedValue': '', 'onPrintStartValue': '100', 'pin': 12}]'
| LightControls (0.4.3) = /home/pi/oprint/lib/python3.7/site-packages/octoprint_LightControls
2023-08-28 22:34:32,853 - octoprint.plugins.LightControls - DEBUG - Running RPi.GPIO version 0.7.1
2023-08-28 22:34:32,857 - octoprint.plugins.LightControls - DEBUG - LightControls gpio_startup, pin: 13, settings: {'frequency': '320', 'inverted': False, 'ispwm': True, 'name': 'Right LEDs', 'onConnectValue': '', 'onDisconnectValue': '', 'onOctoprintStartValue': '', 'onPrintEndValue': '0', 'onPrintPausedValue': '', 'onPrintResumedValue': '', 'onPrintStartValue': '100', 'pin': 13}
2023-08-28 22:34:32,857 - octoprint.plugins.LightControls - DEBUG - LightControls gpio_cleanup, pin: 13
2023-08-28 22:34:32,952 - octoprint.plugins.LightControls - DEBUG - Setup hardware PWM succeded!
2023-08-28 22:34:32,986 - octoprint.plugins.LightControls - DEBUG - LightControls gpio_startup, pin: 12, settings: {'frequency': '320', 'inverted': False, 'ispwm': True, 'name': 'Left LEDs', 'onConnectValue': '', 'onDisconnectValue': '', 'onOctoprintStartValue': '', 'onPrintEndValue': '0', 'onPrintPausedValue': '', 'onPrintResumedValue': '', 'onPrintStartValue': '100', 'pin': 12}
2023-08-28 22:34:32,986 - octoprint.plugins.LightControls - DEBUG - LightControls gpio_cleanup, pin: 12
2023-08-28 22:34:33,108 - octoprint.plugins.LightControls - DEBUG - Setup hardware PWM succeded!

### Manual adjustment of both pins via Octoprint Interface below ###

2023-08-28 22:35:16,927 - octoprint.plugins.LightControls - DEBUG - SendingLightValues
2023-08-28 22:35:24,351 - octoprint.plugins.LightControls - DEBUG - LightControls pin(12).setValue(37), inverted: False
2023-08-28 22:35:25,030 - octoprint.plugins.LightControls - DEBUG - LightControls pin(12).setValue(17), inverted: False
2023-08-28 22:35:25,132 - octoprint.plugins.LightControls - DEBUG - LightControls pin(12).setValue(4), inverted: False
2023-08-28 22:35:25,182 - octoprint.plugins.LightControls - DEBUG - LightControls pin(12).setValue(17), inverted: False
2023-08-28 22:35:25,234 - octoprint.plugins.LightControls - DEBUG - LightControls pin(12).setValue(4), inverted: False
2023-08-28 22:35:26,437 - octoprint.plugins.LightControls - DEBUG - LightControls pin(13).setValue(19), inverted: False
2023-08-28 22:35:26,491 - octoprint.plugins.LightControls - DEBUG - LightControls pin(13).setValue(42), inverted: False
2023-08-28 22:35:26,538 - octoprint.plugins.LightControls - DEBUG - LightControls pin(13).setValue(61), inverted: False
2023-08-28 22:35:26,587 - octoprint.plugins.LightControls - DEBUG - LightControls pin(13).setValue(42), inverted: False
2023-08-28 22:35:27,067 - octoprint.plugins.LightControls - DEBUG - LightControls pin(13).setValue(34), inverted: False
2023-08-28 22:35:27,154 - octoprint.plugins.LightControls - DEBUG - LightControls pin(13).setValue(0), inverted: False

@Damien0505
Copy link

All fixed!!!

GPIO 12: level=0 fsel=4 alt=0 func=PWM0
GPIO 13: level=0 fsel=4 alt=0 func=PWM1

Changed back the config to dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func2=4
Also installed rpi-hardware-pwm

Many thanks for your assistance! Love the plugin!! :)

@RoboMagus
Copy link
Owner

Ah, very well.

I noticed that only one of the alt functions was actually active: GPIO 13: level=0 fsel=4 alt=0 func=PWM1, but nice to see you've fixed it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants