File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -818,9 +818,17 @@ uint8_t TheThingsNode::readMotion(unsigned char REG_ADDRESS)
818
818
819
819
void TheThingsNode::getAcceleration (float *x, float *y, float *z)
820
820
{
821
+ // Resource: https://github.com/sparkfun/MMA8452_Accelerometer/blob/master/Libraries/Arduino/src/SparkFun_MMA8452Q.cpp
822
+ // Read the acceleration from registers 1 through 6 of the MMA8452 accelerometer.
823
+ // 2 registers per axis, 12 bits per axis.
824
+ // Bit-shifting right does sign extension to preserve negative numbers.
821
825
*x = ((short )(readMotion (1 )<<8 | readMotion (2 ))) >> 4 ;
822
826
*y = ((short )(readMotion (3 )<<8 | readMotion (4 ))) >> 4 ;
823
827
*z = ((short )(readMotion (5 )<<8 | readMotion (6 ))) >> 4 ;
828
+
829
+ // Scale 12 bit signed values to units of g. The default measurement range is ±2g.
830
+ // That is 11 bits for positive values and 11 bits for negative values.
831
+ // value = (value / (2^11)) * 2
824
832
*x = (float )*x / (float )(1 <<11 ) * (float )(2 );
825
833
*y = (float )*y / (float )(1 <<11 ) * (float )(2 );
826
834
*z = (float )*z / (float )(1 <<11 ) * (float )(2 );
You can’t perform that action at this time.
0 commit comments