Get motor angles with Python-LEGO Mindstorms

One index when controlling the EV3 is to get the angle of the motor. Also, when doing machine learning while using Python, some data is always required, but you may want to acquire motor data together with sensor data. This time, I will monitor how many angles the motor is rotating in real time in the Python environment of EV3.

About EV3

Educational version LEGO® MINDSTORMS EV3 (hereafter EV3)


The content of this article is based on the following books. The basic control of EV3 using Python is covered below.

Introduction to AI starting with robots

Environment in this article

Source code

from ev3dev2.motor import LargeMotor, OUTPUT_B
from ev3dev2.button import Button
import time

button = Button()
lm_bT = LargeMotor('outB')

def main():
    while not(button.backspace):
    lm_bT.stop(stop_action = 'brake')

if __name__ == '__main__':


The value of the motor angle changes to + when turned in the positive direction and to-when turned in the negative direction. This time, the motor has tires, but for example, if the tire makes one revolution in the positive direction, the angle value will change from 0 to 360.


This time, I used the position method to check the angle of the motor. By recording this data and specifying the position, it will be possible to control the motor accurately.

Recommended Posts

Get motor angles with Python-LEGO Mindstorms
Take a screenshot of the LCD with Python-LEGO Mindstorms
Get started with MicroPython
Get Tweets with Tweepy
Get started with Mezzanine
Get country code with python
Get started with Django! ~ Tutorial ⑤ ~
Get started with influxDB + Grafana
Get Youtube data with python
Get information with zabbix api
Get started with Django! ~ Tutorial ④ ~
Get started with Django! ~ Tutorial ⑥ ~
Get thread ID with python
Get started with Python! ~ ② Grammar ~
Get image features with OpenCV
Get stock price with Python
Get home directory with python
Get keyboard events with python
Get Alembic information with Python
Get another tab with pyppeteer
Get ranking with Rakuten API