MBC IMU Gyro × EV3 clev3r

Read the IMU gyro with clev3r in three steps

A clev3r (EV3 BASIC) program goes in this order: first create the project and pick the port, then set the gyro's mode, and last read values and show them on the EV3 screen. Follow the steps on the left and the program on the right grows with you. Turn, raise and shake the robot in the simulator to see what the EV3 screen shows.

1

Create the project and pick the port

clev3r needs no extension and no files: on the EV3 the gyro acts as a stock LEGO gyro (type 32), so you read it with the Sensor commands. The first line, folder, picks the folder on the EV3.

  1. Install clev3r (this site was tested with v1.7.1.0).
  2. Turn on the EV3 first, then plug the gyro into the port below (keep the robot still then).
  3. Create a program and write these lines.
  4. Press "Compile and download", then run it from the folder starting with MBC_ in the EV3 file menu.
Which port is the gyro on?

The first number in the program (for example Sensor.SetMode(1, 0)) is the port; 1 to 4 are the EV3 ports 1 to 4.

2

Set the mode

The gyro has 7 "modes", each sending 1 to 4 numbers. Sensor.SetMode(port, mode) picks one. Use one mode per program: the EV3 needs about 0.5 s every time the mode changes.

Pick a mode (it follows if you pick a reading from another mode in step 3):

3

Read and show on the screen

Sensor.ReadRawValue(port, which) takes a number of the current mode (counting from 0), and LCD.Text writes it on the EV3 screen. The screen shows only English letters and numbers, so the labels are short English words. Click a reading and the program and screen 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 = sending 0x11 to the sensor (the gyro reset card); when you pick that card the simulator zeroes once (as when the program starts). Firmware version 400 is an example value.

An example for every reading

Full examples


        

!


        

!


        

!

Good to know

  1. Unplugged reads 0: when clev3r cannot read the sensor, Sensor.ReadRawValue gives 0 and the program keeps running, so "heading 0" can also mean it is not connected. Check with the "Is the sensor connected?" card (Sensor.GetType = 32) first.
  2. One mode per program: the EV3 needs about 0.5 s every time the mode changes. Use mode 0 for turning and mode 6 for slopes.
  3. Zeroing: sending 0x11 to the sensor (Sensor.SendUARTData) zeroes all four headings, the same as the EV3-G "Gyro reset"; keep the robot still then. Turning right makes the heading bigger; one turn = 360 and it keeps adding up.
  4. The EV3 screen shows only English letters and numbers, so the labels are short English words (ANGLE, FUSED, RATE, TILT…). Modes 2 to 6 need sensor firmware v4.0 or later.