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

Unable to use package #135

Closed Zebiano closed 3 years ago

Zebiano commented 3 years ago

Hey! I'm currently facing the following issue:

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

const button = new Gpio(23, {
  mode: Gpio.INPUT,
  pullUpDown: Gpio.PUD_UP,
  alert: true
});

yields the following error:

 mode: Gpio.INPUT,
             ^

TypeError: Cannot read property 'INPUT' of undefined

console.log(Gpio) returns undefined. Any idea as to why this is happening?

I'm using a Raspberry Pi 4 with Ubuntu Server 21.04 and Node 14.17.3. I've installed the pigpio C library, but I had to make it, as sudo apt-get install pigpio gave me an E: Package 'pigpio' has no installation candidate error. Running pigpiod -v results in 79. I'm also running Node with sudo, since that is apparently a requirement, and I did run npm i, as well as sudo npm i.

Any help is greatly appreciated!

Zebiano commented 3 years ago

Turns out I was an idiot and required the package wrongly... Instead of

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

It should be be:

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

This happened because I usually don't use PascalCase, but instead camelCase, so I blindly replaced every Gpio entry to gpio.

Sorry for wasting an issue on this. It works now, I'm able to read data through the GPIO pins on the Raspberry Pi, thank you!