Datasheet Help - LSM9DS1

Hello,

I am working on a IoT project and have everything done BUT 1 conversion. It is really driving me mad.

Quick preface, I need to read the ambient temperature in celsius from this 9DOF board (LSM9DS1). I know that the board was not designed for accurate temperature. I don't need accuracy I just need to be able to put a flame, finger, or blowdryer on it and see the temperature climb. I am having a really hard time figuring out this conversion. I can't tell if the board is giving me bad data or if my conversion is wrong. Whats worse, I need to do this is Node.js.

What is the conversion formula for this sensor in NodeJS?

function convert(word) {
    return celsius
}

I am reading 1 word from 0x15
Here are some pictures from the datasheet.
Any help is welcomed.

It looks like you need to read the other register too. If you're only getting 0x15, you're missing the high bits.

An Arduino is programmed in C++. Nodejs, is that something to do with javascript? If so, it has no obvious link with Arduinos - where does the Arduino come in play in this project?

wildbill, I am reading a word. The function is something like i2c_bus.readWord(address, register). Word is 2 bytes. It should read low and high together. I can read each byte too. Either works for me. Its the whole "right justified" "2s complement" conversion that confuses me. I did take a low level assembly course but its been a while and I forget. The closest I have gotten is (sudo code)...

read(0x15) => low
0101 0101 --> 85

read(0x16) => high
1111 1111 --> 255

"Right justified" so LSB on the right?

low & high together => (high, low)
1111111101010101 --> 65365

2s complement
-171?


wvmarle, this is indeed not for a arduino but for a raspberry pi. I figured with forum would still be a good resource as I am asking about the conversion which should be similar regardless of language.

On an Arduino, in C++, I'd do something like:

uint16_t result = read(0x16) << 8 | read(0x15);

to combine two bytes into a single 16-bit unsigned integer. Note that this works in part as the Arduino's C++ compiler defaults to 16-bit width. Other compilers may behave differently, and on an Arduino you have to be careful doing this with values greater than two bytes.

wvmarle,

So that is exactly how I also do it in C++. Does that method handle the "2s Compliment" aspect as well? I might just be able to import a low-level library into my Node.js project that simulates uint16_t.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.