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.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • port: I2C port number

  • addr: I2C address

  • sda_gpio: SDA GPIO

  • scl_gpio: SCL GPIO

esp_err_t qmc5883l_free_desc(qmc5883l_t *dev)

Free device descriptor.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t qmc5883l_reset(qmc5883l_t *dev)

Reset device.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t qmc5883l_get_chip_id(qmc5883l_t *dev, uint8_t *id)

Read chip ID.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • id: Chip ID

esp_err_t qmc5883l_set_mode(qmc5883l_t *dev, qmc5883l_mode_t mode)

Set device mode.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • mode: Mode

esp_err_t qmc5883l_get_mode(qmc5883l_t *dev, qmc5883l_mode_t *mode)

Read current device mode.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • mode: Mode

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

Set device configuration.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • odr: Output data rate

  • osr: Oversampling

  • rng: Field range

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.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • odr: Output data rate

  • osr: Oversampling

  • rng: Field range

esp_err_t qmc5883l_set_int(qmc5883l_t *dev, bool enable)

Enable/disable interrupt pin.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • enable: Enable interrupt if true

esp_err_t qmc5883l_get_int(qmc5883l_t *dev, bool *enable)

Get interrupt pin state.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • enable: Interrupt pin enabled if true

esp_err_t qmc5883l_data_ready(qmc5883l_t *dev, bool *ready)

Get magnetic data state.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • ready: Magnetic data ready to read if true

esp_err_t qmc5883l_get_raw_data(qmc5883l_t *dev, qmc5883l_raw_data_t *raw)

Read raw magnetic data.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • raw: Raw magnetic data

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.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • raw: Raw magnetic data

  • data: Magnetic data in mG

esp_err_t qmc5883l_get_data(qmc5883l_t *dev, qmc5883l_data_t *data)

Read magnetic data in milligauss.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • data: Magnetic data in mG

esp_err_t qmc5883l_get_raw_temp(qmc5883l_t *dev, int16_t *temp)

Read raw temperature data (see datasheet)

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • temp: Raw temperature data

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.