There's more...

So far, the basic library allows us to see the strength of the magnetic field on each of the three axes around the sensor (up/down, left/right, and forward/backward). While we can see that these values will change as we move the sensor around, this is not enough to steer our robot. First, we need to calibrate the sensor, and then determine the direction of the robot from the readings of the x and y axes.

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.