Add modules to your micro:bit

In the Python language, you can use specialized instructions just for the micro:bit that are grouped into modules.  The cyberbot library archive includes several modules that will let you write micro:bit programs for your cyber:bot robot. You can read about them in the cyber:bot library reference here.

 

Quick Start for cyber:bots

Here is a shortcut if you are using a python.microbit.org editor and just need to get started with the cyber:bot robot quickly. Simply download the template below, open it with the Python online editor, and start coding. It already has the cyberbot module added to its project settings.

  • Right-click the hex link below, choose Save link as..., and then save the file to your computer.

Cyberbot-template-with-blink.hex

To run scripts that use from cyberbot import * you must first:

  • Connect the micro:bit to the cyber:bot board. 
  • Connect the 5AA battery pack to the cyber:bot board.
  • Put the cyber:bot board PWR switch to 2 to power all features, or to 1 to power everything but the servo ports (this keeps the robot from running away while downloading code). The script won't run if PWR is set to 0.

 

Example: Add cyberbot Module to micro:bit Filesystem

To run the cyber:bot, the cyberbot library module file (cyberbot.py) must be stored in a special area on your micro:bit module, called the file system. Any other library modules your project might need must also be stored there.

  • Download the cyberbot library archive file from this page:

cyberbot library archive

  • Extract the contents of the archive to a folder of your choice—you will access them from the code editor soon.

If you need instructions on how to extract files from an archive, use a search term like this in Google: How to extract an archive with Windows.  Make sure to replace Windows with Mac or Chrome if that's your computer's operating system.

Install the modules

The process is slighty different depending on which software you are using.

Using online Python editor?

  • Click the Load/Save button, and a file management dialog will appear.
  • Click the Show Files dropdown; it’s below the Project Files heading.
  • Browse into cyberbot-micropython folder you unzipped.  Select cyberbot.py and click Open.
  • Verify that cyberbot.py (and any others you choose) now appear in the file list below the microbit program (main.py).  
  • Click the file management dialog’s × shaped close button.
  • Add from cyberbot import * near the top of your code in the editor area before you download or flash your project.


Now, cyberbot.py and any other added modules will be delivered to your micro:bit along with your code.

 

Using Mu editor?

  • From the folder where you extracted the cyberbot library contents, copy the contents into your computer's mu_code folder.
    • On Windows, the path is: C:\Users\<username>\mu_code
    • On Macintosh, the path is: Macintosh HD>Users>username>mu_code

  • Connect your micro:bit to your computer via USB cable.
  • Click on the Files button- a file management pane will appear at the bottom of the editor.

  • Drag and drop the cyberbot.py file (and others, if desired) from the right pane to the left pane.

Mu will transmit the file to your micro:bit.

  • Click on the Files button again to close the file management pane.
  • Add from cyberbot import * near the top of your code in the editor area before you download or flash your project.

If you see a "no module named 'cyberbot'," error when flashing projects in the future, just follow these steps again the restore the micro:bit's cyberbot.py module.