Finally the board arrived a week later than expected. I also ordered an ESP32 board which required using a for profit shipping company instead of the post office for some reason. They shipped it from Colorado to Chicago and then mailed it to the suburbs.
The pony express would have been faster.
Problems encountered when implementing the I2C interface:
LSM9DS1.prototype.xgReadBytes=function(subAddress,count){
var dest= new Uint8Array(count);
// console.log("xgReadBytes ",this.xgAddress, subAddress|0x80, dest, count);
var x=this.xgAddress;
this.i2c.writeTo(x, subAddress|0x80);
dest=this.i2c.readFrom(x, count);
// for(var i=0;i<count;i++)console.log(dest[i]);
return dest;
};
LSM9DS1.prototype.mReadBytes=function(subAddress,count){
// console.log("mReadBytes ",this.mAddress, subAddress|0x80,count);
var x=this.mAddress;
var dest=new Uint8Array(count);
this.i2c.writeTo(x, subAddress|0x80);
dest=this.i2c.readFrom(x, count);
// for(var i=0;i<count;i++)console.log(dest[i]);
return dest;
};
Notice the var x=this.address.
If this.address was used in the this.i2c.ReadFrom() function timeout errors occurred.
I tried to create a simplified version of the problem but have not succeeded in reproducing the error.
For reads of multiple bytes bit 7 of the sub-address is set to 1.
LSM9DS1.prototype.readAccel=function(){
var temp=this.xgReadBytes(Regs.OUT_X_L_XL, 6); // Read 6 bytes, beginning at OUT_X_L_XL
this.ax=this.twos_comp(temp[0],temp[1]);
this.ay=this.twos_comp(temp[2],temp[3]);
this.az=this.twos_comp(temp[4],temp[5]);
/*
this.ax = (temp[1] << 8) | temp[0]; // Store x-axis values into ax
this.ay = (temp[3] << 8) | temp[2]; // Store y-axis values into ay
this.az = (temp[5] << 8) | temp[4]; // Store z-axis values into az
*/
if (_autoCalc)
{
ax -= aBiasRaw[X_AXIS];
ay -= aBiasRaw[Y_AXIS];
az -= aBiasRaw[Z_AXIS];
}
};
LSM9DS1.prototype.twos_comp=function(low,high){
var t=(high << 8) | low;
return(t & 0x8000 ? t - 0x10000 : t);
};
The values returned are in two’s compliment.
LSM9DS1.prototype.readTemp=function(){
//void LSM9DS1::readTemp(){
// We'll read two bytes from the temperature sensor into temp
var temp=this.xgReadBytes(Regs.OUT_TEMP_L, 2); // Read 2 bytes, beginning at OUT_TEMP_L
// console.log("TT= ",temp[0].toString(16),temp[1].toString(16));
this.temperature = temp[1];//(temp[1] << 8) | temp[0];
//temperature = ((int16_t)temp[1] << 8) | temp[0];
//https://gist.github.com/jimblom/08b333892ee383d6e443
//temperature = (((int16_t) temp[1] << 12) | temp[0] << 4 ) >> 4; // Temperature is a 12-bit signed integer
//var t= (((temp[1]^0xf)<<12)|temp[0])>>4;
//this.temperature=(t & 0x8000 ? t - 0x10000 : t);
};
There is quite a bit of discussion on the web about reading the temperature.
Having tried various solutions, I’m still not sure it is working properly.
The file TestLSM9DS1_d.js is attached.
Some sample output:
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
LSM9DS1
Finally the board arrived a week later than expected. I also ordered an ESP32 board which required using a for profit shipping company instead of the post office for some reason. They shipped it from Colorado to Chicago and then mailed it to the suburbs.
The pony express would have been faster.
Problems encountered when implementing the I2C interface:
Notice the var x=this.address.
If this.address was used in the this.i2c.ReadFrom() function timeout errors occurred.
I tried to create a simplified version of the problem but have not succeeded in reproducing the error.
For reads of multiple bytes bit 7 of the sub-address is set to 1.
The values returned are in two’s compliment.
There is quite a bit of discussion on the web about reading the temperature.
Having tried various solutions, I’m still not sure it is working properly.
The file TestLSM9DS1_d.js is attached.
Some sample output:
The readall function:
1 Attachment