Tags:
create new tag
view all tags

The driver for BMA423 Triaxial Acceleration Sensor

The MicroPython layer in bma423 from https://github.com/OPHoperHPO/lilygo-ttgo-twatch-2020-micropython was not working because it uses deprecated calls to I2C in MicroPython.

However, I found that Daniel Thomson has also written a MicroPython interface to the BMA423 API from Bosch SensorTec, which was easier to adapt to the t-watch.

https://github.com/daniel-thompson/bma42x-upy

I had to make only a few modifications: Daniel uses a BMA421 while the t-watch uses a BMA423. I therefore had to replace all occurrences of "bma421" in bma42x.c by "bma423". In addition the t-watch uses the secondary I2C address 0x19 for the chip (the primary address is 0x18) and I therefore had to replace ic2_addr in the device descriptor to BMA4_I2C_ADDR_SECONDARY.

Daniel also supplies a few example programs, which are essentially ports of the Bosch examples ported from C to MicroPython

The BMA42X driver provides the following methods:

  • BMA42X(i2c): create a BMA42X object. The i2c parameter must be a initialized SoftI2C object
  • debug(on_off): switch debugging on / off
  • feature_enable(feature,on_off): feature: the feature to be enabled or disabled, on_off to switch the feature on or off. The features are listed below.
  • get_offset_comp(): Gets the status of the accel offset compensation
  • get_temperature(unit): gets the temperature in the requested units. Possible units: see below
  • init (called when the object is created)
  • map_interrupt(int_line, interrupt_types): Map the interrupt to either pin1 or pin2
  • read_accel_xyz(): read the accel data for x,y,z from the sensor. The data are returned as a tuple (x,y,z)
  • read_int_status(): reads the hardware interrupt status from the sensor
  • set accel_config(accel_config): set the acceleration sensor config. See the accelerometer.py example in order to understand how to do this.
  • reset_step_counter(): reset the step counter
  • set accel_enable(on_off): enables or disables the accel in the sensor
  • set_any_mot_config(any_mot_config): set the configuration for any motion interrupts. See example motion_interrupt.py in order to understand how to do this.
  • set_no_mot_config(no_mot_config): set the configuration for no motion interrupts. See example motion_interrupt.py in order to understand how to do this.
  • set_command_reg(value): set the command register
    • 0xb6: triggers a soft reset
    • 0xb0: clears all data in the FiFo
    • 0xf0: resets the acceleration data path
  • set_offset_comp(on_off): enables the offset compensation for filtered and unfiltered accel data
  • step_detector_enable(on_off): enables or disables the step detector feature in the sensor
  • step_counter_output(): gets the number of counted steps of the step counter feature from the sensor
  • step_counter_set_watermark(value): sets the watermark level for step counter interrupt in the sensor
  • write_config_file(): write the binary configuration data to the sensor
The driver also defines the following constants:

The registers:

  • ACCEL_CONFIG_ADDR
  • POWER_CONF_ADDR
  • POWER_CTRL_ADDR
  • NV_CONFIG_ADDR
Configuration values:
  • ACCEL_RANGE_2G
  • ACCEL_RANGE_4G
  • ACCEL_RANGE_8G
  • ACCEL_RANGE_16G
  • ACCEL_NORMAL_AVG4
  • (OUTPUT_DATA_RATE_50HZ
  • OUTPUT_DATA_RATE_100HZ
  • CIC_AVG_MODE
  • CONTINUOUS_MODE
Temperature parameters:
  • SCALE_TEMP
  • DEG
  • FAHREN
  • KELVIN
Features
  • STEP_CNTR
  • STEP_ACT
  • WRIST_WEAR
  • SINGLE_TAP
  • DOUBLE_TAP

Interrupts

  • INTR1_MAP
  • INTR2_MAP
  • STEP_CNTR_INT
  • ANY_MOT_INT
  • NO_MOT_INT
Enable axis
  • DIS_ALL_AXIS
  • X_AXIS_EN
  • Y_AXIS_EN
  • Z_AXIS_EN
  • EN_ALL_AXIS

-- Uli Raich - 2021-01-27

Comments

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2021-01-28 - UliRaich
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback