Pybricks: MicroPython for LEGO

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
laurensvalk
Posts: 3
Joined: Fri Jun 19, 2020 9:39 am

Pybricks: MicroPython for LEGO

Post by laurensvalk » Fri Jun 19, 2020 10:40 am

Hi everyone - we're excited to finally share with you a whole new family of MicroPython ports: Pybricks.

Pybricks brings MicroPython to all LEGO smart devices that support firmware updates. Now people can program their LEGO creations with MicroPython and make them autonomous, whether it's MINDSTORMS robots, smart trains, autonomous Technic excavators, or your own custom builds.

We have working MicroPython ports for almost all upgradeable LEGO hubs. Some of them are already stable, others are still in progress.

- LEGO MINDSTORMS EV3 (Unix). Stable. LEGO uses this as the official EV3 MicroPython.
- LEGO Control+ (STM32L431). Currently in beta.
- LEGO City Hub (STM32F030RC): Currently in alpha.
- LEGO Move Hub (STM32F070RB): Currently in alpha.
- LEGO SPIKE Prime Hub (STM32F413VG): Currently in alpha.

See also our development roadmap.

Users can install the firmware and run scripts with our online app, Pybricks Code. The end-user API can be found here. We are also working on a Python library and utility that lets you interface with Pybricks hubs while offline.

In terms of the overall direction of the project, it is worth noting that our core audience is perhaps a bit different from the average MicroPython user. We try to keep everything very beginner-friendly: for many of our users, this is their very first text-based programming experience. And for the most part, they will not be using custom electronics, just LEGO motors and sensors. Finally, due to flash space constraints, not all MicroPython features can be enabled.

Still, we try to make it fun for seasoned MicroPython developers as well, and this side of the project will probably grow over time.

Our source code is MIT licensed. It's available on our GitHub. We include MicroPython a submodule, with a handful of patches for which we usually ultimately create PRs upstream. Quite a few of our contributions have been merged this way already.

We aim to keep contributing to upstream MicroPython going forward. We would like to take this opportunity to thank the whole MicroPython community for making this possible.

We're happy to answer any questions in this topic, but we also welcome generic discussion and specific questions at our issue tracker. We look forward to hearing what you think!

OutoftheBOTS_
Posts: 784
Joined: Mon Nov 20, 2017 10:18 am

Re: Pybricks: MicroPython for LEGO

Post by OutoftheBOTS_ » Fri Jun 19, 2020 9:44 pm

Thanks for both your work and for posting here.

I for 1 have been very excited about Lego move into MP as I own 4 EV3s and my older kids used them to learn robotics and compete at robotics comps but ended up moving away from Lego because having to use the Labview programming environment.

I did install MP onto a SD card for EV3 and visual studio IDE fro my son to do an school assignment for his digital technologies subject and both of us found it much better than labview for both use and performance.

I help a number of teacher with solving robotics problems and setting up teaching projects for the their kids. I did go down the school the other day and have a play with their spike prime hub.

I do realize that the development of spike prime and the new mindstorms(spike prime in disguise) isn't part of PyBricks but am hoping that both projects do talk to each other and work together.

I see pybricks is fully open source do you know it the firmware for spike prime will also become open source?

User avatar
marfis
Posts: 197
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: Pybricks: MicroPython for LEGO

Post by marfis » Sat Jun 20, 2020 6:33 pm

Really nice project setup and great to see a popular HW being MicroPythonized.

Good for me too since it is likely not too far away when my kids want to have a lego tech kit😉

laurensvalk
Posts: 3
Joined: Fri Jun 19, 2020 9:39 am

Re: Pybricks: MicroPython for LEGO

Post by laurensvalk » Sun Jun 21, 2020 9:37 pm

Thanks for both of your replies. If you try it, it would be great to have your feedback.
I did install MP onto a SD card for EV3 and visual studio IDE fro my son to do an school assignment for his digital technologies subject and both of us found it much better than labview for both use and performance.
That's nice to hear. I guess you already knew based on the import statements, but that was based on pybricks-micropython too. You'll find it very easy to try it on the other hubs, then.

Since you asked, we do have a working version of Pybricks for SPIKE Prime as well, but it isn't as fully featured yet. We're focusing on the other hubs first, since those don't have MicroPython support already. But if the community would like to see this happen, we'll probably work on it more. I don't know if the official SPIKE Prime firmware is open source.
Good for me too since it is likely not too far away when my kids want to have a lego tech kit😉
They even come in LEGO City train sets these days. City Hub support is coming soon. But if you're on this forum, you can probably figure out how to build it from source already. :D

esaens
Posts: 1
Joined: Tue Jun 30, 2020 1:13 pm

Re: Pybricks: MicroPython for LEGO

Post by esaens » Tue Jun 30, 2020 1:17 pm

Hi,

I am 7 and I am taking my first steps with Pybricks and micropython.

Using the education trainer robot I made it go in a square using the code below. I am trying to shorten the code and create an iterative loop with a count of 4 (like I would in EV3-G) for make the code shorter.

Can you please suggest the code I need ?

#!/usr/bin/env pybricks-micropython

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port
from pybricks.robotics import DriveBase

ev3 = EV3Brick()
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
robot = DriveBase(left_motor, right_motor, wheel_diameter=55.5, axle_track=104)

robot.straight(100)
ev3.speaker.beep()
robot.turn(110)
robot.straight(100)
ev3.speaker.beep()
robot.turn(110)
robot.straight(100)
ev3.speaker.beep()
robot.turn(110)
robot.straight(100)
ev3.speaker.beep()
robot.turn(110)

User avatar
dhylands
Posts: 3415
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Pybricks: MicroPython for LEGO

Post by dhylands » Tue Jun 30, 2020 6:16 pm

One way would be to use a for loop, so your code would now look like this:

Code: Select all

#!/usr/bin/env pybricks-micropython

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port
from pybricks.robotics import DriveBase

ev3 = EV3Brick()
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
robot = DriveBase(left_motor, right_motor, wheel_diameter=55.5, axle_track=104)

for i in range(4):
    robot.straight(100)
    ev3.speaker.beep()
    robot.turn(110)
Here's a link to learn more about loops in python: https://www.learnpython.org/en/Loops

laurensvalk
Posts: 3
Joined: Fri Jun 19, 2020 9:39 am

Re: Pybricks: MicroPython for LEGO

Post by laurensvalk » Wed Jul 08, 2020 7:54 am

So what can you do when you combine MicroPython with LEGO? Here's a fun demo:

Image

And thanks @dhylands for helping out in the post above.

OutoftheBOTS_
Posts: 784
Joined: Mon Nov 20, 2017 10:18 am

Re: Pybricks: MicroPython for LEGO

Post by OutoftheBOTS_ » Wed Jul 08, 2020 9:03 pm

It is certainly a nice direction for Lego to be moving in.

Post Reply