I'd like to generate 38kHz & 50% duty cycle PWM signals on multiple GPIO pins. Hence hardware PWM won't work for me.

Does anyone have a chance to generate this signal by using python or node.js?

Tried python RPI.GPIO library to generate manually, but the maximum frequency seems ~8kHz.


You can use pigpio waves to generate PWM at 38 kHz on multiple GPIO simultaneously.

You can do this using the pigpio Python module and there are wrappers for node.js.

There are several relevant examples, e.g.



Ok, I was able to use this library to generate waveforms:

const pigpio = require('pigpio');
const Gpio = pigpio.Gpio;

const outPin = 21;

const output = new Gpio(outPin, {mode: Gpio.OUTPUT});

while (true){
  let waveform = [];

  for (let x = 0; x < 200; x++) {
    if (x % 2 === 1) {
      waveform.push({ gpioOn: outPin, gpioOff: 0, usDelay: 13 });
    } else {
      waveform.push({ gpioOn: 0, gpioOff: outPin, usDelay: 13 });


  let waveId = pigpio.waveCreate();

  if (waveId >= 0) {
    pigpio.waveTxSend(waveId, pigpio.WAVE_MODE_ONE_SHOT);
  } else {

    while (pigpio.waveTxBusy()) {}
  catch (err){
    throw err;

NOTE: The problem is that the accuracy of the wave length is 1µs, hence my oscilloscope says that the frequency of the generated signal is 38.45kHz.

  • Yes, I should have mentioned that the resolution is 1 µs. However that is not a problem for IR transmitters or receivers.
    – joan
    Sep 20 '21 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.