Reader small image

You're reading from  Robotics at Home with Raspberry Pi Pico

Product typeBook
Published inMar 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781803246079
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Danny Staple
Danny Staple
author image
Danny Staple

Danny Staple builds robots and gadgets as a hobbyist, makes videos about his work with robots, and attends community events such as PiWars and Arduino Day. He has been a professional Python programmer, later moving into DevOps, since 2009, and a software engineer since 2000. He has worked with embedded systems, including embedded Linux systems, throughout the majority of his career. He has been a mentor at a local CoderDojo, where he taught how to code with Python. He has run Lego Robotics clubs with Mindstorms. He has also developed Bounce!, a visual programming language targeted at teaching code using the NodeMCU IoT platform. The robots he has built with his children include TankBot, SkittleBot (now the Pi Wars robot), ArmBot, and SpiderBot.
Read more about Danny Staple

Right arrow

Calibrating and getting readings

When you start up code using an IMU module with a controller, the sensors will not get correct readings. So, the IMU module will need to determine the sensitivity and correct states of the sensor, a process known as calibration. First, we need some code; then, we’ll need to take the robot through some motions to perform this.

Calibration code

Let’s start with the code. In a file called imu_calibration/code.py, add the following:

import adafruit_bno055
import board
import busio
import time
i2c = busio.I2C(sda=board.GP0, scl=board.GP1)
sensor = adafruit_bno055.BNO055_I2C(i2c)

This code handles importing the module and setting it up. We also import time so that we can use it in loops later.

Next, we must check the calibration state of the module:

def check_status():
  sys_status, gyro, accel, mag = imu.calibration_status
  print(f"Sys: {sys_status}, Gyro: {gyro}, Accel: {accel}, Mag: {mag}"...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Robotics at Home with Raspberry Pi Pico
Published in: Mar 2023Publisher: PacktISBN-13: 9781803246079

Author (1)

author image
Danny Staple

Danny Staple builds robots and gadgets as a hobbyist, makes videos about his work with robots, and attends community events such as PiWars and Arduino Day. He has been a professional Python programmer, later moving into DevOps, since 2009, and a software engineer since 2000. He has worked with embedded systems, including embedded Linux systems, throughout the majority of his career. He has been a mentor at a local CoderDojo, where he taught how to code with Python. He has run Lego Robotics clubs with Mindstorms. He has also developed Bounce!, a visual programming language targeted at teaching code using the NodeMCU IoT platform. The robots he has built with his children include TankBot, SkittleBot (now the Pi Wars robot), ArmBot, and SpiderBot.
Read more about Danny Staple