-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using I2C functions #28
Comments
From @colinbes on July 1, 2014 19:48 I am needing to periodically scan a particular i2c device (monitoring for powerfail). Per my above question I have call to i2cOpen just before i2cReadBytes in timer function. On running the code for a short period of time I get
Full error message
Appreciate your help. |
From @Findus1 on September 16, 2014 11:16 I'm having the same problem. Did you find a solution? var b = require('bonescript');
var port = '/dev/i2c-1';
for(var i = 0; i< 11; i++){
b.i2cOpen(port, 0x70, {});
} This produces a warning after 11 loops. |
From @Findus1 on September 16, 2014 11:30 An update to that last post: it's not okay to just handle the warning. var b = require('bonescript');
var port = '/dev/i2c-1';
for(var i = 0; i< 10000; i++){
b.i2cOpen(port, 0x70, {});
console.log("handles:", i);
} Note that putting delays between i2cOpen() functions does not fix it. |
From @Findus1 on September 16, 2014 16:1 If anyone else is banging up against this issue, the solution I found is to directly use the i2c library that Bonescript uses for i2c: var wire = new i2c(LED_ADDRESS, {device : '/dev/i2c-2'}); and write bytes to an address on it wire.writeBytes(LED_BRIGHTNESS_ADDRESS, [0xFF], function(err) {}); as a bonus, it also numbers the i2c devices properly, so where Bonescript calls i2c-2 "i2c-1", the Kelly I2C library calls it "i2c-2" |
From @colinbes on September 16, 2014 16:39 I have yet to find a solution, presently in order to move forward I am using an exec call to read i2c but would much prefer to not have to do this. I did try to use the i2c library but didn't come right. How did you install and require i2c - I recall having an issue with one of these steps. I actually prefer i2c implementation as the i2c object, 'wire' in your code above is bound to a physical device - I think this is much safer. |
From @Findus1 on September 16, 2014 19:4 To install i2c, I followed the Beaglebone installation instructions on NPM. Like you, I also prefer the way i2c binds each instance to a device object. It is better than the way Bonescript's "open" command needs to be called before each device access (which means that if you are addressing several devices, you very soon exceed 11 "opens" to cause a warning, and eventually it crashes after 1012) It's worth noting that the NPM i2c library also causes a warning when you create more than 11 devices - but unlike Bonescript, you don't need to open a new instance each time you send to a different device, because you can reuse device objects. If anyone knows how to get around the 11 device limit in the i2c library, I'd like to know how. var b = require('bonescript');
var i2c = require('i2c');
b.i2cOpen('/dev/i2c-1', DEVICE_ADDRESS, {}); //needed to open the cape manager port
var wire = new i2c(DEVICE_ADDRESS, {device : '/dev/i2c-2', debug: false});
//note that Bonescript's '/dev/i2c-1' == i2c's '/dev/i2c-2' |
From @colinbes on July 1, 2014 19:11
Maybe I am misunderstanding correct usage of I2C functions provided by bonescript but from what I understand, the correct usage is along the lines of
I assume the thinking is that the ReadBytes is always preceded by the i2cOpen function within the same function scope. If the i2cOpen function was, for example, in static part of code, and the ReadBytes was in a function then you could end up with wrong results.
Example.
In this case if any other function anywhere called i2cOpen and then you called func1() you'd be reading bytes of the last i2cOpen function.
Is there a way to use these functions similar to the way it is used in i2c which is basis for bonescript i2c functions? Where method returned by i2cOpen is used as 'parent' (sorry, can't think of right word to use) to ReadBytes call?
Just looking for direction, thanks
Copied from original issue: jadonk#90
The text was updated successfully, but these errors were encountered: