Hello,
I'm looking for a way to insert following terminal commands into NodeRed:
sudo pigpiod
python
import pigpio
pi=pigpio.pi()
pi.hardware_PWM(12, 25000, 1e6*0.25 ) # 25000Hz 25% dutycycle(normaly)
The whole thing is a fan control and the 0.25 are the duty cycle and should be infinitely adjustable.
Can someone help me plz?
Hi,
a) you can't (easily) run a command as sudo as that is a security privilege escalation. so you need to run pigpiod outside of Node-RED. However once you have done that then
b) there is a node-red-node-pi-gpiod that can drive it for most use cases - https://flows.nodered.org/node/node-red-node-pi-gpiod
Hi,
i know this node but i have to run it with the 25khz and there is no option to change it.
If the pigpiod daemon is running then you might be able to set the frequency by calling your exec node using this (not tried but worth a go)
import pigpio
pi=pigpio.pi()
set_PWM_frequency(12, 25000)
NB pigpio doesn't let you choose any frequency value
but is the fan really that sensitive to the frequency?
1 Like
seem not to work.
Another idea:
A Pythonscript with a variable (DutyCycle), but also there I do not know yet really how I should convert it...
Just checking - what physical pin is your fan connected to
Node-RED uses physical pin numbers so if your connected to pin 12 then you need to use
set_PWM_frequency(18, 25000)
as physical pin 12 is gpio number 18
Just tried it out on a PiZero and it seems to work - with correct syntax that is
I created a file called fred.py
and stuck this in it
import pigpio
pi=pigpio.pi()
pi.set_PWM_frequency(18, 25000)
And injected value of 25 into the pigpio node
I've put an LED on the pin and it glowed as expected
I then changed the fred.py to
import pigpio
pi=pigpio.pi()
pi.set_PWM_frequency(18, 5)
and this time the LED blinked rapidly
So I think that proves the concept is good
Well it doesn't work for me. I get the following error message from exec:
11.8.2019, 21:22:47node: ac7e4461.29989msg.payload : string[0]
""
11.8.2019, 21:22:47node: ac7e4461.29989msg.payload : string[144]
"Traceback (most recent call last):↵ File "/home/pi/scripts/test.py", line 2, in <module>↵ import pigpio↵ImportError: No module named pigpio↵"
11.8.2019, 21:22:47node: ac7e4461.29989
msg.payload : Object
{ code: 1, message: "Command failed: python /home/p…" }
pigpio is runnig cause pigs hp 12 25000 500000 works but the python part dont.
>>> import pigpio
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pigpio
I'm a bit confused
Do you get same error if your run
python /home/pi/scripts/test.py
from plain terminal command line?
Gummix
11 August 2019 19:34
11
yes
pi@octopi:~ $ python /home/pi/scripts/test.py
Traceback (most recent call last):
File "/home/pi/scripts/test.py", line 2, in <module>
import pigpio
ImportError: No module named pigpio
That IS wierd
Luckily you can directly call pigs
(My LED is on pin 12 - gpio 18)
1 Like
Gummix
11 August 2019 19:51
13
Hello,
yeah, that's what I'm playing with right now.
All I have to do now is figure out how to get a number from the inject block into the output.
So I would have to
pigs have hp 12 25000 500000 where the 50000 should come from an input.
You can use incoming msg.payload and get it added onto the end
Just make sure to add the space at the end
Gummix
11 August 2019 20:04
15
Gummix:
pigs hp 12 25000 500000
Ah ok, Thanks it works xD
2 Likes