This module implements the rdk:movement_sensor
API in the berryimu3
model.
You can use this module to interface with the BerryIMU v3 accelerometer, gyroscope and magnetometer using an I2C connection on ARM64 systems.
- BerryIMU v3 movement sensor
- Single board computer running Linux Arm64
- Enable I2C communication on your single board computer. If you are using a Raspberry Pi, see Enable communication protocols.
- Install the Viam Python SDK on your single board computer.
- Calibrate your IMU sensor by running the following command in the BerryIMU v3 module's
src
directory:
python3 calibration.py
Tip
During calibration, rotate the BerryIMU v3 360 degrees in all directions (X,Y, and Z) until the script returns calibration values. Note the returned calibration values, as you'll need to set these values into your movement sensor component's attributes during configuration.
To use this module, follow the instructions to add a module from the Viam Registry and select the viam-labs:movement_sensor:berryimu3
model from the berryimu3
module.
Note
Before configuring your movement sensor, you must create a machine.
Navigate to the Config tab of your machine's page in the Viam app. Click on the Components subtab and click Create component.
Select the movement-sensor
type, then select the berryimu3
model.
Enter a name for your movement sensor, click Create.
On the new component panel, copy and paste the following attribute template into your movement sensor's Attributes box:
{
"hard_iron_y_max": <INT>,
"soft_iron_x_max": <INT>,
"hard_iron_x_min": <INT>,
"hard_iron_x_max": <INT>,
"soft_iron_x_min": <INT>,
"soft_iron_y_max": <INT>,
"soft_iron_y_min": <INT>,
"hard_iron_y_min": <INT>,
"calibrate": <BOOL>,
"i2c_bus": <STRING>
}
Then click Save config to save your changes.
For more information, see Configure a Machine.
Assign each attribute to the corresponding calibration value obtained when you calibrated the BerryIMU v3.
Note
All min
an max
attributes are optional if the calibrate
attribute is not set to true
and required when calibration is enabled.
The calibration values are obtained from running the calibration.py
script.
Name | Type | Inclusion | Description |
---|---|---|---|
hard_iron_y_max |
int | Required | Maximum value for the y-axis hard iron distortion correction. |
soft_iron_x_max |
int | Required | Maximum value for the x-axis soft iron distortion correction. |
hard_iron_x_min |
int | Required | Minimum value for the x-axis hard iron distortion correction. |
hard_iron_x_max |
int | Required | Maximum value for the x-axis hard iron distortion correction. |
soft_iron_x_min |
int | Required | Minimum value for the x-axis soft iron distortion correction. |
soft_iron_y_max |
int | Required | Maximum value for the y-axis soft iron distortion correction. |
soft_iron_y_min |
int | Required | Minimum value for the y-axis soft iron distortion correction. |
hard_iron_y_min |
int | Required | Minimum value for the y-axis hard iron distortion correction. |
calibrate |
bool | Optional | Flag indicating whether callibration is enabled to alibrate the magnetometer using the min and max values (true is enabled). |
i2c_bus |
str | Required | Name of the I2C bus wired to the IMU. |
{
"hard_iron_y_max": 1953,
"soft_iron_x_max": 1069,
"hard_iron_x_min": -1953,
"hard_iron_x_max": 118,
"soft_iron_x_min": -1069,
"soft_iron_y_max": 1069,
"soft_iron_y_min": -1056,
"hard_iron_y_min": -1029,
"calibrate": true,
"i2c_bus": "1"
}
{
"calibrate": false,
"i2c_bus": "1"
}
Wire the board pins outlined below to the corresponding pins on your IMU sensor. The IMU can be powered with the 3.3v pin, and also supports 5V.
Board Pin | Berry IMU Pin |
---|---|
SCL | SCL |
SDA | SDA |
3.3V | 3.3V |
GND | GND |
Verify the I2C connection by running the following command on your board:
i2cdetect -y 1
If the IMU is wired correctly, the output of the command will be the I2C addresses 1c
and 6a
. This indicates that the IMU is successfully connected and detected by your system.
- To test your movement sensor, go to the Control tab.
- To write code against your movement sensor, use one of the available SDKs.
If you encounter an OSError: 5
, check your I2C connection. Ensure your wiring is correct and that the i2cdetect
command successfully detects the device's I2C addresses.