Skip to content

reznikmm/qmc5883

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QMC5883

Build status Alire REUSE status

Driver for QMC5883L magnetic sensor.

The sensor is available as a module for DIY projects from various manufacturers, such as GY-273. It boasts 2 milli-gauss resolution, low power consumption, a compact size, and up to 200 Hz output rate.

The QMC5883L driver enables the following functionalities:

  • Detect the presence of the sensor.
  • Perform soft reset
  • Configure the sensor (over smaple rate, output data rate, full scale range)
  • Conduct measurements as raw 16-bit values and scaled values.

Install

Add qmc5883 as a dependency to your crate with Alire:

alr with qmc5883

Usage

The driver implements two usage models: the generic package, which is more convenient when dealing with a single sensor, and the tagged type, which allows easy creation of objects for any number of sensors and uniform handling.

Generic instantiation looks like this:

declare
   package QMC5883_I2C is new HCM5883.Sensor
     (I2C_Port => STM32.Device.I2C_1'Access);

begin
   if QMC5883_I2C.Check_Chip_Id then
      ...

While declaring object of the tagged type looks like this:

declare
   Sensor : QMC5883.Sensors.QMC5883_Sensor
     (I2C_Port => STM32.Device.I2C_1'Access);
begin
   if Sensor.Check_Chip_Id then
      ...

Sensor Configuration

To configure the sensor, use the Configure procedure by passing the settings (Sensor_Configuration type).

Settings include:

  • Over_Sample: Over Sample Rate - bandwidth of an internal digital filter

  • Data_Rate: Output Data Rate - desired measurement frequency from a predefined list of values (10Hz, 50Hz, 100Hz and 200Hz).

  • Full_Range: Full Scale Range - sensor sensitivity (and resolution) +/- 2 Gauss or +/- 8 Gauss.

  • Mode: Switch between standby mode and continuous measurement mode.

An example:

Sensor.Configure
  ((Over_Sample => 512,
    Data_Rate   => 50,
    Full_Range  => 8,
    Mode        => QMC5883.Continuous),
   Ok);

Read Measurement

The best way to determine data readiness is through interrupts using a separate pin. Otherwise you can ascertain that the data is ready by waiting while Is_Data_Ready returns True.

Read raw data (as provided by the sensor) with the Read_Raw_Measurement procedure.

Calling Read_Measurement returns scaled measurements in Gauss based on the current Full_Range setting.

Examples

You need Ada_Drivers_Library in adl directory. Clone it then run Alire to build:

git clone https://github.com/AdaCore/Ada_Drivers_Library.git adl
cd examples
alr build

GNAT Studio

Launch GNAT Studio with Alire:

cd examples; alr exec gnatstudio -- -P qmc5883_put/qmc5883_put.gpr

VS Code

Make sure alr in the PATH. Open the examples folder in VS Code. Use pre-configured tasks to build projects and flash (openocd or st-util). Install Cortex Debug extension to launch pre-configured debugger targets.

About

An Ada driver for 3-axis magnetic sensor QMC5883L

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages