ev3dev Research Notes

These are some of our findings when playing around with ev3dev.

Recalibrate the Gyro drift

The EV3 gyro calibrates itself on power-up, but this calibration may be incorrect if the gyro is moving during this time. To re-calibrate the gyro drift, there are 3 ways…

  • Unplug and re-plug the gyro
  • Change the mode (eg. from rate to angle) (only works for models ending with N2 or N3)
  • Reset the port (works with models ending with N4 to N8)

(Credits to the Seshan brothers for the info on re-calibration method for different model numbers)

The first and second is trivial. To do the third in EV3DEV, you’ll need to change the port mode (…NOT the sensor mode).

from ev3dev2.port import *

legoPort = LegoPort('in1')
legoPort.mode = 'auto'

..but after doing the reset, it will take a few seconds before the gyro is available. Sometimes, the gyro will not become available and you’ll need to do the reset again. To make it easier, you can use the following function to reset the port and automatically retry until the gyro is detected. Your gyro must be stationary when running this function.

from ev3dev2.port import *
from ev3dev2.sensor.lego import *
import time

def resetGyro(port, timeout=-1):
    endTime = time.time() + timeout
    while True:
        print('Resetting port')
        legoPort = LegoPort(port)
        legoPort.mode = 'auto'
        for _ in range(10):
            if time.time() > endTime and timeout > 0:
                print('Reset failed. Timeout reached')
                print('Gyro detected')
                print('Gyro not detected. Trying again.')
        print('Reset failed. Resetting again.')


The calibration is within the sensor itself, and will stay until the port is reset again or the gyro is powered off. This means that you can run the above program independently, and all programs run after it will see a properly calibrated gyro.

ev3dev is slow

Tested on ev3dev-jessie-2017-09-14. Performance may have improved on newer versions.

Performance is especially poor when using the default python ev3 modules. A simple two-sensor line following program can run as slow as 30 loops per second, compared with 300+ loops per second on LeJOS and 400+ on EV3-G. Using ev3fast.py will improve performance to 200+ loops per second, and supports nearly all EV3 sensors.

Unless your project requires high speed, this should not be a deciding factor on whether you should use ev3dev or some other firmware. The benefit of having support for just about any programming language can easily out-weight the performance drawbacks.

LED operations can severely slow the system down

Operations that changes the ev3’s built in LED (eg. turning them on or off), can cause a severe system slowdown. This slow down persists even after your program terminates, and it stacks with every LED operations.

If your program calls an LED operations every loop (eg. to set color or turn them on/off), you may find your program slowing down to as low as 4 loops per second. Even after the program ends, the slow down will continue to affect the entire system and any program that you run, and it may last for several minutes.

If your program needs to use the LED, it should keep track of the LED state and only send the LED commands if there is a change from the current state.