Contents
3. Warp7 Sensors demo - mpl3115a2
4. Warp7 Sensors demo - fxos8700cq <-- You are here
In this guide we will explore warp7 accelerometer and magnetometer functionality.
The write_register and read_register functions from the previous blog can remains same.
The FXOS8700CQFXOS8700CQ is small low-power sensor in warp7warp7 that integrates a 3-axis 14-bit accelerometer and a 3-axis 16-bit magnetometer in a single package.
Scenarios where FXOS8700CQ sensor can be used to monitor:
- orientation sensing.
- freefall detection.
- transient detection.
- motion inputs(ex: games and pedometers)
- magnetic pole detection
- underground exploration like drilling and mining.
fxos8700 is located at the i2c address 0x1E.
WHO_AM_I
Probing the WHO_AM_I register located at 0x0D gives a value hex value C7.
WHO_AM_I register is used to identify the type of sensor hardware.
$ i2cget -y 3 0x1E 0x0D
0xc7
reading WHO_AMI_I register programatically using the i2c functions.
read_register(file, 0x1E, 0x0D, <BUFFER_ADDRESS>)
Activating FXOS8700CQ
FXOS8700 needs to be set to active mode prior to using it.
The bit0 of register CTRL_REG1 sets the sensor to active mode.
So, we write 0x01 to the 0x2A(CTRL_REG1) register.
write_register(file, 0x1E, 0x2A, 0x01)
Fast Read Mode:
In some real time scenarios you have to read data as an extremely fast rate.
Fortunately the sensor has a built in support for a Fast Read mode.
The bit1 needs to be activated alongwith bit0 by writing 0x03 to CTRL_REG1 .
Note: this mode will give you only the 8bit MSB data, so you might miss some exact precision here, a trade-off.
write_register(file, 0x1E, 0x2A, 0x03)
Enabling accelerometer & magnetometer
with FXOS8700 in active mode, we need to enable the accelerometer and magnetometer also.
The M_CTRL_REG1 register needs to be configured.
So, we write 0x03 to the 0x5B(M_CTRL_REG1) register.
write_register(file, 0x1E, 0x5B, 0x03)
Registers to read data from..
we are interested in below registers:
0x01 – read x-axis MSB data (8 bits 0:7)
0x02 – read x-axis LSB data (6 bits 2:7)
0x03 – read y-axis MSB data (8 bits 0:7)
0x04 – read y-axis LSB data (6 bits 2:7)
0x05 – read z-axis MSB data (8 bits 0:7)
0x06 – read z-axis LSB data (6 bits 2:7)
we will read the LSB & MSB and store in two variables.
read_register(file, 0x1E, 0x01, &data1)
read_register(file, 0x1E, 0x02, &data2)
Next we need to convert the X,Y,Z axis readings to usable data by applying some changes.
for X axis:
val1 = (int)data1;
val1 <<=8;
val2 = (int)data2;
x_value = val1 | val2;
implementing the similar conversions for Y & Z axis.
Retrieving sensor values from magnetometer
we are interested in below registers:
0x33 – read x-axis MSB data (16 bits)
0x34 – read x-axis LSB data (16 bits)
0x35 – read y-axis MSB data (16 bits)
0x36 – read y-axis LSB data (16 bits)
0x37 – read z-axis MSB data (16 bits)
0x38 – read z-axis LSB data (16 bits)
Similarly we need to read the LSB & MSB and store in two variables later use.
read_register(file, 0x1E, 0x33, &data1)
read_register(file, 0x1E, 0x34, &data2)
Check in terminal the values of accelerometer while performing Pitch, Roll and Yaw.
In terminal the y-value of magnetometer will be zero while pointed to North.