Dynamic PWM Frequency?

I am trying to create a test jig to drive a RPM sensor and I need to take the RPM value and divide it by 2.82 and toggle a rpi GPIO pin that number of times a second.

The GPIO node in PWM mode will honor the set frequency value, however it will not accept it as a message input.

Add a debug node showing what you are sending to the gpio node and post the output here.

Here's my flow:

[{"id":"7175d55.5e6142c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"9166b787.249cc8","type":"calculator","z":"7175d55.5e6142c","name":"Calculate Generator R terminal value","inputMsgField":"payload","outputMsgField":"frequency","operation":"div","constant":"2.82","round":true,"decimals":0,"x":350,"y":180,"wires":[["3272a7d2.5495e8"]]},{"id":"82ef93d.b682e7","type":"ui_slider","z":"7175d55.5e6142c","name":"","label":"slider","tooltip":"","group":"66629d30.efc514","order":0,"width":0,"height":0,"passthru":true,"outs":"all","topic":"topic","topicType":"msg","min":0,"max":"2400","step":"25","x":330,"y":80,"wires":[["b243462b.3487a8","1f25c30d.bc5c5d","9166b787.249cc8"]]},{"id":"1f25c30d.bc5c5d","type":"ui_gauge","z":"7175d55.5e6142c","name":"Current RPM","group":"66629d30.efc514","order":5,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{value}}","min":0,"max":"2400","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":530,"y":80,"wires":[]},{"id":"b243462b.3487a8","type":"debug","z":"7175d55.5e6142c","name":"RPM Setting","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":40,"wires":[]},{"id":"c799f521.3a7388","type":"debug","z":"7175d55.5e6142c","name":"PWM Inputs","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":260,"wires":[]},{"id":"2c6fd8ae.8bcae8","type":"inject","z":"7175d55.5e6142c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":90,"y":60,"wires":[["82ef93d.b682e7"]]},{"id":"62c1bc63.dd39a4","type":"inject","z":"7175d55.5e6142c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"600","payloadType":"num","x":90,"y":100,"wires":[["82ef93d.b682e7"]]},{"id":"94bec17c.5e77a","type":"inject","z":"7175d55.5e6142c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1800","payloadType":"num","x":90,"y":140,"wires":[["82ef93d.b682e7"]]},{"id":"b301b983.60d478","type":"rpi-gpio out","z":"7175d55.5e6142c","name":"PWM GPIO12","pin":"32","set":"","level":"0","freq":"","out":"pwm","x":540,"y":320,"wires":[]},{"id":"3272a7d2.5495e8","type":"change","z":"7175d55.5e6142c","name":"Set PWM 50% duty cycle","rules":[{"t":"set","p":"payload","pt":"msg","to":"50","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":280,"wires":[["c799f521.3a7388","b301b983.60d478"]]},{"id":"66629d30.efc514","type":"ui_group","name":"RPM Testing","tab":"de246fc6.c97b5","order":1,"disp":true,"width":"6","collapse":false},{"id":"de246fc6.c97b5","type":"ui_tab","name":"Testing","icon":"dashboard","order":7,"disabled":false,"hidden":false}]

Here's the debug output:

{"_msgid":"bbcdd507.8e73e8","payload":50,"topic":"","frequency":213}

Whart do you mean by that? It you look at the GPIO node, you will see '50' under it.

The value 50 is the percentage of the duty cycle, not the frequency which only has a static configuration on the node:

Looks like you are using to high a value. Notice what the Help says:

rpi-gpio out

Raspberry Pi output node. Can be used in Digital or PWM modes.

Inputs

payload number | string | boolean

Details

Digital mode - expects a msg.payload with either a 0 or 1 (or true or false), and will set the selected physical pin high or low depending on the value passed in.

The initial value of the pin at deploy time can also be set to 0 or 1.

PWM mode - expects an input value of a number 0 - 100. It can be floating point.

PWM mode can be used to drive a servo using input values between 10 and 20 only, but will accept floating point values. The GPIO2 pin is best for this as it uses hardware to do the PWM. For better servo support consider the alternative node-red-node-pi-gpiod node.

Requires the RPi.GPIO python library version 0.5.10 (or better) in order to work.

Well obviously I am using the wrong kind of node.

How can I toggle a GPIO pin X times a second on a Raspberry Pi?

My desired range is 213 to 833 HZ..

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.