In this article we connect a TLV493D magnetic sensor to a Raspberry Pi Pico running Circuitpython
Sensor Information
The 3D magnetic sensor TLV493D offers accurate three-dimensional sensing with extremely low power consumption in a small 6-pin package.
With its magnetic field detection in x, y, and z-direction the sensor reliably measures three dimensional, linear and rotation movements.
Applications include joysticks, control elements (white goods, multifunction knops), or electric meters (anti tampering) and any other application that requires accurate angular measurements or low power consumptions.
Features
• 3D magnetic sensing
• Very low power consumption = 10 µA during operations (10 Hz, typ.)
• Power down mode with 7 nA power consumption
• Digital output via 2-wire based standard I2C interface up to 1 MBit/sec
• 12-bit data resolution for each measurement direction
• Bx, By and Bz linear field measurement up to +130 mT
• Excellent matching of X/Y measurement for accurate angle sensing
• Variable update frequencies and power modes (configurable during operation)
• Supply voltage range = 2.8 V…3.5 V, Temperature range Tj = -40°C…125°C
• Triggering by external µC possible
• Interrupt signal available to wake up a microcontroller
• Temperature measurement
This is the sensor that I bought
Parts Required
The sensor you can pick up in the $6 price range – you can connect to the sensor using a standard header the classic dupont style jumper wire.
I used a Qwiic cable – since a few sensors seem to use these but this is optional
Name | Link |
Pico | Raspberry Pi Pico Development Board |
TLV493D | ADA Adafruit (PID 4366) TLV493D Triple-Axis Magnetometer – Stemma QT/Qwiic |
Connecting cables | Aliexpress product link |
Schematic/Connection
I used the Adafruit TLV493D sensor and in this case used the Stemma connection
For the STEMMA QT cables, it uses the Qwiic convention:
Black for GND
Red for V+
Blue for SDA
Yellow for SCL
So color coded for ease of use, this layout shows a connection to the module
Code Example
I used Thonny for development
The following is based on a library , I copied the adafruit_tlv493d.mpy library for this device to the lib folder on my RP2040 – https://circuitpython.org/libraries
This is the basic example which comes with the library
[codesyntax lang=”python”]
import time import board import adafruit_tlv493d import busio # Create sensor object, communicating over the board's default I2C bus i2c = busio.I2C(scl=board.GP1, sda=board.GP0) tlv = adafruit_tlv493d.TLV493D(i2c) while True: print("X: %s, Y: %s, Z: %s mT" % tlv.magnetic) time.sleep(1)
[/codesyntax]
Output
Here is what I saw in Thonny REPL window
X: 0.098, Y: 0.098, Z: 0.0 mT
X: -0.098, Y: 0.196, Z: -0.098 mT
X: 0.0, Y: -0.098, Z: 0.0 mT
X: 0.0, Y: 0.098, Z: 0.0 mT
X: 0.0, Y: 0.0, Z: -0.098 mT
X: -0.196, Y: 0.0, Z: 0.0 mT
X: 0.0, Y: 0.098, Z: 0.098 mT
Links
1 comment
[…] Raspberry Pi Pico and TLV493D Magnetic Sensor CircuitPython example – RP2040 Learning. […]
Comments are closed.