node-rpio icon indicating copy to clipboard operation
node-rpio copied to clipboard

PWM does not work on startup

Open thomaswelter opened this issue 10 months ago • 0 comments

I've got a bit of a strange situation. At first I was using a single PWM channel which was working fine.

rpio.init({gpiomem: false});
rpio.open(12, rpio.PWM)
rpio.pwmSetClockDivider(8)
rpio.pwmSetRange(12, 1000)
rpio.pwmSetData(12, 100)

Then I tried adding a second PWM channel:

rpio.init({gpiomem: false});
rpio.open(12, rpio.PWM)
rpio.open(35, rpio.PWM)
rpio.pwmSetClockDivider(8)
rpio.pwmSetRange(12, 1000)
rpio.pwmSetData(12, 100)
rpio.pwmSetRange(35, 1000)
rpio.pwmSetData(35, 100)

This was also fine, except on a restart of my pi 3. After a restart of the pi the voltage at the pins stay at 0v (no error). After restarting the process both PWM channels would work again. I tried adding a delay to the process start but that did not make a difference. I ended up with the following code that works even after a restart of the pi:

rpio.init({gpiomem: false});
rpio.open(12, rpio.PWM)
rpio.open(35, rpio.PWM)
rpio.pwmSetClockDivider(8)
rpio.pwmSetRange(12, 1000)
rpio.pwmSetData(12, 100)
rpio.pwmSetRange(35, 1000)
rpio.pwmSetData(35, 100)

// don't know why but I have to init twice
// otherwise the PWM output will be 0v on startup
// restarting will fix it
// it did not do this when only using pin 12 for PWM
rpio.init({gpiomem: false});
rpio.open(12, rpio.PWM)
rpio.open(35, rpio.PWM)
rpio.pwmSetClockDivider(8)
rpio.pwmSetRange(12, 1000)
rpio.pwmSetData(12, 100)
rpio.pwmSetRange(35, 1000)
rpio.pwmSetData(35, 100)

What is happening here?

thomaswelter avatar Mar 18 '25 20:03 thomaswelter