sandeepmistry / node-chip-io

Johnny-Five IO Plugin for the Next Thing Co. C.H.I.P.
MIT License
96 stars 28 forks source link

GPIO 0-7 don't require sudo, eh? #36

Closed Narvey closed 7 years ago

Narvey commented 7 years ago

README.md says that the pins XIO-P0 through XIO-P7 don't require root privileges, but when I try to make a very simple script to use them:

var five = require('johnny-five')
var chipio = require('chip-io')
var board = new five.Board({
    io: new chipio()
})
board.on('ready', function (){
    var doorbell = new five.Button('XIO-P2')
    doorbell.on('down', function() {
        console.log('ding dong')
    })
})

I get the error:

fs.js:640
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: EACCES: permission denied, open '/dev/i2c-0'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at I2C.open (/usr/lib/node_modules/chip-io/lib/i2c.js:15:17)
    at AXP209.open (/usr/lib/node_modules/chip-io/lib/axp209.js:23:13)
    at new ChipIO (/usr/lib/node_modules/chip-io/lib/chip-io.js:66:22)
    at Object.<anonymous> (/home/chip/bin/NodeServer/doorbell.js:5:6)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

This error looks like you are trying to do I2C stuff, but I never asked for that! I just wanted the XIO pins!

fivdi commented 7 years ago

The user running the node process doesn't appear to be a member of group i2c. This is mentioned in the prerequisites section of the readme. Note that the user may need to logout and login again before changes to group membership are visible.

This error looks like you are trying to do I2C stuff, but I never asked for that! I just wanted the XIO pins!

Although the above error message isn't related to the XIO pins, the XIO pins are made available through an I2C PCF8574A 8-bit I/O expander. Accessing the XIO pins will therefore always involve I2C. See page 5 of the schematic.

sandeepmistry commented 7 years ago

@Narvey as @fivdi suggestion please see: https://github.com/sandeepmistry/node-chip-io#prerequisites