Magnetometer Sensor

Browse source code on GitHub

Overview

Sample application that periodically reads magnetometer (X, Y, Z) data from the first available device that implements SENSOR_CHAN_MAGN_* (predefined array of device names).

Board-specific overlays

TMAG5170 via Raspberry Pi Pico

The Zephyr driver for the ti,tmag5170` requires an SPI driver that supports 32-bit SPI_WORD_SIZE. On the Raspberry Pi Pico, the raspberrypi,pico-spi-pio SPI driver provides this support, demonstrated with the samples/sensor/magn_polling/boards/rpi_pico.overlay.

The GPIO pin assignments in the overlay file are arbitrary. The PIO SPI driver allows using any four GPIO pins for the SPI bus. Just keep in mind that the pin assignments in the pinctrl block and the pio0_spi0 block must match.

With the sensor wired to the desired pins, build and flash with:

# From the root of the zephyr repository
west build -b rpi_pico samples/sensor/magn_polling
west flash

See also

Sensor Interface