sensor-qmc5883p

CLI reference

glasgow run sensor-qmc5883p

Measure magnetic field using the QMC5883P triple-axis magnetometer sensor.

This applet only supports sensors connected via the I²C interface.

usage: glasgow run sensor-qmc5883p [-h] [-V SPEC] [--scl PIN] [--sda PIN]
                                   [--i2c-address ADDR] [-m MODE] [-r RATE]
                                   [-o RATIO] [-d RATIO] [-R GAUSS]
                                   OPERATION ...
-h, --help

show this help message and exit

-V <spec>, --voltage <spec>

configure I/O port voltage to SPEC (e.g.: ‘3.3’, ‘A=5.0,B=3.3’, ‘A=SA’)

--scl <pin>

bind the applet I/O line ‘scl’ to PIN (default: ‘A0’, required)

--sda <pin>

bind the applet I/O line ‘sda’ to PIN (default: ‘A1’, required)

--i2c-address <addr>

I2C address of the sensor (default: 0x2c)

-m {suspend,normal,single,continuous}, --mode {suspend,normal,single,continuous}

operating mode (default: normal)

-r {10,50,100,200}, --data-rate {10,50,100,200}

output data rate in Hz (default: 50)

-o {8,4,2,1}, --oversample {8,4,2,1}

oversample ratio (default: 4)

-d {1,2,4,8}, --downsample {1,2,4,8}

downsample ratio (default: 2)

-R {30,12,8,2}, --range {30,12,8,2}

field range in Gauss (default: 8)

glasgow run sensor-qmc5883p log

usage: glasgow run sensor-qmc5883p log [-h] -i TIME DATA-LOGGER ...
-h, --help

show this help message and exit

-i <time>, --interval <time>

sample each TIME seconds

glasgow run sensor-qmc5883p log csv

Log data to a comma-separated value (CSV) file.

usage: glasgow run sensor-qmc5883p log csv [-h] [--dialect DIALECT] CSV-FILE
csv-file

write data to CSV-FILE

-h, --help

show this help message and exit

--dialect {excel,excel-tab,unix}

format CSV file according to DIALECT

glasgow run sensor-qmc5883p log influxdb

Log data to an InfluxDB 1.x endpoint over HTTP(S).

usage: glasgow run sensor-qmc5883p log influxdb [-h] [-r POLICY]
                                                [-t TAG=VALUE] -p PRECISION
                                                [--batch-size BATCH-SIZE]
                                                ENDPOINT DATABASE SERIES
endpoint

write to endpoint URL //ENDPOINT/write

database

write to database DATABASE

series

write to measurement SERIES

-h, --help

show this help message and exit

-r <policy>, --retention-policy <policy>

write to retention policy POLICY

-t <tag=value>, --tag <tag=value>

attach TAG=VALUE to all data points

-p {ns,us,ms,s,m,h}, --precision {ns,us,ms,s,m,h}

set timestamp precision to PRECISION

--batch-size <batch-size>

submit data in groups of BATCH-SIZE points

glasgow run sensor-qmc5883p log influxdb2

Log data to an InfluxDB 2.x endpoint over HTTP(S).

usage: glasgow run sensor-qmc5883p log influxdb2 [-h] [-t TAG=VALUE]
                                                 -p PRECISION
                                                 [--batch-size BATCH-SIZE]
                                                 --token TOKEN
                                                 ENDPOINT ORGANIZATION BUCKET
                                                 SERIES
endpoint

write to endpoint URL //ENDPOINT/api/v2/write

organization

write to Organization ORGANIZATION (can be either the name or the id)

bucket

write to bucket BUCKET

series

write to measurement SERIES

-h, --help

show this help message and exit

-t <tag=value>, --tag <tag=value>

attach TAG=VALUE to all data points

-p {ns,us,ms,s,m,h}, --precision {ns,us,ms,s,m,h}

set timestamp precision to PRECISION

--batch-size <batch-size>

submit data in groups of BATCH-SIZE points

--token <token>

set the Token to use for Authentication

glasgow run sensor-qmc5883p log stdout

Log data to standard output in a human-readable format.

usage: glasgow run sensor-qmc5883p log stdout [-h]
-h, --help

show this help message and exit

glasgow run sensor-qmc5883p measure

usage: glasgow run sensor-qmc5883p measure [-h]
-h, --help

show this help message and exit

API reference

exception glasgow.applet.sensor.qmc5883p.QMC5883PError
enum glasgow.applet.sensor.qmc5883p.OperatingMode(value)

Operating modes for QMC5883P.

Valid values are as follows:

Suspend = <OperatingMode.Suspend: 'suspend'>
Normal = <OperatingMode.Normal: 'normal'>
Single = <OperatingMode.Single: 'single'>
Continuous = <OperatingMode.Continuous: 'continuous'>
enum glasgow.applet.sensor.qmc5883p.OutputDataRate(value)

