IIM42652¶
This module contains the I2C driver for IIM-42652 6-axis SmartIndustrial™ MotionTracking device that supports an extended operating temperature range. The IIM-42652 combines a 3-axis gyroscope (up to ±2000 degrees/sec), and a 3-axis accelerometer (up to ±16g) and features a 2K-byte FIFO that can lower the traffic on the serial bus interface and reduce power consumption by allowing the system processor to burst read sensor data and then go into a low-power mode.
class IIM42652¶
IIM42652(drv=I2C0, addr=0x69, clk=1000000)
drvis the I2C drive to use. Default isI2C0;addris the I2C address of the device. Default is0x69;clkis the I2C clock speed to use. Default is1000000.
method soft_reset¶
soft_reset()
method set_drive¶
set_drive(i2c_sr)
DRIVE_CONFIG on IIM-42652 datasheet. i2c_sris the desired I2C slew rate.
method setup¶
setup()
method get_temp¶
get_temp()
method get_accel_x¶
get_accel_x(raw=False)
True, the pre conversion value is returned. method get_accel_y¶
get_accel_y(raw=False)
True, the pre conversion value is returned. method get_accel_z¶
get_accel_z(raw=False)
True, the pre conversion value is returned. method get_gyro_x¶
get_gyro_x(raw=False)
True, the pre conversion value is returned. method get_gyro_y¶
get_gyro_x(raw=False)
True, the pre conversion value is returned. method get_gyro_z¶
get_gyro_x(raw=False)
True, the pre conversion value is returned. method set_pwr_cfg¶
set_pwr_cfg(acc, gyro, idle=0, tmp=0)
PWR_MGMT0 on IIM-42652 datasheet. -
accis the accelerometer power configuration. Reset value is0b00.accMode 0b00 Off 0b01 Off 0b10 Low Power 0b11 Low Noise -
gyrois the gyroscope power configuration. Reset value is0b00.gyroMode 0b00 Off 0b01 Off 0b10 Low Power 0b11 Low Noise -
idleset to1to keep the RC Oscillator always on. Default value is0, reset value is0. -
tmp_disset to1to disable the temperature sensor. Default value is0, reset value is0.
method set_accel_cfg¶
set_accel_cfg(odr, fs)
ACCEL_CONFIG0 on IIM-42652 datasheet. -
odris the Output Data Rate. Reset value is0b0110(32 kHz). possibleodrvalues are:odrValue [Hz] 0b000132000 0b001016000 0b00118000 0b01004000 0b01012000 0b01101000 0b0111200 0b1000100 0b100150 0b101025 0b101112.5 0b11006.25 0b11013.125 0b11101.5625 0b1111500 -
fsis the Full Scale. Reset value is0b000(±16 g). possiblefsvalue are:fsValue [g] 0b000± 16 0b001± 8 0b010± 4 0b011± 2
method set_gyro_cfg¶
set_gyro_cfg(odr, fs)
GYRO_CONFIG0 on IIM-42652 datasheet. -
odris the Output Data Rate. Reset value is0b0110(32 kHz). possibleodrvalues are:odrValue [Hz] 0b000132000 0b001016000 0b00118000 0b01004000 0b01012000 0b01101000 0b0111200 0b1000100 0b100150 0b101025 0b101112.5 0b1111500 -
fsis the Full Scale. Reset value is0b000(±2000 degrees/sec). possiblefsvalue are:fsValue [dps] 0b000± 2000 0b001± 1000 0b010± 500 0b011± 250 0b100± 125 0b101± 62.5 0b110± 31.25 0b111± 15.625 ### method set_fifo_cfg set_fifo_cfg(accel_en, gyro_en, tmp_en=False, tmst_en=False, hires_en=False, wm_gt_th=False, res_rd=False)Set the fifo configuration to select data saved on the fifo. For additional information, see register FIFO_CONFIG1on IIM-42652 datasheet. -
accel_enif set toTrueallows accelerations data of the 3-axis to go to the fifo. -
gyro_enif set toTrueallows gyro data of the 3-axis to go to the fifo. -
tmp_enif set toTrueallows temperature data to go to the fifo. DefaultFalse. -
tmst_enif set toTrueallows time stamp data to go to the fifo. DefaultFalse. -
hires_enif set toTrueenable the high resolutions data on the fifo. DefaultFalse. -
wm_gt_thif set toTrueenables fifo watermark on every ODR if data on fifo are over watermark. DefaultFalse. -
res_rdif set toTrueallows partial read from the fifo. Reading again will resume from the last byte read. DefaultFalse
method fifo_cnt¶
fifo_cnt()
method set_fifo_mode¶
set_fifo_mode(mode)
FIFO_CONFIG on IIM-42652 datasheet. -
modeis the mode of the fifo. Reset value is0b00.modeMode 0b00 Bypass 0b01 Stream-to-FIFO 0b10 STOP-on-FULL 0b11 STOP-on-FULL
method handle_fifo¶
handle_fifo(buf, raw=False)
raw is set to True, the raw data will be returned. bufis the buffer to get the first packet from.
Return a tuple with the following fromat. ( n_bytes, header, measure_1, measure_2, ..., measure_n)
-
n_bytesnumber of bytes that contained the packet. -
headeris the header of the packet. -
measure_#are the measures, depending on the fifo configuration.
method set_fsync_cfg¶
set_fsync_cfg(pol, ui_clear_flag, ui)
FSYNC_CONFIG on IIM-42652 datasheet. -
polis the polarity of the fsync pulse. -
ui_clear_flagif set to1fysnc flag is cleared when ui sensor register is updated. -
uiselect the fysnc flag tag.
method get_fifo¶
get_fifo(n)
n bytes from the fifo. nis the number of bytes to get from the fifo.
Returns a bytearray with n bytes.
method set_signal_path¶
set_signal_path(fifo_flush, tmst_strobe, abort_n_reset, dmp_mem_rst=False, dmp_init_en=False)
SIGNAL_PATH_RESET on IIM-42652 datasheet. -
fifo_flushif set toTruethe fifo is flushed. -
tmst_strobeif set toTruetime stamp counter is latched into time stamp register. -
abort_n_resetif set toTruesignal path is reset an ODR restarted. -
dmp_mem_rstif set toTruethe DMP memory is reset. DefaultFalse. -
dmp_init_enif set toTruethe DMP memory is enabled. DefaultFalse.
method set_fifo_decimation¶
set_fifo_decimation(dec)
5 only one data over 5 will be stored on the fifo. decis the decimation to set. Range 0-127.
method set_fifo_wm¶
set_fifo_wm(wm)
wmis the watermark value to set.
method set_int_cfg¶
set_int_cfg(int_pin, mode, drive, polarity)
INT_CONFIG on IIM-42652 datasheet. -
int_pinis the pin of IIM42652 to configure. -
modeis the mode of the interrupt.0for pulsed,1for latched. -
driveis the drive configuration.0open drain,1push pull. -
polarityis the polarity of the pin.0active low,1active high.
method set_int_sources¶
set_int_sources(int_pin, fifo_full, fifo_ths, ui_acg_rdy=False, ui_drdy=False, reset_done=False, pll_rdy=False, ui_fsync=False)
INT_SOURCE0 on IIM-42652 datasheet. -
int_pinis the pin of IIM42652 to configure. -
fifo_fullif set toTrueinterrupt is triggered when fifo is full. -
fifo_thsif set toTrueinterrupt is triggered when fifo watermark is reached. DefaultFalse. -
ui_acg_rdyif set toTrueinterrupt is triggered if UI AGC is ready. DefaultFalse. -
ui_drdyif set toTrueinterrupt is triggered if UI data are ready. DefaultFalse. -
reset_doneif set toTrueinterrupt is triggered if reset is completed. DefaultFalse. -
pll_rdyif set toTrueinterrupt is triggered if PLL is ready. DefaultFalse. -
ui_fsyncif set toTrueinterrupt is triggered if UI fsync is triggered. DefaultFalse.
method get_int_status¶
get_int_status(get_list=False)
INT_STATUS on IIM-42652 datasheet. get_listif set toTruethe interrupt status is returned as a list. The list members correspond to the related bit in the status register. E.g.: element0is the bit 0, element1is the bit 1, and so forth.
method set_int_clear_cfg¶
set_int_clear_cfg(fifo_full, fifo_ths, ui_drdy)
| val | clear method |
|---|---|
| 0b00 | Status bit read |
| 0b01 | Status bit read |
| 0b10 | Sensor reg read |
| 0b11 | Both above methods |
For additional information, see register INT_CONFIG0 on IIM-42652 datasheet.
-
fifo_fullis the clear method of fifo full interrupt. -
fifo_thsis the clear method of fifo watermark threshold interrupt. -
ui_drdyis the clear method of ui data ready interrupt.
Example¶
from bsp import board
from components.iim42652 import iim42652
# Create a iim42652 class with i2c
iim = iim42652.IIM42652()
sleep(500)
# Software reset of the iim42652
iim.soft_reset()
# Set up the device for I2C communication
iim.setup()
# Set accel and config
# Accel ODR = 2khz, full scale = 16 g
iim.set_accel_cfg(0b0101, 0b000)
# Set fifo in stream mode
iim.set_fifo_mode(0b01)
# Power accels and gyros on low noise mode
iim.set_pwr_cfg(3, 0, 0, 0)
while True:
sleep(1000)
print("accel x:", iim.get_accel_x())
print("accel y:", iim.get_accel_y())
print("accel z:", iim.get_accel_z())