fivdi / pigpio

Fast GPIO, PWM, servo control, state change notification and interrupt handling with Node.js on the Raspberry Pi
MIT License
948 stars 89 forks source link

Error when calling pwmWrite() #75

Closed ralphhughes closed 5 years ago

ralphhughes commented 5 years ago

I'm trying to write a motor controller for a servomotor with optical encoder and I'm getting this error sporadically. I can't pin down what's causing it as I can't reproduce it every time. Any idea where I should start to look?

pigpio/pigpio.js:98
    pigpio.gpioPWM(this.gpio, +dutyCycle);
           ^

Error: EINVAL, Invalid argument
    at Gpio.pwmWrite
fivdi commented 5 years ago

dutyCycle must be an unsigned 32-bit integer. When calling pwmWrite be sure to pass an unsigned 32-bit integer rather than a number. A number can be converted to an unsigned 32-bit integer with the right-shift operator. Use something like this:

gpio.pwmWrite(dutyCycle >> 0);
ralphhughes commented 5 years ago

That appears to have fixed it so far, many thanks for your accurate and timely response.

fivdi commented 5 years ago

That's good news. Thanks for the feedback.