# How To Calibrate And Setup The EIMU

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FQPmsAugE15tts71Inbmn%2Feimu_pic_setup_app.png?alt=media&#x26;token=c064c829-e9b4-468d-9f64-4eafdb77381c" alt=""><figcaption></figcaption></figure>

The **Easy IMU (EIMU)** is an easy-to-use open-source advanced IMU compute system for the MPU9250 IMU, with configurable and ready-to-use orientation readings.&#x20;

It has a **GUI application** that allows one to easily calibrate and setup its Madgwick filter. It also has **libraries** for easy interfacing with your preferred project (whether **ROS2**, **Arduino,** **Python**, or **Cpp** robotics projects).

It can easily be used by hobbyists, students, learners, researchers, etc.

But before you can use it in your preferred project, calibration and some filter setup needs to be done.

This tutorial aims to teach you how to calibrate and setup the EIMU so you can start using it in your preferred project.

Here are the steps we would be following to setup and calibrate the EIMU Module:

1. [Start The Application And Reset Parameters (if necessary)](#id-1.-start-the-application-and-reset-parameters-if-necessary)
2. [Calibrate The Magnetometer Sensor](#id-2.-calibrate-the-magnetometer-sensor)
3. [Calibrate The Gyroscope Sensor](#id-3.-calibrate-the-gyroscope-sensor)
4. [Calibrate The Accelerometer Sensor](#id-4.-calibrate-accelerometer-sensor)
5. [Visualize Orientation, Change Filter Gain, and Reference Frame (as Necessary)](#id-5.-visualize-orientation-change-filter-gain-and-reference-frame-as-necessary)
6. [Compute the Orientation, Gyroscope, and Accelerometer Sensor Variances](#id-6.-compute-the-orientation-gyroscope-and-accelerometer-sensor-variances)
7. [Set I2C Address (If neccessary)](#id-7.-set-i2c-address-if-neccessary)

### Prerequisite

* Ensure your PC is capable of communicating with Arduino boards - specifically **Arduino Nano** -(both code upload and serial communication) as the **EIMU  Module** uses a super-mini arduino nano microcontroller.
* Ensure to have the **EIMU Module** and a **USB Cable** for serial communication.
* Download the **EIMU Setup Application** executable [here](https://drive.google.com/drive/folders/15VKJOoy0xsAJwgAZPfSEe5I1lhudSw7_?usp=sharing) and extract it.

{% hint style="info" %}
**NOTE:**\
if you don't find the application for your operating system, you'll need to run the eimu setup application python code via a python virtual environment. check the github repo for that [here](https://github.com/robocre8/eimu_setup_application)\
(Windows, Linux \[Ubuntu], and MacOS)
{% endhint %}

{% hint style="info" %}
**NOTE:**

* Please do not run on a micro-computer (e.g. Raspberry Pi), only a PC
  {% endhint %}

### 1. Start The Application and Reset Parameters (if necessary)

* Start the application

{% hint style="info" %}
**NOTE (For Linux-Ubuntu Users)**\
you may need to add executable permission to the downloaded application.\
(see image below)\
preferably, start the start the application from terminal using - **./eimu\_app\_ubuntu\_\<OS Version>**
{% endhint %}

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2Fc3FcuRwAo9e7UwtSV5u4%2Fexe_permission_linux.jpeg?alt=media&#x26;token=e24e74c5-4881-46f2-9bc1-2ac4f39769fe" alt="" width="221"><figcaption></figcaption></figure>

* Once you start the application and connect to the **EIMU module** to your PC, you will see a page that allows you to choose the USB port, select the right port, and click **connect**. Wait for about 10 seconds (you should see a green-blue LED sequence on the EIMU during this time) and you should have a successful connect dialog appear, click ok to continue. If not, **refresh** and try again to ensure you select the right port.

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FPTXBk7lnsQ1bWkXXdDMv%2Feimu_usb_select2.gif?alt=media&#x26;token=d27b062e-1b20-47cb-bde4-f9b1b06adfc2" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
NOTE:

facing any issues, [contact](https://robocre8.gitbook.io/robocre8/contact)
{% endhint %}

* You should now see a menu on the left-hand side. If you’re setting up for the first time, reset all parameters by selecting the **RESET PARAMS** menu option and clicking the **RESET ALL PARAMS** button to start the setup process with a clean slate. Once the reset is completed, close the application, disconnect and reconnect the EIMU Module, and start the application again.

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FXKtp7fSLrKjR1S31axnP%2Feimu_reset.gif?alt=media&#x26;token=21215a07-b06d-48aa-a9be-c176ee416eb0" alt=""><figcaption></figcaption></figure>

* Once that is done, let’s get into the real deal – calibrating, testing visualization, and computing covariances.

### 2. Calibrate The Magnetometer Sensor

* This is the first step in the calibration process and the only calibration process that requires you to move and rotate the **EIMU Module**.
* Select the **CALIBRATE MAG** menu and click the **START** button. You should see a Matplotlib plot appear plotting points of different colors – red, blue, and green. Start rotating the IMU (or the container – e.g. robot – on which the IMU is mounted) slowly about the different (x, y, z) axis and see the plot update of the uncalibrated magnetometer data. Continue doing this until you see something like three balls not aligned with each other.

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FjuFubUyFStmDZ621tiZg%2Feimu_mag_cal_1.gif?alt=media&#x26;token=ec13927f-736e-4d2c-8025-1af6846d2b2b" alt=""><figcaption></figcaption></figure>

* After this, click on the plot and the plot will be paused (please do not close the plot). On the terminal, you would see some values printed out which are the calibration parameters for the magnetometer. These values are automatically saved to the microcontroller on the **EIMU module** (but you can copy the values somewhere else – e.g. a text editor – for reference or report purposes).
* Then click on the plot again and it will begin to plot the calibrated magnetometer data. Rotate the **EIMU Module** about the different axis again and you should see three balls forming which are aligned with each other.

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FnL0PxcQjYMafntaCA98l%2Feimu_mag_cal_2.gif?alt=media&#x26;token=611fb034-0513-4cb0-8d76-9a517459a1e1" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**NOTE:**&#x20;

If you do not see three balls forming or you see any of them forming a line (and not a ball or circle), you will have to repeat the magnetometer calibration process.
{% endhint %}

* With this, I say congratulations because the magnetometer has successfully been calibrated. You can now close the plot (not the app).

### 3. Calibrate The Gyroscope Sensor

* Calibrating the gyroscope is very easy. Firstly, ensure the IMU is stationary – i.e. not being moved or disturbed – on a flat surface (If the IMU is mounted on a robot for example, just place the robot on a flat surface – e.g. on the floor, or on a flat table).
* Now select the **CALIBRATE GYR** menu and click the **START** button. You should see progress bar, wait until it is finished.&#x20;
* Once it is completed, you should see a Matplotlib graph showing the uncalibrated and calibrated gyroscope data. Also, the calibration offset parameters would be printed on the terminal.

  Remember that the gyroscope calibration offset values are automatically saved on the microcontroller on the **EIMU module** (but you can copy the values somewhere else – e.g. a text editor – for reference or report purposes).

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2F66FwUFUaKlccKw6mM7z8%2Feimu_gyr_cal.gif?alt=media&#x26;token=a230a7e3-4bab-4c72-9d1a-48ce655cb985" alt=""><figcaption></figcaption></figure>

* With this, I say congratulations because the gyroscope has successfully been calibrated. You can now close the plot (not the app).

### 4. Calibrate Accelerometer Sensor

* Calibrating the accelerometer is also easy. Just follow the same steps as the gyroscope calibration above.&#x20;
* You just need to select the **CALIBRATE ACC** menu and click the **START** button.

  Don’t forget to ensure the IMU is stationary – i.e. not being moved or disturbed – on a flat surface (If the IMU is mounted on a robot for example, place the robot on a flat surface – e.g. on the floor, or on a flat table).

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FtoKvwHJbUmgEBZMNevCu%2Feimu_acc_cal.gif?alt=media&#x26;token=eadf397a-0d75-416d-8177-6b461250c35d" alt=""><figcaption></figcaption></figure>

* With this, I say congratulations because the accelerometer has successfully been calibrated. You can now close the plot (not the app).

### 5. Visualize Orientation, Change Filter Gain, and Reference Frame (as Necessary)

* You need to do this step before going to the computing variances steps.
* Select the **VIZUALIZE RPY** menu. You should now see a page with option for changing Filter Gain and Reference Frame. Also, you'll the Roll, Pitch, and Yaw values displayed.
* Click the **VIZUALIZE IMU** button, you should see a Matplotlib plot appear showing the IMU visual
* Rotate the IMU (or your robot if it is mounted on it) and see the IMU visual transforms. Check if you are okay with the orientation convergence and noise. If you are not okay with it, adjust the Filter Gain value till you are satisfied.

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FyaNlegaNMvlAnysyUNeZ%2Feimu_viz.gif?alt=media&#x26;token=0ae27870-4df2-4a34-9991-7726aaf97265" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**NOTE:**&#x20;

A higher gain value leads to faster convergence and more noise while a lower gain value leads to slower convergence but smoother signal.
{% endhint %}

* The default gain value (1.0) is generally okay for most applications but feel free to adjust as you see fit for your application.
* Change the reference frame based on your application.

{% hint style="info" %}
**NOTE on Reference Frame Selection:**&#x20;

* Use **ENU** frame if you are working on a ground robot (e.g mobile robot). This is Also the accepted frame for ROS2 development

* Use **NED** frame for drones/aircrafts

* Use **NWU** frame in place of the ENU frame if you like. it is also good for ground robots.
  {% endhint %}

* Once you are done, you can close the plot.

### 6. Compute the Orientation, Gyroscope, and Accelerometer Sensor Variances

The variences are the sensor noise in the orientation, gyroscope, and accelerometer readings. This is important when using the EIMU with sensor fusion algorithms like EKF.

* First, ensure the IMU is stationary – i.e. not being moved or disturbed – on a flat surface (If the IMU is mounted on a robot for example, place the robot on a flat surface – e.g. on the floor, or on a flat table).
* Select any of the **RPY VARIANCE**, **GYR VARIANCE**, and **ACC VARIANCE** menu button and click the **START** button. You should see the progress bar, wait until it is finished.&#x20;
* Once it is completed, you should see variance values printed on the terminal.

  Remember that these variance values are automatically saved on the microcontroller on the **EIMU Module** (but you can copy the values somewhere else – e.g. a text editor – for reference or report purposes).
* Do this for computing the orientation (RPY), rate (GYR), and acceleration (ACC) variance.

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2Fmd6uZmQuj9OnBVR8Fl1n%2Feimu_var.gif?alt=media&#x26;token=bcafab8e-6923-4ce7-bd2a-9f52abd869b6" alt=""><figcaption></figcaption></figure>

### 7. Set I2C Address (If neccessary)

* You can also set its i2c address for communication with Arduino microcontrollers.
* Select the **I2C SETUP** menu and set your preferred address value (between 1 – 127). The default address value is 104 (i.e. 0x68).

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2Fw6z2vRRgkKXVvfW1XTR5%2Feimu_i2c.gif?alt=media&#x26;token=553a23e8-d6b9-4c60-9f17-4f3f2261d02f" alt=""><figcaption></figcaption></figure>

### Reference

* [Magnetometer Calibration with the Ellipsoid Fit Algorithm](https://teslabs.com/articles/magnetometer-calibration/) – Tesla Labs&#x20;
* [2D Graph Magnetometer visualization](https://learn.adafruit.com/adafruit-sensorlab-magnetometer-calibration/magnetic-calibration-with-jupyter) – Adafruit&#x20;
* [Gyroscope Calibration with Jupyter](https://learn.adafruit.com/adafruit-sensorlab-gyroscope-calibration/gyro-calibration-with-jupyter) – Adafruit&#x20;
* [Reading Data From MPU9250 IMU](https://github.com/bolderflight/invensense-imu/) – Bolder Flight&#x20;
* [IMU Data Visualization with Vpython](https://www.youtube.com/watch?v=iQ2zX4_Ftv8) – Paul McWhorter&#x20;
* [IMU Madgwick Filter Algorithm](https://github.com/CCNYRoboticsLab/imu_tools/tree/humble/imu_filter_madgwick) – CCNYRoboticsLab \[Here’s a link to the Arduino Library I created from it – [imu\_madgwick\_filter](https://github.com/samuko-things/imu_madgwick_filter)]


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://robocre8.gitbook.io/robocre8/tutorials/how-to-calibrate-and-setup-the-eimu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
