Program a Micro:Bit in your Web Browser

Updated 15 September 2023

In this article, we'll program a Micro:bit v2 using a web browser.

We'll connect a Micro:bit to our computer, open python.microbit.org and begin coding our first script.

Contents

What You'll Need

To follow along, you will need:

  • A Micro:bit V2
  • A computer connected to the internet, with Google Chrome installed. Chrome is recommended because the USB drivers work best at the time of writing.

 

Connect your Micro:bit

Use a USB cable to connect your Micro:bit to your computer. If you're using a GO kit, the correct cable is supplied.

If this is your first time powering the Micro:bit, it will say hello with a demonstration of its features.

connect-microbit-to-computer-with-usb-cable

 

Open the Programming Website

In Chrome, navigate to python.microbit.org - you will be greeted by a programming screen with a short example script:

default-script

Let's give it a try! In the top menu bar, click Connect and select your Micro:bit from the list, then click the blue Connect.

connect-to-microbit

connected-status The Connect button has changed to a smiling Micro:bit to show that we are now connected.

 

Click the Flash button to upload the default script. Watch how a message scrolls across your Micro:bit's display, then it shows a heart.

You can change the text by modifying the contents of display.scroll()

 

Code Remix

Copy the following code and paste it into your editor, replacing all the default code.

 

# Print the thirteen-times table
from microbit import *

multiple = 1

while True:
    result = multiple * 13
    print(str(multiple) + " times 13 is " + str(result))
    multiple = multiple + 1
    sleep(1000)

Flash the code, then click Open Serial. Now the Micro:bit is calculating the thirteen-times tables.

thirteen-times-table

This serial console is a great tool for debugging, and seeing what goes on inside the Micro:bit.

 

Saving and Loading a Project

We can save this new script to our computer by opening the Load/Save menu. Click "Download Python Script" to download the current contents of the web-editor if you would like to keep a copy on your computer.

Aside: If your project is made up of multiple files, you download the whole project as one file by selecting Download Project Hex. This will capture a more complex project, but the .hex file will not be human-readable. You have to re-upload it to the web-editor to make any changes.

load-save-menu

Now we'll load another script - right-click the following link (microbit-button-demo.py) and select "save link as..." to download it to your computer.

Now in the Load/Save menu, upload the same file to your web-editor by either dragging the file into the menu, or click the Browse for a file option.

Once the file is loaded, click flash to see what it does! With some experimenting you should find that pressing the A-button on the Micro:bit will print the next multiple of thirteen in the console; and pressing the B-button causes the microbit to make a happy sound, and show a smile on its display.

 

Projects with Multiple Files

Some more advanced MicroPython projects may need multiple files, you can always add multiple files using the Add file button under Project Files. If you don't see this option, you may have to click Show Files, which is in the Project Files section.

Once you've added the files, you will need to click the Flash button again to actually copy them onto the Micro:bit.

upload-multiple-files

 

Conclusion

We've written our first MicroPython script for Micro:bit and flashed it using the web-editor python.microbit.org. We were able to print information to the console and save/load files to/from our computer.

If you have any questions, start the conversation below! We're full time makers and happy to help.

Happy coding!

Attachment - microbit-button-demo.zip

 

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.