Liam just shared a new guide! “DIY Magnetic Encoder”
This guide covers what the PiicoDev Magnetometer is reading, a simple setup using some 3D printed parts, a walkthrough of the code that runs the module and how you can use it in your projects!
So my PiicoDev Magnetometer and SSD1306 modules arrived today.
Setup as per this guide and it doesn’t work.
I get the following error from Micropython:
PiicoDev could not communicate with module at address 0x1C, check wiring
Traceback (most recent call last):
File “”, line 10, in
File “PiicoDev_QMC6310.py”, line 68, in init
File “PiicoDev_QMC6310.py”, line 61, in init
File “PiicoDev_QMC6310.py”, line 81, in _setMode
OSError: [Errno 5] EIO
Thonny version 3.2.7
Ubuntu version 20.0.4
MicroPython v1.21.0 on 2023-10-06; Raspberry Pi Pico with RP2040
If i run a simple I2C scanner it shows:
Found devices at:
Which is exactly as it should.
I’ve also run the calibration example from Arduino QMC5883L library and get the following:
19:04:09.993 → This will provide calibration settings for your QMC5883L chip. When prompted, move the magnetometer in all directions until the calibration is complete.
19:04:10.126 → Calibration will begin in 5 seconds.
19:04:15.112 → CALIBRATING. Keep moving your sensor…
19:04:25.115 → DONE. Copy the lines below and paste it into your projects sketch.);
19:04:25.182 → compass.setCalibrationOffsets(0.00, 0.00, 0.00);
19:04:25.215 → compass.setCalibrationScales(nan, nan, nan);
An i2c scan on the arduino nano reports the magnetometer at 0x1C as expected.
Do you have the latest unified library?
Would it also be possible to send through a photo of your setup?
I’ve tried witth the latest version from here:
Connected up as per here:
I’ve tried using the other I2C pins with approprate modifications to the main.py file still the same result.
Thanks for testing and sending everything through
Everything looks fine there, I’d also try downgrading your micropython to 1.19: MicroPython - Python for microcontrollers
I’ll get a version of it setup once I have a spare moment
Tried Micropython 1.19.1 didn’t work.
Went to Micropython 1.18 and works as per the guide.
So obviously there is some change in 1.19.1 that breaks your library.
Noted - I’ll check out the guide and update the required parts.
Thanks for using the library and working through the bugs, keen to see what you make!
I now have it working with Arduino Nano as well.
This is what it will be used on. It’s a 60 year old Marklin 7186 all metal turntable.
The magnet is mounted on the bottom of the central shaft and the module is mounted on the 3D printed mount from the guide.
It still requires significant software development but the concept generally works.
The sensor will be used as positioning input to a DCC accessory decoder.
Awesome application! So happy to see it being used out in projects!
Thanks for sharing Ross and happy making