fusion_hat.modules.gy87 module

fusion_hat.modules.gy87.scan_i2c_addr(bus_id=1)[source]

Scan the I2C bus for all responding device addresses

Parameters:

bus_id – I2C bus number, defaults to I2C_BUS (1)

Returns:

list of all detected I2C device addresses

Return type:

found

fusion_hat.modules.gy87.tilt_comp_heading(mx, my, mz, ax, ay, az, decl_deg=0.0)[source]

Calculate tilt-compensated heading: Use accelerometer data to calculate roll/pitch angles, then compensate magnetometer data

Parameters:
  • mx – Three-axis data from the magnetometer (Gauss)

  • my – Three-axis data from the magnetometer (Gauss)

  • mz – Three-axis data from the magnetometer (Gauss)

  • ax – Three-axis data from the accelerometer (g)

  • ay – Three-axis data from the accelerometer (g)

  • az – Three-axis data from the accelerometer (g)

  • decl_deg – Magnetic declination (degrees), used to convert magnetic north to true north

Returns:

Compensated heading angle, range 0-360 degrees

Return type:

hdg

class fusion_hat.modules.gy87.GY87(bus_id=1, decl_deg=0.0)[source]

Bases: object

GY-87 sensor module main class Integrate MPU6050 (accelerometer + gyroscope), BMP180 (barometer), and magnetometer (support multiple models) Provide complete sensor data reading functionality, including self-recovery mechanism

read_all()[source]

Read all sensor data Include automatic error handling and self-recovery mechanism to ensure system stability

Returns:

Dictionary containing all sensor data
{accel_g: (x,y,z), gyro_dps: (x,y,z), temp_mpu_c: float,

temp_bmp_c: float, pressure_pa: float, altitude_m: float, mag_gauss: (x,y,z), heading_deg: float}

Return type:

dict

fusion_hat.modules.gy87.demo_loop()[source]

GY-87 sensor module demo loop function

Functions:
  1. Scan and display connected I2C devices

  2. Initialize the GY87 sensor module

  3. Continuously read and display all sensor data

  4. Adjust output format based on magnetometer presence

Output format:
  • With magnetometer: displays acceleration, angular velocity, magnetic field strength, heading, temperature, pressure, and altitude

  • Without magnetometer: displays all data except magnetic field strength and heading

Sampling frequency:

~5 Hz (0.2 s pause after each read)