MicroPython Tutorial I

Mark Lucking
3 min readAug 1, 2019

I got a gig to teach MicroPython in a summer camp over the summer and I documented the experience and decided to compile a quick cookbook of the code I used, here it is.

Preference

Ok I going to assume you already visited ev3dev.org link thru the LEGO link and got the MicroPython environment setup. Assuming too that your using more then one robot, so you need to have renamed your Brickman OS with the /usr/sbin/ev3dev-config program as well. I also used MICROSOFT’s Visual Studio Code [MVSC] app with the LEGO mindstorms extension to write the code. You don’t have too, but it’ll make your life easier if you do. Finally I prefer to open a separate terminal window, thru which I made a SSH connection to the brick to run my code. Again its optional, you can open a terminal window thru MVSC, but I like to use a separate terminal connection.

Lesson I

Ok. You got everything loaded and you’re logged in, let’s start coding. Here our first template. Type it in and make sure you give it a name with an extension of “.py”. This script lets you run different code snippets when you press different keys on the brick. In our case we’re just printing out the name of the button your hitting.

Brick Buttons

#!/usr/bin/env pybricks-micropython 
from pybricks import ev3brick as brick
from pybricks.parameters import Button
while True:
if Button.DOWN in brick.buttons():
print(“DOWN button”,Button)
if

--

--

Mark Lucking

Coding for 35+ years, enjoying using and learning Swift/iOS development. Writer @ Better Programming, @The StartUp, @Mac O’Clock, Level Up Coding & More