Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

LIS3MDL 3-axis magnetometer. T


Hello to you.
I am an amateur. I want to build a simple magnetometer consisting of six LIS3MDL 3-axis magnetometers working with Raspberry 3Pi. How should I connect magnetometers to Raspbery? The magnetometers would be used to measure the magnetic field of small solids - rocks, meteorites etc … placed in a special container - box. In order to make a measurement of the magnetic field of the tested object, a ground-based measurement (natural terrestrial magnetic field) should be made without a sample, and then a measurement with a sample placed in the container. The result of the measurement with the sample should be subtracted from the zero measurement value, thanks to which we obtain the real value of the magtnet field emitted by the tested object. unfortunately I do not know about programming languages. Can any of the Honorable forum members talk to me?
Thank you in advance for any help.
Best wishes
Marcin from the geological museum.


Hello, Marcin.

Probably the most straightforward solution for getting data from six of those magnetometers with a Raspberry Pi is to use their SPI interface. (You can learn more about the specifics of that interface under the “Communication interface characteristics” section of the LIS3MDL’s datasheet, which you can find under the Resources tab of its product page.) However, we do not have a library for that, so you would have to write your own code, or see if someone else has written a library.

Those sensors also have a second interface, I²C, that you could use. However, using that interface is not trivial because those sensors only have two possible slave addresses (which means you could only connect two LIS3MDL per I²C bus). To get around that, you might look into using something like an I²C multiplexer, which would allow you to use the same bus to connect to multiple same-address I²C slave devices.

As for not knowing much about programming languages, you might look for people that are interested in your application at a local university (maybe the computer science or electrical engineering majors) or your local hackerspace/makerspace.



Hello John,

I am thanking you for a professional response.

Best wishes

  • Marcin