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

Cannot get pwm demo running #56

Closed LockonS closed 6 years ago

LockonS commented 6 years ago

Node.js version: 10.8.0 pigpio version: 1.1.2 Device: Raspberry Pi 3B+ pigpio C library already installed and started as root. While trying to get demo running, it always output errors as below.

2018-08-05 21:17:28 initInitialise: Can't lock /var/run/pigpio.pid
/root/pi-gpio-trial/node_modules/pigpio/pigpio.js:16
    pigpio.gpioInitialise();
           ^

Error: pigpio error -1 in gpioInitialise
    at initializePigpio (/root/pi-gpio-trial/node_modules/pigpio/pigpio.js:16:12)
    at new Gpio (/root/pi-gpio-trial/node_modules/pigpio/pigpio.js:29:5)
    at Object.<anonymous> (/root/pi-gpio-trial/test.js:3:13)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)

And the demo that I tried to run is

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

const led = new Gpio(17, {mode: Gpio.OUTPUT});

let dutyCycle = 0;

setInterval(() => {
  led.pwmWrite(dutyCycle);

  dutyCycle += 5;
  if (dutyCycle > 255) {
    dutyCycle = 0;
  }
}, 20);

I tried to run the script as pi with sudo or directly run the script as root, but still cannot get it to run properly.

onokje commented 6 years ago

That happens if the gpio is already in use by another process. Maybe you have it running twice? Quit other processes that may use the gpio and try again.

LockonS commented 6 years ago

@onokje Thanks for the reply, but I am pretty sure that this node.js application is the only processess that use the gpio.

fivdi commented 6 years ago

@LockonS please verify that the pigpiod daemon is not running. If the pigpiod daemon is running the pigpio Node.js module can not be run.

LockonS commented 6 years ago

@fivdi Thanks a lot and it works perfectly now. I was so stupid to miss the statement in readme. Maybe highlight this part in readme could save the some others in case I was not the only one to overlock that.

fivdi commented 6 years ago

@LockonS Yes, highlighting the appropriate section of the readme would help here. Thank you for the suggestion.

fixed with db033b544d0bc8672546c765ced3cdd744bb8adb