# Software PWM on RPi

**URL:** <https://discourse.nodered.org/t/software-pwm-on-rpi/51254>\
**Category:** General\
**Created:** [19 September 2021 20:35 UTC](https://discourse.nodered.org/t/software-pwm-on-rpi/51254 "2021-09-19T20:35:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wester.weerdt](https://avatars.discourse-cdn.com/v4/letter/w/f04885/32.png) [@wester.weerdt](https://discourse.nodered.org/u/wester.weerdt)\
**Post date:** [19 September 2021 20:35 UTC](https://discourse.nodered.org/t/software-pwm-on-rpi/51254/1 "2021-09-19T20:35:24Z")

</div>

I'd like to create a node for the Software PWM which supports any GPIO pins and support a fixed frequency(38kHz) and fixed duty cycle(50%).  
In other word, I just need 5~6 GPIO pins that output 38kHz/50% PWM signal.

I have tried pigpiod implementations([node-red-node-pi-gpiod (node) - Node-RED](https://flows.nodered.org/node/node-red-node-pi-gpiod), [GitHub - miketrebilcock/js-pigpio](https://github.com/miketrebilcock/js-pigpio)) but neither works with this specific frequency on any GPIO pin.

Does anyone have a chance to create a software PWM on any GPIO pin?

Regards,  
Wester.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 September 2021 21:02 UTC](https://discourse.nodered.org/t/software-pwm-on-rpi/51254/2 "2021-09-19T21:02:55Z")

</div>

You want to output, on a Pi and under s/w control, a signal that switches every 26 microseconds, to 6 GPIO pins?

If that is possible, which I rather doubt, then node-red will not be involved.

---

<div class="post-metadata">

**Author:** ![wester.weerdt](https://avatars.discourse-cdn.com/v4/letter/w/f04885/32.png) [@wester.weerdt](https://discourse.nodered.org/u/wester.weerdt)\
**Post date:** [19 September 2021 21:14 UTC](https://discourse.nodered.org/t/software-pwm-on-rpi/51254/3 "2021-09-19T21:14:45Z")

</div>

Hi!

Actually, I would like to create a custom node to output 38kHz on a configured pin to control an IR transmitter.

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [19 September 2021 21:17 UTC](https://discourse.nodered.org/t/software-pwm-on-rpi/51254/4 "2021-09-19T21:17:03Z")

</div>

> [@Colin](#):
>
> If that is possible, which I rather doubt, then node-red will not be involved.

I was trying to think of a way to say the same 🙂

@wester.weerdt A node will NOT control the GPIO, it would control the library or custom code that would control the GPIO. You need to figure out that part first.

You might also consider looking at an add-on board with true hardware PWM.

> [@wester.weerdt](#):
>
> fixed frequency(38kHz) and fixed duty cycle(50%)

Is this for a specific IR communication? or general purpose "programmable"

---

<div class="post-metadata">

**Author:** ![wester.weerdt](https://avatars.discourse-cdn.com/v4/letter/w/f04885/32.png) [@wester.weerdt](https://discourse.nodered.org/u/wester.weerdt)\
**Post date:** [19 September 2021 21:19 UTC](https://discourse.nodered.org/t/software-pwm-on-rpi/51254/5 "2021-09-19T21:19:57Z")

</div>

It is just to emit 38kHz, 50% duty cycle signal. 🙂

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [19 September 2021 21:21 UTC](https://discourse.nodered.org/t/software-pwm-on-rpi/51254/6 "2021-09-19T21:21:15Z")

</div>

Then find some way to do that via library, custom code, hardware PWM, etc... then once you have that, and not before, you can make your custom node to control the process.

---

<div class="post-metadata">

**Author:** ![davidz](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@davidz](https://discourse.nodered.org/u/davidz)\
**Post date:** [19 September 2021 21:32 UTC](https://discourse.nodered.org/t/software-pwm-on-rpi/51254/7 "2021-09-19T21:32:31Z")

</div>

What is the highest frequency that you can do with the pigpio node?

You can do 40kHz easily with pigpio in C. The default accuracy is 5us and you need to set 1 us accuracy.

You may write a C program and use EXEC node to do it.

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [19 September 2021 22:47 UTC](https://discourse.nodered.org/t/software-pwm-on-rpi/51254/8 "2021-09-19T22:47:20Z")

</div>

Google for LIRC (Linux Infrared Remote Control) library and how to install it.  
With this lib you can send Ir commands from the command Line and thus with the EXEC node.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 November 2021 22:47 UTC](https://discourse.nodered.org/t/software-pwm-on-rpi/51254/9 "2021-11-18T22:47:28Z")

</div>

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