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.  A module must be stored in a special area on your micro:bit, called the file system, before its instructions can be used in a script.  For example, the cyberbot library archive includes several modules that will let you write micro:bit scripts for your cyber:bot robot. You can read about them in the cyber:bot library reference here.

You have two options: use a .hex file template that already has the module included, or add the module to your micro:bit file system manually.

Quick Start Template for cyber:bot Robots using online Python editor

Here is a template shortcut if you are using the online 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, so you can use its instructions in your scripts right away.

  • 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.

 

Adding a Module to micro:bit Filesystem

Follow these instructions for adding a module to your micro:bit. The cyberbot.py module is used as an example. The step-by-step video and checklist instructions will guide you through creating and saving a project file that has the cyberbot module.  When you start writing scripts that make the cyber:bot robot move, yoy will be able to open the file you saved, and it will have the cyberbot module ready to use.

  • Follow along with your own computer and micro:bit module.

  • Go to www.parallax.com/package/cyberbot-library-python/.
  • Click the Download button.  
  • Use a file browser (Windows Files Explorer, Mac Finder, or Chromebook Files app) to look in the Downloads folder and find the cyberbot-micropython-v0-9-2.zip archive.  

 

  • Unzip/extract the archive:
    • Windows File Explorer:  Right-click cyberbot-micropython-v0-9-2.zip, select Extract all, and then follow the prompts
    • Mac Finder:  If double-clicking it doesn’t automatically extract the files to a folder, then Right-click (or two finger tap or CTRL + Click) cyberbot-micropython-v0-9-2.zip, point at Open With, and select Archive Utility.
    • Chromebook:  Right-click cyberbot-micropython-v0-9-2.zip, select Extract all.  
  • Verify that you can now see a cyberbot-micropython-v0-9-2 folder (in addition to the .zip file with the same name) in your Downloads folder.  

 

 

  • Back in the micro:bit Python Editor, click the Project tab.  It’s along the left side panel near the bottom.  
  • Click the Open… button near the bottom of the left side panel (not the one in the bottom-right).  
  • In the Open dialog, browse into the downloads / cyberbot-micropython-v0-9-2 folder. Make sure you are browsing into the folder and not into the .zip file archive.  
  • Find and select cyberbot.py and click the Open button.

 

  • In the Change files? popup, make sure it says Add module cyberbot.py, and then click the Confirm button.

 

  • Check to make sure that both main.py and cyberbot.py are listed in the left side panel’s Project tab.


Note: You will learn how to use this module later.  For now, just note that you can also find cyberbot module documentation at:  learn.parallax.com/support/reference/cyberbot-library-reference.    

  • Click main.py and replace whatever’s in the editor pane with this:
# Template for cyber:bot Robot
from cyberbot import *
  • Rename the project to cyberbot template.  For a refresher on how to rename a project, see the Save & Edit Scripts with micro:bit Python Editor V3 section.  
  • Click the Save button to download a copy of cyberbot template.hex to your Downloads folder.


IMPORTANT: The script in these steps will only work when the micro:bit is connected to a cyber:bot board that has battery power and its power switch set to 1 or 2.  So, for micro:bit-only projects, it’s best to go back to a project that does not contain the cyberbot.py module

  • Close the micro:bit Python Editor tab in Chrome.  Then, open a new tab and go back to https://python.microbit.org/v/3 again.  
  • Click the left side panel’s Project tab again, and verify that there is no cyberbot.py module listed.  Now, you are ready to write more micro:bit-only scripts.