Closed robyoung closed 3 years ago
Hmm, interesting. Could it be that the measurements were taken too quickly (i.e. before the mode change took effect)? Being in one-shot mode, I assume the delay should be the turn-on delay detailed in the 4.2.1 section of the datasheet. Could you add some delays and try again?
I have done a bit of reading through other drivers to better understand things and I think I misunderstood the datasheet. This chunk of code from SodaqMoja/Sodaq_LSM303AGR scales even the +/-2g factor back up when in normal or low power modes. I now realise that the right most column of the table below is talking about the number after applying the resolution factor.
So the raw result is divided by a higher resolution factor for the lower power modes to blank out the least significant bits because they are not significant for lower resolutions. But the number still has to be scaled back up again to get a valid mg value.
Given this I'm not sure how useful the unscaled value is. I think I have enough information now to have a stab at a PR though.
Hmm, interesting. Could it be that the measurements were taken too quickly (i.e. before the mode change took effect)? Being in one-shot mode, I assume the delay should be the turn-on delay detailed in the 4.2.1 section of the datasheet. Could you add some delays and try again?
The example has 1s delays after each mode change and then takes three measurements to try and ensure the value is stable.
Ah, thanks I missed that reading it now as well. As a hint, if you prepare a PR, I would suggest a macro for the tests to avoid repeating the code for all combinations.
Scaling addressed in #5
I am using this library on micro:bit (tested on a V1.5 and V2) and getting some confusing readings when experimenting with different
AccelMode
values.When I change the
AccelMode
I get different values for the readings. My understanding of theresolution_factor
used here is that it accounts for the different number of bits used in each operating mode (described in 4.2.1 of the datasheet).It looks as though the
HighResolution
data is correct (Z is approximately equal to 1000mg). This is what I would expect from the datasheet. However, it looks as though theNormal
andLowPower
data is also being returned the same and then getting sent off by thereslution_factor
.Example code
The full example, working on the V1.5 or V2 micro:bit, can be found here. Run it with
The main logic of the example is also copied below for convenience.
And the output I get (with the data being written to the registers)