node-i2c icon indicating copy to clipboard operation
node-i2c copied to clipboard

Problem talking to multiple i2c devices

Open mofux opened this issue 12 years ago • 8 comments

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?

mofux avatar May 22 '13 18:05 mofux

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.

kelly avatar May 22 '13 19:05 kelly

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.

mofux avatar May 23 '13 18:05 mofux

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

kelly avatar May 23 '13 19:05 kelly

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

kelly avatar Jun 04 '13 03:06 kelly

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

MrYsLab avatar Dec 14 '14 21:12 MrYsLab

is there an update to this?

alexdmejias avatar Aug 02 '15 23:08 alexdmejias

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 avatar Apr 18 '16 20:04 phixMe

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.

phixMe avatar May 18 '16 18:05 phixMe