This article contains a guide to the new micro:bit Python Editor, currently in Beta python.microbit.org/v/beta

Python Editor Overview

Python Editor overview

A bright, colourful interface contains a range of features that aim to make text-based coding more accessible to students who may find it hard to engage with the subject by removing known barriers to learning. The editor is also designed to make computer science appeal to more diverse cohorts and hence expand their horizons.


How to use the Editor


The editor is divided into two panels. On the left of the screen is the sidebar menu. This menu contains buttons that open the Reference, Ideas, API, Files, Settings and Help menus. On the right of the screen is the edit window, where you can make changes to your Python Code.


Editing a project


You can make edits to your program in the edit window on the right-hand side of the screen. For example, if you want to change the image from the default HEART to HAPPY, you can delete the word for the image and replace it. The auto-complete feature suggests different images that you can choose from the drop-down list. If you make a mistake, you can use the undo or redo buttons to correct it.

Downloading or Flashing a program

The simplest way to download a project to the micro:bit is by connecting the browser to the micro bit device. Make sure your micro:bit is connected via the USB cable.

  1. Click on Connect to open a dialogue in the browser which will tell you that the python.microbit.org editor wants to connect to your micro:bit.
  2. Select your micro bit and then press Connect
  3. The editor updates to tell me the micro bit is "ready to flash"
  4. Click on Flash to send the code to the micro bit device.


You can still download a .hex file or a .py script if you want to by using the more (three dots) menu next to the Flash button. You can also disconnect from the micro:bit, which takes the editor back to its default state, where you can download a project .hex file or .py script.

Loading a program

animated gif of loading a file


To load a program, click on the Load button to open the files dialogue. From here, select the .hex or .py file that you wish to load and then click open. Alternatively, you can drag and drop a .hex file or .py script into the editor.

Using the Reference menu

The reference menu contains working examples of code that you can use in your project. The examples relate to market bit features and Python concepts. Here we are using an example for the micro:bit buttons.


  1. Navigate to the Buttons item in the Reference menu. 
  2. Drag and drop or click on the insert button to add your code to the editor. You can put this anywhere in the program. In this example, we are replacing the existing program with the new code.

Using the Ideas menu


The ideas menu contains complete Python projects to try out on the micro:bit. To use them, replace the code in the edit window with the code from the idea. You can then edit the code to make it your own.

Using the API

The API (Application Programming Interface) menu provides a more detailed overview of the MicroPython commands that you can use with the micro:bit. This can be useful when you want to understand more about what a particular piece of code is doing and what options or arguments you can use with a function.


You can access it from the sidebar menu or by using the autocomplete feature, which offers you a range of options via  a dropdown menu. You can click on the Python logo to be taken to the API entry for the option you are looking at.

The documentation is also published in full at https://microbit-micropython.readthedocs.io/en/v2-docs/


Using the serial console

Coming soon...

Errors

See our guide to troubleshooting errors in the micro:bit Python Editor for more information


As with any written language, you occasionally run into errors that you will need to fix in order for your program to run.


The Python Editor shows you the errors in your code, so you know what you need to fix before flashing your code to the micro:bit.


Errors are indicated in the margin by a red dot or grey square. They are also indicated  by using  a red triangle or a red wavy underline:

 
Setting the language


Click on the setting cog in the bottom left of the screen, choose languages and then choose the language from the menu. 


Using the projects menu

Coming soon...

Troubleshooting, Further help  and FAQ

Can I use my Python Editor code in MakeCode?

Not at the moment. The MakeCode editor uses its own version of Python. You can read more about this in our article MakeCode Python and MicroPython


Where do I save my projects?

To save your project, simply download the Python Script or .hex file

What’s the difference between download and flash/connect?

The download button will download your program as a .hex or .py file. When you connect your micro:bit to the browser the code is directly 'flashed' to the micro:bit device.


Does this editor work with Mu?

Yes. you can use your MicroPython scripts or .hex files from Mu in the micro:bit Python Editor

Where can I find more information on teaching Python with the micro:bit?
You can find a range of projects and lessons on the microbit.org website


Can I use this editor to teach standard Python concepts?

Yes. We've put a serial console into the editor so you can do more traditional Python coding using your keyboard input and printing to the screen. Your BBC micro:bit becomes a real, tiny physical Python computer you can program and hold in your hand.


You can also use the serial console to read any Python error messages that scroll across the micro:bit's display, making it easier to debug 'runtime' errors.


Does the editor work with micro:bit classroom?

Yes. you can choose to use the beta editor when you set up a classroom session.


Is there a simulator?

Not at the moment. Though it is planned for future development. For now, if you have a micro:bit device and a browser that supports WebUSB (Chrome, Edge) then you can get quick feedback by connecting to the micro:bit via "Connect" and flashing code after each change with "Flash". After the first flash the process is much quicker. If you are interested in this feature, add your support for it on the GitHub issue https://github.com/microbit-foundation/python-editor-next/issues/402


When will the editor be released?

The general release of the editor is planned for the 3rd quarter of 2022.

Where do I report bugs or request features?
You can report bugs to the foundation via creating a ticket here on support.microbit.org or if you are comfortable using Github via https://github.com/microbit-foundation/python-editor-next/issues