Pybricks introduces block coding

Posted by ,

Pybricks is an open source, community project for programming all current Powered Up hubs and running the code autonomously without the need for Bluetooth tethering to a smart phone.

I've written a couple of articles about it previously, explaining what it is and how to use it with Technic Control+ hubs, turning what are otherwise useless devices into something powerful and versatile.

A potential stumbling block to its use was that it required knowledge of Python, which is easy for those with a programming background to pick up, but could appear daunting to those without.

That has now been addressed with the latest release, which introduces a graphical block-progamming environment that will be familiar to anyone who's used Scratch or similar.

This game-changing new release also supports hub-to-hub communication via Bluetooth, and multitasking, making it even more versatile.

You can read an extract of the press release and find out how to get coding after the break.


Endless creativity and fun with smart LEGO bricks using Pybricks

  • For the first time ever, fans of all LEGO themes can bring their smart bricks together in a single app for endless possibilities and creativity.
  • Make your LEGO City trains, LEGO BOOST creatures, LEGO Technic machines, or SPIKE and MINDSTORMS robots come alive. All with the same code blocks!
  • Programs are saved directly onto the LEGO hubs. Just press the button and go. No permanent connections required.
  • Hubs communicate wirelessly so you can build at every scale.
  • Accurate vehicle control using built-in gyro for robot missions.
  • Smooth transition from blocks to Python with live preview.
  • Low floors and high ceilings: Easy to get started, but endless possibilities by mixing blocks with Python.
  • Exclusively available to Pybricks supporters on Patreon.

Today, the Pybricks team presents the first beta release of block coding for all modern LEGO hubs. For the first time, fans of all LEGO themes can bring their smart bricks together in a single app for endless possibilities and creativity.

Whether you want to make smart train layouts, autonomous Technic machines, interactive BOOST creatures, or super-precise SPIKE and MINDSTORMS robots, you can do it with Pybricks.

Pybricks is beginner-friendly and easy to use. There’s no need to install complicated apps or libraries either. Just go to https://beta.pybricks.com, update the firmware, and start coding.

And now for the first time, no prior Python coding experience is required. You can code with familiar but powerful blocks, and gradually switch to Python when you’re ready. The live preview makes it easy to see how your blocks translate to Python code.

Meanwhile, more seasoned builders and robotics teams will enjoy advanced features such as color sensor calibration or builtin gyro control for drive bases.

The new block coding experience is exclusively available to our supporters on Patreon. You can sign up for a monthly subscription or make a one-time pledge in our shop for lifetime access.

Python coding remains entirely free and open source, and continues to be supported by a community of developers and LEGO enthusiasts around the world. Improvements are made almost every day, with the lead developers actively engaging with the community for ideas, bug fixes, and brand new features.

So grab your LEGO sets and start coding!

18 comments on this article

Gravatar
By in United Kingdom,

This has made me very happy

Gravatar
By in Belgium,

Great!!

Gravatar
By in United Kingdom,

This shows that Powered Up was engineered as an excellent piece of flexible tech that provides important upgrades compared to previous generation, but the launch was botched by Lego as lacked proper support and official sets did not fully utilize its power.

In the long term I am sure this will be successful and widely used given all the capabilities, but bit of a shame that it takes a team of enthusiasts to finish the product instead of Lego doing so.

Gravatar
By in United States,

This is good new indeed for the LEGO community.

P.S. I don't understand the love Python has gotten over the past 5-10 years. It should have died long ago.

Gravatar
By in Germany,

@followsclosely said:
"P.S. I don't understand the love Python has gotten over the past 5-10 years. It should have died long ago."
Why? It is versatile and relatively easy to learn and implement.
What is it you dislike about it?

Gravatar
By in United States,

Short answer: Python is easy. Becuase it's popular and easy to get stuff done, stuff gets written by just about anyone.

In my 25+ years experence maintaining and hardening production systems I have seen more security holes (per lines of code) with python solutions than any other language by far. It's not Pythons fault per se, it is really a process issue in most organizations.

Gravatar
By in Canada,

@AustinPowers said:
" @followsclosely said:
"P.S. I don't understand the love Python has gotten over the past 5-10 years. It should have died long ago."
Why? It is versatile and relatively easy to learn and implement.
What is it you dislike about it? "


True. As great as C is (in terms of speed), it is not that easy to properly manage the memory usage, pointers, dereferencing etc. You can learn Python and do something meaningful with it in a matter of hours - you might not remember all of it at the time but you would have a useful program which is reasonably fast. Also quite useful to have an easy interface to automate most things on a computer.
I suppose, with Python, the difficulty is becoming to figure out which functions are in which library - nothing a quick search on the internet cannot tell you in a few seconds.

As far as PyBrick is concerned: Great! but why is it that a company with the resources of Lego is not able to service itself its own products - only the best is good enough, right? Right....

Gravatar
By in Germany,

@followsclosely said:
"Short answer: Python is easy. Becuase it's popular and easy to get stuff done, stuff gets written by just about anyone.

In my 25+ years experence maintaining and hardening production systems I have seen more security holes (per lines of code) with python solutions than any other language by far. It's not Pythons fault per se, it is really a process issue in most organizations."

In can understand your reasoning, but like you say, that's not the fault of the programming language.

Gravatar
By in Canada,

Really like the idea, especially the fact the translates the blocks into code. As someone learning Python, I see that as a big help.

