The BBC micro:bit (or Micro Bit) is an ARM-based embedded system designed by the BBC for use in computer education in the UK. It will be given to every 11 year old student in UK. The device is based on ARM Cortex-M0 processor, and has an accelerometer and magnetometer sensors. In this article, you’ll learn how to get started with programming using a Micro Bit with Fedora.
Getting Mu on your Micro Bit
From Fedora 24 (and also on Fedora 23), you can install the official Python IDE, Mu. With Mu, you can learn Python and programming in general using a Micro Bit. Install it like any other official package in Fedora:
$ sudo dnf install -y mu
After installing the package, add your user account to the dialout group:
$ sudo usermod -a -G dialout username
Log out and log back in again for the change to take effect. Then you can start the IDE as a normal application.
Writing your first program in Mu
To write your first program, you need to provide input to the Micro Bit. One way to do this is with the Read Eval Print Loop, or Repl. To access the Repl on the device, click the Repl button. You can now start writing standard Python 3 code into the Repl.
Running the program on the Micro Bit
Now you can use the editor to write a full Python program, and save it on the local computer. When it’s ready, you can upload it to the device by clicking the Flush button. The yellow LED on the Micro Bit blinks while the code is flushed into the device.
The full source for the example in this article can be found below. It is written by Nicholas H.Tollervey, who also oversaw the effort of running MicroPython on the BBC Micro Bit. He is also the upstream author of Mu.
# Make the display sparkle. Click button A to show an image for # a moment before the sparkles start again. Click button B to # scroll a friendly message before the sparkles return. # By Nicholas H.Tollervey and released to the Public Domain. # How would you improve this code? from microbit import * import random # A full list of images can be found here: http://bit.ly/1WY221q images = [Image.HAPPY, Image.SAD, Image.GHOST, Image.SKULL, Image.DUCK, Image.UMBRELLA, Image.GIRAFFE, Image.RABBIT, Image.HEART, Image.ANGRY, Image.STICKFIGURE] while True: sleep(20) x = random.randint(0, 4) y = random.randint(0, 4) brightness = random.randint(0, 9) display.set_pixel(x, y, brightness) if button_a.was_pressed(): display.show(random.choice(images)) sleep(500) if button_b.was_pressed(): display.scroll("Hello, World!", delay=100)