I am using node-red-node-gpio (version 2.0.6) to control the brightness of a LED that is attached to my raspberry pi 3.
When I set the brightness to a low value (e.g. 6 (6%)) then the LED flickers.
I would not expect this flickering - the LED should appear as it is shining with a constant low brightness.
To complicate matters I am running node-red and RPi.GPIO in a docker container in privileged mode.
My node-red version:
Welcome to Node-RED
===================
30 Sep 10:01:28 - [info] Node-RED version: v3.1.0
30 Sep 10:01:28 - [info] Node.js version: v18.17.1
30 Sep 10:01:28 - [info] Linux 5.10.103-v7+ arm LE
30 Sep 10:01:31 - [info] Loading palette nodes
30 Sep 10:01:38 - [info] Dashboard version 3.6.0 started at /ui
my RPi.GPIO version
31c7c63ab81f:~$ python
Python 3.11.5 (main, Aug 26 2023, 11:59:23) [GCC 12.2.1 20220924] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.VERSION
'0.7.1'
>>>
I don't think the problem is caused due to an overloaded CPU according to top statistics taking in the container shell
node-red-node-pi-gpio uses RPi.GPIO under the hood.
According to it's documentation, it's Software PWM only.
Note that the current release does not support SPI, I2C, hardware PWM or serial functionality on the RPi yet. This is planned for the near future - watch this space! One-wire functionality is also planned.
Although hardware PWM is not available yet, software PWM is available to use on all channels.
The problem with hardware pwm on the RPi is that you need root permission to access the register. Therefore software pwm is mostly used. You can also use a pwm chip pca9685.
You should be able to adjust the permissions to allow the user running Node-RED to have access?
I think that most of us don't recommend using the Pi GPPIO at all unless you really have to. It is supposedly all too easy to release the magic blue smoke on your hard-to-find Pi and access to the GPIO hardware is relatively hard.
If budget allows, the addition of a wired ESP, Arduino or Pi PICO device for a few dollars/pounds/euros can make things a lot more robust.
Also gpiod does not solve @janvda's problem.
I see that the PWM frequency is 100Hz.
This means 1/100Hz = 10ms, which is why the LED is switched on every 9.4ms for 0.6ms (6% duty cycle).
And you see that as flickers.
Try testing at 400Hz or more.
Assure you are running it with option -t 0 otherwise this may break audio (see above comments in this thread).
I ran it as a service so I have to specify the option -t 0 in /etc/systemd/system/pigpiod.service.d/public.conf
run the deamon on the host, not in a docker container. The versions running in docker container seem to give serious problems when the host becomes rebooted (e.g. no network connectivity).
use node-red-node-pi-gpiod (version 0.4.0). I have configured the node as follows
When sending a brightness 7 (7%) I see no more flickering.
When increasing/decreasing the brightness every 100ms I still see some flickering. So it is not completely fixed but it is good enough for me.
Here the load on raspberry pi 3B when it is constantly changing the brightness of the LED.