kelly / node-i2c

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

Problem talking to multiple i2c devices #7

Open mofux opened 11 years ago

mofux commented 11 years ago

Hi,

after the update the i2c address has to be passed to the constructor when initialising a new i2c device. Unfortunately this does not account for talking to multiple i2c devices:

var i2c = require('i2c');
var device1 = new i2c(0x5, {device: '/dev/i2c-0', debug: false});
// imagine device 1 would always return 1 if I read a byte and device 2 would always return 2
device1.readByte(console.log);   // result: 1
var device2 = new i2c(0x6, {device: '/dev/i2c-0', debug: false});
device2.readByte(console.log);   // result: 2
device1.readByte(console.log);   // result: 2 <-- wrong, should be 1

Is this behaviour intended? If so, what would be the correct way to change the i2c address after initialisation?

kelly commented 11 years ago

There is a setAddress method, but I'll change it so that it sets the address before each read and write request. I'll get that in the next version.

mofux commented 11 years ago

I have tested with the new version but the problem still exists. I can see the changes in the i2c.cc file but it doesn't seem to change the address properly. If I do wire.setAddress(..) it is working okay.

kelly commented 11 years ago

Will try a few more things and get a new release out soon.

kelly commented 11 years ago

Maybe fixed now? Still haven't had a chance to test.

MrYsLab commented 9 years ago

Has the latest version been verified to support multiple simultaneous i2c devices?

alexdmejias commented 9 years ago

is there an update to this?

phixMe commented 8 years ago

I am having similar issues. I get a memory leak if I try this:

var device1 = new i2c(0x70, {device: '/dev/i2c-1', debug: false}); var device2 = new i2c(0x70, {device: '/dev/i2c-6', debug: false});

Has anybody had trouble with this?

phixMe commented 8 years ago

I am still having a show stopping bug related to this.

Here is my error: ERROR: (node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit. ERROR: Trace at process.addListener (events.js:160:15) at process.on.process.addListener (node.js:802:26) at new i2c (/home/root/.node_app_slot/node_modules/node-BNO055/node_modules/i2c/lib/i2c.coffee:34:15)

Thanks for looking, any suggestions would be greatly appreciated.