Closed ashishdatta closed 9 years ago
This is super helpful. I think I have one of these sensors, but I have to look. Will post back as soon as I know more things :)
Turns out I have every single other model, but not this one. I should've looked on Sunday, would've been able to order on Monday :(
Doing some research here, and I think that there is nothing wrong with the i2c implementation in Galileo-IO. This sensor requires some finessing of the values it returns. The following is untested, but I believe it should be something like this:
var accel = {
0x53: "ADDRESS",
0x2D: "POWER_CTL",
0x31: "RANGE",
0xB2: "ALL_DATA"
};
/* Shameless stolen from the blinkm tutorial...*/
Object.keys(accel).forEach(function(key) {
// Turn the value into a key and
// the key into an int value
accel[accel[key]] = key | 0;
});
board.on("ready", function() {
var sensitivity = 0.00390625;
// This is required to enable I2C
this.i2cConfig();
// Standby mode
this.i2cWrite(accel.ADDRESS, accel.POWER_CTL, 0);
// Enable measurements
this.i2cWrite(accel.ADDRESS, accel.POWER_CTL, 8);
// Set range (this is 2G range)
this.i2cWrite(accel.ADDRESS, accel.RANGE, 8);
// NOTE: This interval will soon be unnecessary. Upgrades
// the IO plugin i2c read protocol will allow for continuous reads.
setInterval(function() {
// This will read every axis, previously only X was being read.
this.i2cRead(accel.ADDRESS, accel.ALL_DATA, 6, function(data) {
var x = (data[1] << 8) | data[0];
var y = (data[3] << 8) | data[2];
var z = (data[5] << 8) | data[4];
// Wrap and clamp 16 bits;
var X = (x >> 15 ? ((x ^ 0xFFFF) + 1) * -1 : x) * sensitivity;
var Y = (y >> 15 ? ((y ^ 0xFFFF) + 1) * -1 : y) * sensitivity;
var Z = (z >> 15 ? ((z ^ 0xFFFF) + 1) * -1 : z) * sensitivity;
console.log("X: ", X);
console.log("Y: ", Y);
console.log("Z: ", Z);
});
}.bind(this), 1000);
});
That aside, once the Johnny-Five Accelerometer
class is refactored for device profiles, this will all be handled for you.
Ah okay, so as I suspected my I2c knowledge was lacking and led to these errors. Thanks!
No problem! Glad we could get this sorted out :)
Hello I really hope this is the right place for this...I am currently having some issues trying to get this Grove 3-axis accelerometer ADXL345 to work....
My code:
I am getting an output of
Now the weird part is that I am getting these values even when the sensor is unplugged... I know the address is correct because I RTFM ;) Also the i2c bus sees the address:
i2cdetect -y -r 6
The output isI am still pretty new to I2C (yeah Im that bad), but I know that this data has to be faulty....so does anyone think that there is a problem with my code or maybe an issue with Galileo-IO i2c function? really at a loss at the moment again sorry if I am posting this in the wrong place.
PS: My MRAA version
Verison
Also the blinkm example posted under examples worked on my blinkm...