kelly / node-i2c

Node.js native bindings for i2c-dev. Plays well with Raspberry Pi and Beaglebone.
Other
216 stars 91 forks source link

string_decoder.js Error when creating i2c connection #12

Closed pandringa closed 10 years ago

pandringa commented 11 years ago

I'm trying to get your module working, but I have a problem... Just to test it, I'm using a simple test file that goes

var i2c = require("i2c");
var connection = new i2c(0x40, {device: '/dev/i2c-1', debug: true});

But when I run the script with node, I get an error like this https://gist.github.com/pandringa/6281910

What is the problem here? I'm using node 0.10.0, and I just installed your library a few minutes ago, so I know its not old. Thanks for your help, Peter

mofux commented 11 years ago

I think I have seen this error before and it has been down to a change introduced in node v0.10.0. I think they fixed it a few versions later. Have you tried upgrading to node v0.10.16?

pandringa commented 11 years ago

So I tried your suggestion, and it worked for a short amount of time (maybe three times), but now it doesn't work again. I'm still getting the same error, even though my node version is 0.10.16. One thing though: I noticed that it does connect if I say

var connection = new i2c(0x40);

instead of

var connection = new i2c(0x40, {device: '/dev/i2c-1', debug: true});

However, I'm not sure thats the right solution, because reading/writing may not work correctly. I haven't tested it out yet.

kelly commented 11 years ago

It appears to be something with repl. As long as debug is false, it should work.

pandringa commented 11 years ago

Ok, thanks!

mrutgerj commented 10 years ago

First off, thanks for coding the library.

I can confirm this as a bug on node version v10.9. Using Raspberry Pi, rev2. It is caused by line 30 in i2c.coffee:

process.stdin.emit('data', 1);

When I turned debug to false, it reported the same error. When I used:

var connection = new i2c(address);

The problem went away.

But, it did not set the address correctly, and threw an error, from line 49 in the same file:

return wire.scan(function(err, data) {

Using the address directly in the function call didn't change anything. I tried a binary of node 10.21 and that didn't change anything. I'll have to poke around more, but this is a separate bug from this topic.

EDIT: set address error was a permissions problem, add your user to group i2c on the Pi.