qmc5883l - Driver for QMC5883L 3-axis magnetic sensor

group qmc5883l

ESP-IDF Driver for 3-axis magnetic sensor QMC5883L.

Copyright (C) 2019 Ruslan V. Uss unclerus@gmail.com

BSD Licensed as described in the file LICENSE

Defines

QMC5883L_I2C_ADDR_DEF

Default I2C address.

Enums

enum qmc5883l_odr_t

Output data rate.

Values:

enumerator QMC5883L_DR_10

10Hz

enumerator QMC5883L_DR_50

50Hz

enumerator QMC5883L_DR_100

100Hz

enumerator QMC5883L_DR_200

200Hz

enum qmc5883l_osr_t

Oversampling rate.

Values:

enumerator QMC5883L_OSR_64

64 samples

enumerator QMC5883L_OSR_128

128 samples

enumerator QMC5883L_OSR_256

256 samples

enumerator QMC5883L_OSR_512

512 samples

enum qmc5883l_range_t

Field range.

Values:

enumerator QMC5883L_RNG_2

-2G..+2G

enumerator QMC5883L_RNG_8

-8G..+8G

enum qmc5883l_mode_t

Mode.

Values:

enumerator QMC5883L_MODE_STANDBY

Standby low power mode, no measurements.

enumerator QMC5883L_MODE_CONTINUOUS

Continuous measurements.

Functions

esp_err_t qmc5883l_init_desc(qmc5883l_t *dev, i2c_port_t port, uint8_t addr, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptor.

Parameters
  • dev – Device descriptor

  • port – I2C port number

  • addr – I2C address

  • sda_gpio – SDA GPIO

  • scl_gpio – SCL GPIO

Returns

ESP_OK on success

esp_err_t qmc5883l_free_desc(qmc5883l_t *dev)

Free device descriptor.

Parameters

dev – Device descriptor

Returns

ESP_OK on success

esp_err_t qmc5883l_reset(qmc5883l_t *dev)

Reset device.

Parameters

dev – Device descriptor

Returns

ESP_OK on success

esp_err_t qmc5883l_get_chip_id(qmc5883l_t *dev, uint8_t *id)

Read chip ID.

Parameters
  • dev – Device descriptor

  • [out] id – Chip ID

Returns

ESP_OK on success

esp_err_t qmc5883l_set_mode(qmc5883l_t *dev, qmc5883l_mode_t mode)

Set device mode.

Parameters
  • dev – Device descriptor

  • mode – Mode

Returns

ESP_OK on success

esp_err_t qmc5883l_get_mode(qmc5883l_t *dev, qmc5883l_mode_t *mode)

Read current device mode.

Parameters
  • dev – Device descriptor

  • [out] mode – Mode

Returns

ESP_OK on success

esp_err_t qmc5883l_set_config(qmc5883l_t *dev, qmc5883l_odr_t odr, qmc5883l_osr_t osr, qmc5883l_range_t rng)

Set device configuration.

Parameters
  • dev – Device descriptor

  • odr – Output data rate

  • osr – Oversampling

  • rng – Field range

Returns

ESP_OK on success

esp_err_t qmc5883l_get_config(qmc5883l_t *dev, qmc5883l_odr_t *odr, qmc5883l_osr_t *osr, qmc5883l_range_t *rng)

Read current device configuration.

Parameters
  • dev – Device descriptor

  • [out] odr – Output data rate

  • [out] osr – Oversampling

  • [out] rng – Field range

Returns

ESP_OK on success

esp_err_t qmc5883l_set_int(qmc5883l_t *dev, bool enable)

Enable/disable interrupt pin.

Parameters
  • dev – Device descriptor

  • enable – Enable interrupt if true

Returns

ESP_OK on success

esp_err_t qmc5883l_get_int(qmc5883l_t *dev, bool *enable)

Get interrupt pin state.

Parameters
  • dev – Device descriptor

  • [out] enable – Interrupt pin enabled if true

Returns

ESP_OK on success

esp_err_t qmc5883l_data_ready(qmc5883l_t *dev, bool *ready)

Get magnetic data state.

Parameters
  • dev – Device descriptor

  • [out] ready – Magnetic data ready to read if true

Returns

ESP_OK on success

esp_err_t qmc5883l_get_raw_data(qmc5883l_t *dev, qmc5883l_raw_data_t *raw)

Read raw magnetic data.

Parameters
  • dev – Device descriptor

  • [out] raw – Raw magnetic data

Returns

ESP_OK on success

esp_err_t qmc5883l_raw_to_mg(qmc5883l_t *dev, qmc5883l_raw_data_t *raw, qmc5883l_data_t *data)

Convert raw magnetic data to milligauss.

Parameters
  • dev – Device descriptor

  • raw – Raw magnetic data

  • [out] data – Magnetic data in mG

Returns

ESP_OK on success

esp_err_t qmc5883l_get_data(qmc5883l_t *dev, qmc5883l_data_t *data)

Read magnetic data in milligauss.

Parameters
  • dev – Device descriptor

  • [out] data – Magnetic data in mG

Returns

ESP_OK on success

esp_err_t qmc5883l_get_raw_temp(qmc5883l_t *dev, int16_t *temp)

Read raw temperature data (see datasheet)

Parameters
  • dev – Device descriptor

  • [out] temp – Raw temperature data

Returns

ESP_OK on success

struct qmc5883l_raw_data_t
#include <qmc5883l.h>

Raw measurement result.

struct qmc5883l_data_t
#include <qmc5883l.h>

Measurement result, milligauss.

struct qmc5883l_t
#include <qmc5883l.h>

Device descriptor.