MBC IMU Gyro × EV3-G (EV3 Lab software)

Read the IMU gyro with EV3-G in three steps

In the EV3 software (EV3-G), the IMU gyro shows up as a LEGO Gyro Sensor. So you do not import a library: you read it with the Gyro Sensor block in the right mode. Work through the steps on the left and the blocks on the right grow with you. These pictures were taken in EV3-G after opening each program (100% size, English interface), so they look exactly like the software.

1

Start: Start block + Loop

You need to read the sensor again and again. A new program already has the green Start block. Attach an orange Loop block after it and put a Wait block inside, so it reads every 0.1 seconds.

  1. Open the EV3 software (EV3-G) and make a new project.
  2. Drag a Loop from the orange Flow Control tab and attach it after the Start block (it repeats forever by default).
  3. Drag a Wait block into the loop, choose the Time mode and set it to 0.1 seconds.
2

Meet the reading blocks (Gyro Sensor)

On the EV3, the IMU gyro shows up as a LEGO Gyro Sensor (not an infrared sensor). Drag the Gyro Sensor block from the yellow Sensors tab and choose the mode at the bottom left; the number at the top right is the port: choose 1 (the sensor is in port 1). Each mode means something different from the stock gyro:

BlockWhat you getRange
Measure → Anglegyro 3D heading-32768 ~ 32767 degrees (0 at power-on / reset, bigger turning right)
Measure → Ratefused heading (not degrees per second)-32768 ~ 32767 degrees (0 at power-on / reset, bigger turning right)
Measure → Angle and Rate: Anglegyro 1D heading-32768 ~ 32767 degrees (0 at power-on / reset, bigger turning right)
Measure → Angle and Rate: Ratemagnetic heading-32768 ~ 32767 degrees (0 at power-on / reset, bigger turning right)
Resetzero all four headings—

Use blocks of only one mode in a program. Every mode change makes the EV3 pause for about 0.5 seconds.

3

Show it on the EV3 screen

Use the Text block from the red Data Operations tab to join a name (for example ANGLE) and the reading, then feed it into the green Display block (mode Text → Grid, Y = the line). The yellow and orange lines are data wires: drag one from the sensor to the Text block, and one from the Text block to the Display block. Put a "Display → Reset Screen" block before the loop. Click a function and the blocks and result change to its example.

Sensor simulator: the left picture is seen from above (heading), the right one from the side (pitch). Drag the sliders and press the buttons, and watch the output change

The simulator is only a picture: values come from the robot's direction and angle on screen, not the sensor's own algorithm. The "Zero" button = the gyro "reset"; the pitch slider and the shaking rates cannot be read in this software (use Pybricks / clev3r).

Block example for each function

Every value EV3-G can read has a small program you can copy (sensor in port 1). Press "Try it" to jump to step 3.

What EV3-G cannot read: the yaw rate, pitch and pitch rate (modes 2, 5 and 6, added in firmware v4.0). For these, use Pybricks or clev3r. Magnetometer trust, face up, raw 9-axis values and the calibration commands cannot be read on the EV3 at all (use Arduino, mBlock or micro:bit).

Things to know

  1. Plug the sensor into port 1. If you use another port, change the port number on the block. Switch the EV3 on first, then plug in the sensor (keep the robot still then); if the number never changes, unplug it and plug it in again.
  2. "Rate" is not degrees per second: this gyro puts the fused heading in "Rate", and the gyro 1D and magnetic headings in "Angle and Rate". For degrees per second, read mode 2 with Pybricks / clev3r.
  3. Use one mode per program. Each mode change makes the EV3 pause for about 0.5 seconds, and a racing robot can lose control; "reset" needs no mode change.
  4. When the sensor is unplugged: the EV3 cannot read it, the number becomes "not a number" and the screen shows ----. Each reading also waits about 1.2 seconds. The program does not stop, and it works again when you plug the sensor back in.
  5. Direction: turning right makes the heading bigger, left smaller; one turn = 360 and it keeps adding up. If right makes it smaller, the sensor is mounted upside down.
  6. English interface: the block icons are the same in other languages; only the menu text differs.
  7. For complete projects (turning 90°, a square, driving straight …) see the EV3 examples page; the first 5 examples have an EV3-G file to download.