Output data rates (Hz).

Valid values are as follows:

ODR_10Hz = <OutputDataRate.ODR_10Hz: 10>
ODR_50Hz = <OutputDataRate.ODR_50Hz: 50>
ODR_100Hz = <OutputDataRate.ODR_100Hz: 100>
ODR_200Hz = <OutputDataRate.ODR_200Hz: 200>
enum glasgow.applet.sensor.qmc5883p.OversampleRatio(value)

Oversample ratios.

Valid values are as follows:

OSR_8 = <OversampleRatio.OSR_8: 8>
OSR_4 = <OversampleRatio.OSR_4: 4>
OSR_2 = <OversampleRatio.OSR_2: 2>
OSR_1 = <OversampleRatio.OSR_1: 1>
enum glasgow.applet.sensor.qmc5883p.DownsampleRatio(value)

Downsample ratios.

Valid values are as follows:

DSR_1 = <DownsampleRatio.DSR_1: 1>
DSR_2 = <DownsampleRatio.DSR_2: 2>
DSR_4 = <DownsampleRatio.DSR_4: 4>
DSR_8 = <DownsampleRatio.DSR_8: 8>
enum glasgow.applet.sensor.qmc5883p.FieldRange(value)

Field ranges (Gauss).

Valid values are as follows:

Range_30G = <FieldRange.Range_30G: 30>
Range_12G = <FieldRange.Range_12G: 12>
Range_8G = <FieldRange.Range_8G: 8>
Range_2G = <FieldRange.Range_2G: 2>
enum glasgow.applet.sensor.qmc5883p.SetResetMode(value)

Set/Reset modes.

Valid values are as follows:

On = <SetResetMode.On: 'on'>
SetOnly = <SetResetMode.SetOnly: 'set-only'>
Off = <SetResetMode.Off: 'off'>
class glasgow.applet.sensor.qmc5883p.QMC5883PInterface(logger: Logger, i2c_iface: I2CControllerInterface, i2c_address: int = _DEFAULT_ADDR)

Interface to QMC5883P magnetometer sensor.

async identify() int

Read and verify chip ID.

Returns:

Chip ID (should be 0x80).

Return type:

int

Raises:

QMC5883PError – If chip ID does not match expected value 0x80.

async soft_reset() None

Perform soft reset via CONTROL2 register.

Waits 50ms for reset to complete and verifies chip ID.

Raises:

QMC5883PError – If chip ID is invalid after reset.

async set_mode(mode: OperatingMode) None

Set operating mode.

Parameters:

mode (OperatingMode) – Operating mode.

Raises:

QMC5883PError – If mode is invalid.

async set_data_rate(odr: OutputDataRate) None

Set output data rate.

Parameters:

odr (OutputDataRate) – Output data rate.

Raises:

QMC5883PError – If data rate is invalid.

async set_oversample_ratio(osr: OversampleRatio) None

Set oversample ratio.

Parameters:

osr (OversampleRatio) – Oversample ratio.

Raises:

QMC5883PError – If oversample ratio is invalid.

async set_downsample_ratio(dsr: DownsampleRatio) None

Set downsample ratio.

Parameters:

dsr (DownsampleRatio) – Downsample ratio.

Raises:

QMC5883PError – If downsample ratio is invalid.

async set_range(field_range: FieldRange) None

Set field range.

Parameters:

field_range (FieldRange) – Field range.

Raises:

QMC5883PError – If field range is invalid.

async get_range() FieldRange

Get current field range setting.

Returns:

Current field range.

Return type:

FieldRange

async set_setreset_mode(setreset: SetResetMode) None

Set set/reset mode for eliminating sensor offset.

Parameters:

setreset (SetResetMode) – Set/reset mode: SetResetMode.ON, SetResetMode.SETONLY, or SetResetMode.OFF.

Raises:

QMC5883PError – If set/reset mode is invalid.

async data_ready() bool

Check if new measurement data is available.

Returns:

True if data is ready to be read.

Return type:

bool

async overflow() bool

Check if sensor measurement has overflowed.

Returns:

True if overflow occurred.

Return type:

bool

async get_magnetic_raw() tuple[int, int, int]

Read raw magnetic field values.

Waits for data ready, then reads all three axes.

Returns:

Raw 16-bit signed values (x, y, z).

Return type:

tuple[int, int, int]

Raises:

QMC5883PError – If timeout waiting for data ready.

async get_magnetic() tuple[float, float, float]

Read magnetic field in Gauss.

Reads raw values and converts to Gauss based on current range setting.

Returns:

Magnetic field values in Gauss (x, y, z).

Return type:

tuple[float, float, float]

Raises:

QMC5883PError – If timeout waiting for data ready.