Free Canadian Shipping on orders over $150 using discount code "FREESHIP" at checkout

micro:bit as a Bluetooth Low Energy gestural controller

January 12, 2018

We're finding more and more to do with the micro:bit. Not merely did Craig upgrade his Christmas Tree decorations to be micro:bit-powered and NeoPixel-driven, but we also discovered how to use a micro:bit as a BLE gestural controller. Best of all, it doesn't need much extra hardware beyond a micro:bit go kit and a BLE-capable computer (like a Raspberry Pi Zero W or Raspberry Pi 3). You can also use the same micro:bit code with Bitty Software's “bitty blue” app for iOS or Android.

The micro:bit has a bunch of sensors built in — accelerometer, compass, temperature, buttons, digital and analogue I/O, plus the 5×5 LED display — and they can be read and set over BLE.

To start, you'll need to download and install the Bitty Blue firmware hex file onto your micro:bit over USB. The download file is here— http://www.bittysoftware.com/downloads.html#bitty_blue — and choose the “no pairing required” version. Once the program is on your micro:bit, it will ask you to draw a circle by tilting the micro:bit to calibrate the magnetometer.

Next, you'll need to associate the micro:bit with your Raspberry Pi. Open a terminal and type bluetoothctl, then enter the following commands. I've added some comments following # signs; you don't have to type those:

scan on  # start looking for new devices
  Discovery started
  [CHG] Controller B8:27:EB:0E:C8:6B Discovering: yes  # ← your BLE adapter address
  [NEW] Device D5:9F:24:AE:0C:EC BBC micro:bit [zozug] # ← your micro:bit BLE address
connect D5:9F:24:AE:0C:EC                              # use your micro:bit BLE address
  Attempting to connect to D5:9F:24:AE:0C:EC
  [CHG] Device D5:9F:24:AE:0C:EC Connected: yes
  Connection successful
disconnect
exit

 

Now install python-bluezero so you can talk to your micro:bit:

sudo pip3 install bluezero

 

Then you can run a little program like this to scroll messages on your micro:bit's LEDs:

#!/usr/bin/env python3
# encoding: utf-8

from bluezero import microbit
# important: change adapter_addr and device_addr to the values you got above
ubit = microbit.Microbit(adapter_addr='B8:27:EB:0E:C8:6B',
                         device_addr='D5:9F:24:AE:0C:EC')
my_text = 'Hello, world'
ubit.connect()

while my_text is not '':
    ubit.text = my_text
    my_text = input('Enter message: ')

ubit.disconnect()

 

(For more examples, please see Barry Byford's RPi <-> micro:bit Workshop, from which this blog post is derived.)

I'm working on getting all the buttons on the SparkFun gamer:bit board to work with bluezero. Then it will be a real game controller!





Also in News

Getting Started with Sid - Theremin Gloves
Getting Started with Sid - Theremin Gloves

July 19, 2021

Continue Reading

Getting Started with Sid - Schematics
Getting Started with Sid - Schematics

June 29, 2021

As we delve into larger projects with more components and potentially less instructions, schematics become more important. If you’re like me, schematics haven’t played a huge role in your life since 9th grade science class.

Continue Reading

Getting Started with Sid - Circuit Playground Express
Getting Started with Sid - Circuit Playground Express

June 23, 2021

Circuit Playground Express really streamlines a lot of the things you can do with boards when learning. By having so many built-in components and so many alligator clip pads there’s not soldering required and it has minimal set up requirements. 

Continue Reading