robocre8
AboutContactSocial
  • robocre8
  • About
  • Contact
  • Social
  • DOCUMENTATIONS
    • MoboBot Documentation
    • EPMC Documentation
    • EIMU Documentation
  • EIMU TUTORIALS
    • How To Calibrate And Setup The EIMU
    • How To Use EIMU With ROS2
    • How To Use EIMU With Arduino
  • EPMC TUTORIALS
    • How To Setup DC Motor PID Speed Control With The EPMC
  • How To Use the EPMC With ROS2
  • How To Use EPMC With Arduino
  • TUTORIALS
    • How To Install ROS2 Humble Desktop On PC (FULL INSTALL)
    • How To Install ROS2 Humble Base On Raspberry Pi 4B (FULL INSTALL)
Powered by GitBook
On this page
  • EIMU Module I2C Connection Overview
  • EIMU Arduino Test Code - Read RPY
  1. EIMU TUTORIALS

How To Use EIMU With Arduino

Learn how to test and integrate the Easy IMU (EIMU) in your Arduino project

PreviousHow To Use EIMU With ROS2NextHow To Setup DC Motor PID Speed Control With The EPMC

Last updated 3 months ago

EIMU Module I2C Connection Overview

When using the EIMU with I2C, you’ll need to power it from its 5V input port, while the 5V3 pin of the EIMU I2C port will be connected to the Arduino-based microcontroller power for reference during I2C communication.

For example, if it is connected to an ESP32 microcontroller, the 5V3 pin of the EIMU I2C port will be connected to the ESP32 3.3v power (while the EIMU power port will use 5V).

Also, if it is connected to an Arduino UNO, MEGA, or NANO, the 5V3 pin of the EIMU I2C port will be connected to the Arduino microcontroller’s 5V power (the EIMU power port will still use 5V, most likely also from the microcontroller also).

Don’t forget to ensure the EIMU and the Arduino-based microcontroller are connected to a common ground.

EIMU Arduino Test Code - Read RPY

  • Ensure you have calibrated and setup the EIMU I2C address following this tutorial.

  • Download the eimu_arduino I2C comm library from here by clicking on the green Code button.

    if you download it, extract it and change the folder name to eimu_arduino

  • Move the downloaded library file - eimu_arduino - to your Arduino library folder

    e.g on linux: ... home/Arduino/libraries/

    e.g on windows: ... Documents/Arduino/libraries/

    (or any where your arduino libraries are stored)

  • restart your ArduinoIDE and copy this example code into your project to test the EIMU Module (feel free to modify it to your taste).

read_rpy.ino

/*
 * Basic example code shows how to read orientation data from the MPU9250 EIMU Module
 * which have been succesfully calibrated with filter and covariances setup
 *
 * The code basically reads roll, pitch, and yaw values from the MPU9250 EIMU Module connected to it.
 * read printed values from serial monitor or serial plotter.
 *
 * you can copy the code and use it in your project as you will.
 */

// Easy IMU i2c communication library
#include <eimu.h>

// please update with the address with that which you set when doing
// calibration and filter setup with the eimu_setup_application
uint8_t imuAddress = 104; // i.e 0x68 in HEX
EIMU imu(imuAddress);

float toRad = 2 * PI / 360;
float toDeg = 1 / toRad;

float roll, pitch, yaw; // create variables to store orientations
String ref_frame;

long prevSampleTime;
long sampleTime = 100; // millisec

void setup()
{
  // start i2c communication
  Wire.begin();

  // setup serial communication to print result on serial minitor
  Serial.begin(115200);

  // wait for the imu module to fully setup
  for (int i = 1; i <= 6; i += 1)
  {
    delay(1000);
    Serial.println(i);
  }

  // change the reference frame to ENU frame (0 - NWU,  1 - ENU,  2 - NED)
  imu.setRefFrame(1);

  // check the refence frame the IMU is working in (0 - NWU,  1 - ENU,  2 - NED)
  int ref_frame_id;
  imu.getRefFrame(ref_frame_id);
  if (ref_frame_id == 0)
    Serial.println("Reference Frame is North-West-Up (NWU)");
  else if (ref_frame_id == 1)
    Serial.println("Reference Frame is East-North-Up (ENU)");
  else if (ref_frame_id == 2)
    Serial.println("Reference Frame is North-East-Down (NED)");

  // wait for the imu module to fully setup
  for (int i = 1; i <= 4; i += 1)
  {
    delay(1000);
    Serial.println(i);
  }

  prevSampleTime = millis();
}

void loop()
{

  if ((millis() - prevSampleTime) >= sampleTime)
  {
    /* CODE SHOULD GO IN HERE*/

    imu.getRPY(roll, pitch, yaw); // read roll, pitch, yaw in radians

    Serial.print(roll, 4);
    Serial.print(", ");
    Serial.print(pitch, 4);
    Serial.print(", ");
    Serial.println(yaw, 4);

    // Serial.print(roll * toDeg, 1);
    // Serial.print(", ");
    // Serial.print(pitch * toDeg, 1);
    // Serial.print(", ");
    // Serial.println(yaw * toDeg, 1);

    prevSampleTime = millis();
  }
}
  • read output from serial monitor.

  • adjust the code to your taste and use.