# Using micro:bit and CRICKIT with MicroPython

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/075/569/medium800/micropython_picture2.png?1557524489)

![](https://cdn-learn.adafruit.com/assets/assets/000/075/701/medium800thumb/micropython_ezgif-5-8a39b83eb1eb.jpg?1557936767)

The Adafruit CRICKIT for micro:bit is a very nifty add-on. With it, you can extend the capabilities of the micro:bit to include additional inputs/outputs, capacitive touch input, servo control and DC motor control.

These functions can be accessed via the Arduino IDE with the following tutorials:

- [Micro:bit with Arduino](https://learn.adafruit.com/use-micro-bit-with-arduino/overview)
- [Introducing Adafruit Crickit](https://learn.adafruit.com/adafruit-crickit-creative-robotic-interactive-construction-kit/arduino-code)

This guide presents **using CRICKIT functions via MicroPython**. MicroPython was started by author Damien George to allow Python programming on microcontrollers like the micro:bit. CircuitPython is a fork of MicroPython that Adafruit started to make Python on microcontrollers easier for beginners. Unfortunately, CircuitPython will not fit onto the limited memory of the micro:bit.&nbsp;

There are significant differences between MicroPython and CircuitPython. This tutorial focuses on using MicroPython on micro:bit with an Adafruit CRICKIT robotics controller attached.

## Parts
### Adafruit CRICKIT for micro:bit

[Adafruit CRICKIT for micro:bit](https://www.adafruit.com/product/3928)
Sometimes we wonder if robotics engineers ever watch movies. If they did, they'd know that making robots into servants always ends up in a robot rebellion. Why even go down that path? Here at Adafruit, we believe in making robots our&nbsp; **friends!**

So if you find...

In Stock
[Buy Now](https://www.adafruit.com/product/3928)
[Related Guides to the Product](https://learn.adafruit.com/products/3928/guides)
![Angled shot of a Adafruit CRICKIT for micro:bit connected to a black squared board.](https://cdn-shop.adafruit.com/640x480/3928-01.jpg)

### USB A/Micro Cable - 2m

[USB A/Micro Cable - 2m](https://www.adafruit.com/product/2185)
This is your standard USB A-Plug&nbsp;to Micro-USB cable. It's 2 meters long so you'll have plenty of cord to work with for those longer extensions.

In Stock
[Buy Now](https://www.adafruit.com/product/2185)
[Related Guides to the Product](https://learn.adafruit.com/products/2185/guides)
![USB Cable with Type A and Micro B ends](https://cdn-shop.adafruit.com/640x480/2185-00.jpg)

### 5V 2A (2000mA) switching power supply - UL Listed

[5V 2A (2000mA) switching power supply - UL Listed](https://www.adafruit.com/product/276)
This is an FCC/CE certified and UL listed power supply. Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to 2000mA. 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one...

In Stock
[Buy Now](https://www.adafruit.com/product/276)
[Related Guides to the Product](https://learn.adafruit.com/products/276/guides)
![Angled shot of power supply.](https://cdn-shop.adafruit.com/640x480/276-06.jpg)

A breadboard and some parts are used to demonstrate certain functions - feel free to only get the parts you may want to use for your project.

### Part: Half Breadboard
quantity: 1
Half-size breadboard
[Half Breadboard](https://www.adafruit.com/product/64)

### Part: Micro Servo
quantity: 1
Tiny little servo can rotate approximately 180 degrees
[Micro Servo](https://www.adafruit.com/product/169)

### Part: DC Motor
quantity: 1
Toy / Hobby Motor - 130 Size
[DC Motor](https://www.adafruit.com/product/711)

### Part: 10K potentiometer
quantity: 1
Breadboard size trim pot
[10K potentiometer](https://www.adafruit.com/product/356)

### Part: LEDs
quantity: 1
Diffused 5mm LED Pack - 5 LEDs each in 5 Colors - 25 Pack
[LEDs](https://www.adafruit.com/product/4203)

### Part: Breadboard Buttons
quantity: 1
Tactile Button switch (6mm) x 20 pack
[Breadboard Buttons](https://www.adafruit.com/product/367)

# Using micro:bit and CRICKIT with MicroPython

## Installing MicroPython on the micro:bit

We highly recommend you install the Mu Python editor. Mu has versions for PC, mac, and Linux, it is open source / free, and it is tailored to learning and microcontrollers such as the micro:bit and others.

## Download Mu

Download Mu from&nbsp;[https://codewith.mu](https://codewith.mu/). Click the&nbsp; **Download** &nbsp;or&nbsp; **Start Here** &nbsp;links there for downloads and installation instructions. The website has a wealth of other information, including extensive tutorials and and how-to's.

## Starting up Mu
It would be best to plug your micro:bit into your computer before starting Mu, as the Mu menu changes depending on which board it detects on startup.

For Mu starting up in micro:bit mode, you should get a display like this.

The menu bar looks like the one below:

![micropython_Capture.jpg](https://cdn-learn.adafruit.com/assets/assets/000/075/672/medium640/micropython_Capture.jpg?1557862911)

![](https://cdn-learn.adafruit.com/assets/assets/000/075/673/medium800/micropython_Capture.jpg?1557862911)

If you are familiar with Mu with CircuitPython, you are not seeing strange things. There are buttons on the menu that are different than when Mu is in CircuitPython (Adafruit) mode.

The first time you start Mu, you will be prompted to select your 'mode' - you can always change your mind later. For now please select&nbsp; **BBC Microbit**!

The current mode is displayed in the lower right corner of the window, next to the "gear" icon. If the mode says **Adafruit** or something else, click on that (or the leftmost menu icon **Mode** and then choose **BBC Microbit** in the dialog box that appears.

![micropython_Untitled.png](https://cdn-learn.adafruit.com/assets/assets/000/075/674/medium640/micropython_Untitled.png?1557863053)

## Installing MicroPython

Mu will install MicroPython for you. It is _not_ intuitive that it does so, but **it does work**.

Create a new blank file/program. Ensure your micro:bit is plugged in to your computer's USB port and recognized with Mu being in Microbit mode.

Click the Flash icon shown at left.&nbsp;

The text in the lower left will say "Flashing MicroPython (or untitled") to the micro:bit. The micro:bit yellow LED should be flashing during this process.

Then Mu will say "Finished Flashing" in the lower left corner of its window.

MicroPython is now on your micro:bit.

The flash drive that shows up on plugging your micro:bit into the computer will NOT change at all, re. you cannot tell if MicroPython is installed on your board by looking at the flash drive representing the micro:bit (unlike CircuitPython which changes the drive name to **CIRCUITPY** , this does NOT happen with MicroPython).

&nbsp;

## Loading Programs

Loading MicroPython programs onto the micro:bit is different than with CircuitPython also. this will be explained next when we create a MicroPython program for Crickit.

![micropython_Untitled.png](https://cdn-learn.adafruit.com/assets/assets/000/075/675/medium640/micropython_Untitled.png?1557863395)

![micropython_Capture.jpg](https://cdn-learn.adafruit.com/assets/assets/000/075/676/medium640/micropython_Capture.jpg?1557863739)

![micropython_Capture2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/075/678/medium640/micropython_Capture2.jpg?1557863793)

# Using micro:bit and CRICKIT with MicroPython

## The Seesaw Driver

To use the CRICKIT with MicroPython, you will need the Adafruit **seesaw.py** driver code loaded onto the board in addition to your user program named **main.py**.

The seesaw driver code is below. You can use the Download function to put it on your computer. The best location to download **seesaw.py** depends on your operating system.&nbsp;

Place the file **seesaw.py** into your `mu_code` folder, which might be in:

- C:\Users\YourUserName\mu\_code on Windows
- /Users/YourUserName/mu\_code on macOS

Putting it in the **mu\_code** folder makes it much easier to copy the files onto the micro:bit on the next page.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Crickits/Crickit_microbit_MicroPython/seesaw.py

# Using micro:bit and CRICKIT with MicroPython

## Testing CRICKIT's Features

## Connections

We can test connections using the parts in the diagram below. Feel free to omit anything you do not wish to control, this example shows testing a number of things to give you an idea what can be done.

![](https://cdn-learn.adafruit.com/assets/assets/000/075/685/medium800/micropython_microbit_crickit_test_bb.png?1557930579)

### Signals

Signal **2** to LED (long lead +), LED (short lead -) to **GND** (breadboard common ground)

Signal **7** to leg of switch, opposite diagonal switch leg to **ground**

Signal **8** to Potentiometer middle pin. Ground to one outer pin, **3.3V** to the other outer pin.

### Servo

Servo connected to Servo block port 1, darkest wires facing towards micro:bit slot

### Motor

Motor connected to Motor port 1 (color connections do not matter)

## Plug in the micro:bit and Power

The micro:bit unfortunately fits into Crickit in either orientation but only one is correct. See the board markings which says "Micro:bit LED grid facing this way" - ensure the micro:bit LEDs face the direction shown.

Use a 5 volt 2A power supply plugged into the barrel jack of the Crickit. Ensure the tiny switch next to the barrel jack is in the **On** position. The green LED on CRICKIT with the smiley face (shown below) shows that CRICKIT is happy with its power supply.

![](https://cdn-learn.adafruit.com/assets/assets/000/075/686/medium800/micropython_Power_Picture.jpg?1557930630)

Warning: 

Warning: 

## An Example: the Test Program
The following MicroPython program tests the CRICKIT and micro:bit:

- The Motor drive
- The Digital In on the Signals block
- The Digital Out on the Signals block
- The Analog In on the Signals block
- Servo drive on the Servo block

The code also has a demonstration of the Drive block setting various levels not used here.

The following capabilities are currently not written into the seesaw.py driver:

- Sound (this does not need a driver, use the standard micro:bit sound pin 0 to output sound to the CRICKIT amplifier).
- NeoPixel control via micro:bit pin 16 (use the default micropython NeoPixel driver and use pin #16!)
- Stepper motor control on either the Motor or Drive blocks. (We wanted to keep things simple)

## Code

Click download to get the **main.py** file below via the [tutorial GitHub repo](https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/master/Crickit_microbit_MicroPython). Save the file as **main.py** in your `mu_code` folder mentioned on the previous page.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Crickits/Crickit_microbit_MicroPython/main.py

![](https://cdn-learn.adafruit.com/assets/assets/000/075/704/medium800/micropython_File_Transfer.jpg?1557953666)

## Moving the Code to the micro:bit

Click the Mu Files icon. Your files that are in your `mu_code` folder will show up to the right. Using your cursor, drag **seesaw.py** to the left pane. Then do the same for **main.py**. This will copy the files onto the micro:bit.&nbsp;

The code should run. It might take a reset of the micro:bit and/or CRICKIT (both have reset buttons on them) to work.&nbsp;

To use the REPL to see the output of the code, click the **Files** icon once more to close that window, then click the **REPL** button. The program output can now be viewed. If the code isn't running and you've reset the boards, press on the keyboard to do a soft reboot.

Warning: 

## Use

The program will continually be testing various functions as a demonstration. The LED will blink, the servo will turn, and the motor will turn on and off.

Values for the capacitive touch pads, the potentiometer, and the status of the switch will be printed out in the REPL window.

![](https://cdn-learn.adafruit.com/assets/assets/000/075/689/medium800thumb/micropython_ezgif-5-8a39b83eb1eb.jpg?1557932172)


## Featured Products

### BBC micro:bit

[BBC micro:bit](https://www.adafruit.com/product/3530)
The British Invasion is here! No, not music...microcontrollers! New to the USA is the newest and _easiest_ way to learn programming and electronics - the **BBC micro:bit**.

Designed specifically for kids and beginners, the&nbsp; **micro:bit** &nbsp;is a...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3530)
[Related Guides to the Product](https://learn.adafruit.com/products/3530/guides)
### Adafruit CRICKIT for micro:bit

[Adafruit CRICKIT for micro:bit](https://www.adafruit.com/product/3928)
Sometimes we wonder if robotics engineers ever watch movies. If they did, they'd know that making robots into servants always ends up in a robot rebellion. Why even go down that path? Here at Adafruit, we believe in making robots our&nbsp; **friends!**

So if you find...

In Stock
[Buy Now](https://www.adafruit.com/product/3928)
[Related Guides to the Product](https://learn.adafruit.com/products/3928/guides)
### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

In Stock
[Buy Now](https://www.adafruit.com/product/592)
[Related Guides to the Product](https://learn.adafruit.com/products/592/guides)
### 5V 2A (2000mA) switching power supply - UL Listed

[5V 2A (2000mA) switching power supply - UL Listed](https://www.adafruit.com/product/276)
This is an FCC/CE certified and UL listed power supply. Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to 2000mA. 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one...

In Stock
[Buy Now](https://www.adafruit.com/product/276)
[Related Guides to the Product](https://learn.adafruit.com/products/276/guides)
### Micro servo

[Micro servo](https://www.adafruit.com/product/169)
Tiny little servo can rotate approximately 180 degrees (90 in each direction) and works just like the standard kinds you're used to but _smaller_. You can use any servo code, hardware, or library to control these servos. Good for beginners who want to make stuff move without...

Out of Stock
[Buy Now](https://www.adafruit.com/product/169)
[Related Guides to the Product](https://learn.adafruit.com/products/169/guides)
### DC Toy / Hobby Motor - 130 Size

[DC Toy / Hobby Motor - 130 Size](https://www.adafruit.com/product/711)
These are standard '130 size' DC hobby motors. They come with a wider operating range than most toy motors: from 4.5 to 9VDC instead of 1.5-4.5V. This range makes them perfect for controlling with an Adafruit Motor Shield, or with an Arduino where you are more likely to have 5 or 9V...

In Stock
[Buy Now](https://www.adafruit.com/product/711)
[Related Guides to the Product](https://learn.adafruit.com/products/711/guides)
### Breadboard trim potentiometer

[Breadboard trim potentiometer](https://www.adafruit.com/product/356)
These are our favorite trim pots, perfect for breadboarding and prototyping. They have a long grippy adjustment knob and with 0.1" spacing, they plug into breadboards or perfboards with ease.

This is the same pot that comes with our character LCDs and tutorial...

In Stock
[Buy Now](https://www.adafruit.com/product/356)
[Related Guides to the Product](https://learn.adafruit.com/products/356/guides)
### Diffused 5mm LED Pack - 5 LEDs each in 5 Colors - 25 Pack

[Diffused 5mm LED Pack - 5 LEDs each in 5 Colors - 25 Pack](https://www.adafruit.com/product/4203)
Need some indicators? We are big fans of these diffused LEDs. They are fairly bright, so they can be seen in daytime, and from any angle. They go easily into a breadboard and will add that extra zing to your project.

Now you can get a pack of 25 with 5 different colors

- Pack of...

In Stock
[Buy Now](https://www.adafruit.com/product/4203)
[Related Guides to the Product](https://learn.adafruit.com/products/4203/guides)

## Related Guides

- [CRICKIT WobblyBot](https://learn.adafruit.com/crickit-wobblybot.md)
- [Micro:bit Radio Control of Crickit Robotics](https://learn.adafruit.com/micro-bit-radio-control-of-crickit-robotics.md)
- [Make it Move with Crickit](https://learn.adafruit.com/make-it-move-with-crickit.md)
- [micro:bit Crickit Robot](https://learn.adafruit.com/microbit-crickit-robot.md)
- [Trellis M4 Beat Sequencers](https://learn.adafruit.com/trellis-m4-beat-sequencer.md)
- [Simple Vertical Wordclock](https://learn.adafruit.com/vertical-wordclock.md)
- [CRICKIT Snake Bot](https://learn.adafruit.com/crickit-snake-bot.md)
- [Using the Android CircuitPython Editor](https://learn.adafruit.com/using-the-android-circuitpython-editor.md)
- [PyPortal Astronauts in Space](https://learn.adafruit.com/pyportal-astronauts-in-space.md)
- [Motion Gift Box](https://learn.adafruit.com/motion-gift-box.md)
- [Shadow Box Internet Clock with NeoPixel Visualization](https://learn.adafruit.com/shadow-box-internet-clock-with-neopixel-visualization.md)
- [PlayStation Spinner Controller](https://learn.adafruit.com/playstation-spinner-controller.md)
- [Light Up your Costume with Noods](https://learn.adafruit.com/light-up-your-costume-with-noods.md)
- [NeoPIO: Drive lots of LEDs with Raspberry Pi Pico](https://learn.adafruit.com/neopio-drive-lots-of-leds-with-raspberry-pi-pico.md)
- [CircuitPython Display_Text Library](https://learn.adafruit.com/circuitpython-display-text-library.md)