I appreciate the amazing work that the PyBricks team has put into this project over the years, but to be totally honest I am a little let down that this is paywalled. I wouldn't mind supporting them, but it feels like a non-trival amount, especially for someone only casually interested in tinkering. I wonder if it is the right feature to paywall.

Gravatar
By in Canada,

@followsclosely said:
"Short answer: Python is easy. Becuase it's popular and easy to get stuff done, stuff gets written by just about anyone.

In my 25+ years experence maintaining and hardening production systems I have seen more security holes (per lines of code) with python solutions than any other language by far. It's not Pythons fault per se, it is really a process issue in most organizations."


I am not quite sure I would use Python for anything 'production' that is 'customer' or 'internet' facing. I don't mind an application that is used internally for the research department (for example) but not something that people at large (internet facing) can probe and dig into. I would not even know how to secure code for python - I have not played with the auth library much - I use python mostly of AI and ML as you can have a running model in less than 10 lines.

Gravatar
By in United States,

@followsclosely said:
"Short answer: Python is easy. Becuase it's popular and easy to get stuff done, stuff gets written by just about anyone. "

My guy. This *is* the application where you want anyone to be writing code. This is hobbyist Lego personal projects. Not security critical. This is one great Python use case, many of which exist, and are among the reasons the language has not died 5+ years ago.

Gravatar
By in Mozambique,

Anyone know if/when the coding blocks will be free to use?

Gravatar
By in Netherlands,

Please compare it with Bricklife Scratch. I think using full featured Scratch as starting point has benefits. One of the downsides right now for BL Scratch is that you can't read the light sensor by brightness, it only reads colours.
Big hurdle with PyBricks is the custom bootloader and pain-in-the-ass Windows USB drivers. You need to reinstall a Windows driver for EVERY hub you insert. In a classroom that is really frustrating. BL Scratch works with the default LEGO firmware, which is much easier to use.

Another problem with PyBricks is the dependecy on Chrome. BL Scratch runs with the Scratch Link Bluetooth add-on with any browser. So on a Chromebook you are limited to PyBricks, on Mac/PC you can use both.

Gravatar
By in Netherlands,

The object-everything (myhellokitty.cuterobot.whiteandbluemotor.turnaround.leftlike(14)) approach which makes readability a mess, the library includes that are highly complex compared ot other languages (for education purposes all LEGO/math functions should have been included invisibly in the background by default), and the annoying structure-by-indentation format.

Gravatar
By in United Kingdom,

@followsclosely said:
" ""P.S. I don't understand the love Python has gotten over the past 5-10 years. It should have died long ago.""
In my 25+ years experence maintaining and hardening production systems I have seen more security holes (per lines of code) with python solutions than any other language by far. It's not Pythons fault per se, it is really a process issue in most organizations."


But that is just saying that whatever language is being flavour of the month/year/decade should have died long ago.

40+ years ago I could've said the same about Fortran (because all the newbs in the tutor group happened to be learning Fortran to bash out stats analyses - badly!). After that, all the bad coding was appearing in C, then C++ caught the popular imagination, a brief flirtation with Tcl and so on and so forth. At every point in time, there is a pile of people who chuck out code that makes one want to scream.

And even the sorts of problems have changed over the decades: you are talking about security holes. We never even used to talk about the concept of "security holes" (in the most common computing cases): desktop computers were not networked, a buffer overflow meant one person's machine crashed, a pita but not a security issue.

Nowadays, we have the not-very-good people dropping their code into servers that serve the web - and all their bad habits are suddenly so much worse. Coincidentally, Python has become popular, hence your observations.

Gravatar
By in United Kingdom,

@HOBBES said:
"As far as PyBrick is concerned: Great! but why is it that a company with the resources of Lego is not able to service itself its own products - only the best is good enough, right? Right.... "

Huh? LEGO services its products a lot better than most! From the first MindStorms on, they provided environments that were a decent match for "whatever is the current 'best' way of introducing coding".

And, unlike many other companies, LEGO have been good about letting coding enthusiasts delve deeper into the system and produce their own alternatives. Which means that we *can* have something like PyBricks, which presented a different approach to the LEGO Powered Up App. And it is only one of the alternatives to the Powered Up App.

Alternatives to the LEGO-produced products are a Good Thing, but you can not expect LEGO to be creating all of them! If one - or more - of the third-party alternatives turn out to be markedly better (for your Use Case!) then that is something to celebrate, not any reason to complain about what LEGO has released. Ironically, this is only being discussed because PyBricks has "finally caught up with LEGO" in providing a blocks-coding environment!

Unless, of course, you can point to a case where the LEGO product was actually defective (in terms of *its* goals, not necessarily your own), in which case please describe that failure.

Gravatar
By in United Kingdom,

@martiniman said:
"Please compare it with Bricklife Scratch...
"


Thanks for point out that there is another alternative.

"Big hurdle with PyBricks is ... The object-everything... and the annoying structure-by-indentation format.
"


Although you needn't be quite so down on Pythonisms to do so (horses for courses and all that).

(Well, except for the use of "meaningful white space", of course: Makefiles have an excuse - they are very old and knew no better - , Occam was embarrassing in this regard and Python just has no excuse :-) )

Gravatar
By in United States,

Isn't this essentially the program "Scratch 3"? It comes preloaded on Raspberry Pi and has a Lego Edition to it that can be downloaded.

Return to home page »