The BBC micro:bit is a pocket-sized computer that lets you get creative with digital technology. Each order contains just the micro:bit board. You can code, customize and control your micro:bit from anywhere! You can use your micro:bit for all sorts of unique creations, from robots to musical instruments and more. At half the size of a credit card, you will be surprised at the amount of hardware each board is equipped with, including 25 red LED lights that can flash messages. There are two programmable buttons that can be used to control games or pause and skip songs on a playlist. The micro:bit can even detect motion and tell you which direction you’re heading. It can also use Bluetooth Low Energy (BLE) to interact with other devices and the Internet.
Taking a closer look at the front of the board, we can see the 5×5 LED array that you can use as a light sensor, a tiny screen to draw on, display words, numbers and other information, and the two programmable buttons! On the back of the board you will find the brains of the micro:bit, a 16MHz, 32-bit ARM Cortex-M0 microcontroller with 256KB Flash, 16KB RAM and a built-in temperature sensor. Additionally, the back of the micro:bit is populated by an accelerometer, compass and Bluetooth Smart antenna, as well as a microUSB and two-pin JST connector for different power options. Finally, at the bottom of the board you will find 20 gold-tabbed edge pins and five ring connectors (three for digital/analog I/O, two for power and ground) for hooking up external components. The tabs with larger holes can be easily used with alligator clips to prototype added components quickly.
Micro:bit has even supplied an intuitive mobile app that lets you send your code to your micro:bit over Bluetooth (without using a USB cable) and more. With this app you will be able to interact with your micro:bit on a higher level of accessibility.
- 32-bit ARM Cortex-M0 CPU
- 256KB Flash
- 16KB RAM
- 5×5 Red LED Array
- Two Programmable Buttons
- Onboard Light, Compass, Accelerometer and Temp Sensors
- BLE Smart Antenna
- Three Digital/Analog Input/Output Rings
- Two Power Rings — 3V and GND
- 20-pin Edge Connector
- MicroUSB Connector
- JST-PH Battery Connector (Not JST-XH)
- Reset Button with Status LED
Read temperature remotely on an Android phone with BBC micro:bit and Bluetooth Low Energy BLE. Write the codes, using the simplest ways, for the BBC micro:bit and Android smartphone, and test the setup.
Duly connected BBC micro:bit through USB connector to PC and use an Android smartphone compatible with Bluetooth Low Energy BLE.
1. Coding the BBC micro:bit
To use Bluetooth in your micro:bit application you first need to add the Bluetooth package to your project using the menu More/Add Package.
Once this is done (you may receive a warning of some incompatibilities, but do accept them) , you will have a complete collection of Bluetooth related Blocks with which can build the Bluetooth capabilities of your application. Many are very simple and merely result in a given Bluetooth service being available at run-time. But there are also blocks which provide access to Bluetooth connect and disconnect events and the Bluetooth UART service can be used to transmit arbitrary data to a connected peer or to receive data from a peer service.
The following image shows all the the blocks that will become available
Now you are ready to write the code. Let’s code! Drag and drop the blocks to get the following result:
Save the code giving it a name. And download the respective .hex file. At this stage you should connect the BBC micro:bit to your PC (in my case with Windows 7 OS).
Yo are now ready to install the firmware in BBC micro:bit which behaves like a drive in your PC and will be visible. You will need to copy, or drag and drop, the hex file into BBC micro:bit:
The hex file once dropped or pasted (“Colar” in above image means “Paste”) will install itself in BBC micro:bit, and run.
2. Writing an App for Android
To stay in visual programming we will write now an App for Android smartphones. MIT has MIT App Inventor (now version 2) that we will use to write the App.
It allows newcomers to computer programming to create software applications for the Android operating system (OS). It uses a graphical interface, very similar to Scratch and the StarLogo TNG user interface, which allows users to drag-and-drop visual objects to create an application that can run on Android devices. In creating App Inventor, Google drew upon significant prior research in educational computing, as well as work done within Google on online development environments.
MIT App Inventor and the projects on which it is based are informed by constructionist learning theories, which emphasizes that programming can be a vehicle for engaging powerful ideas through active learning. As such, it is part of an ongoing movement in computers and education that began with the work of Seymour Papert and the MIT Logo Group in the 1960s and has also manifested itself with Mitchel Resnick‘s work on Lego Mindstorms and StarLogo.
MIT App Inventor is also supported with the Firebase Database extension. This allows people to store data on Google’s firebase.
a) Register yourself at http://ai2.appinventor.mit.edu/ using a Google or other accepted email account. We will first add Bluetooth Lowe Energy blocks to MIT App Inventor-
b) First and foremost we need now to add the necessary extension. In the Palette windows click on Atension at the bootm and then on “Import extesnion” and click on “URL”. Paste the URL:
c) We will not show all the steps you need to undertake nor of how to build the blocks blocks. I suggest you follow the tutorial by downloading and reading and following the tutorial at: http://iot.appinventor.mit.edu/assets/howtos/MIT_App_Inventor_Microbit_Temperature.pdf
If you are too lazy to write the App cyou can download the code here. The file named BLE_Temp_Mon.aia is made available at github.com repository that you can import into your MIT App Inventor account. You will, once imported, have to compile and export the application with .apk extension into your Android phone and isntall. You will find plenty of information in Internet on how to do it.
If you have difficulties for any parts of this tutorial do not hesitate to contact me.
3) Pairing Android phone with BBC micro:bit
Making your BBC micro:bit pair requires you to follow some simple steps which will be described shortly. What you do with the device you’re pairing it to will vary slightly depending on what that device is. We’ll look at how it’s done with common smartphones and tablets here too.
To get your micro:bit ready for pairing do the following:
- Hold down buttons A and B on the front of your micro:bit together. The front is the side with two buttons and the LED display. Keep the two buttons held down. Don’t let go of them yet!
- While still holding down buttons A and B, press and then release the reset button on the back of the micro:bit. Keep holding down buttons A and B.
- You should see “PAIRING MODE!” start to scroll across the micro:bit display. When you see this message start to appear you can release buttons A and B.
- Eventually you’ll see a strange pattern on your micro:bit display. This is like your micro:bit’s signature. Other people’s micro:bits will probably display a different pattern.
Your micro:bit is now ready to be paired with the other device.
4) Testing the App on Android phone
If you have installed the apk compiled from the .aia file that I have provided you will see the following icon in your Android phone:
Click on icon to start the App. Click on Scan button:
You will see the paired BLE device that is BBC micro:bit. Click on black labelled button containing data on the device that is paired and next click on Connect button:
If all is well you will see the Status as Connected and read the temperature in ºC:
You will see the right sign on the BBC micro::bit:
If Bluetooth is disconnected by pressing Disconnect button or for any other reason, the display will show X which means disconnected!
Of course you can do more thinks like hearing the temperature om the Android phone writing a modification to App, and other things. Also, instead of using the ready made temperature block you can write your own one for the BBC micro:bit. If you do use any parts of my tutorial please acknowledge as I do here.
A special thank you to y Martin Woolley for inspiring articles and videos on BBC micro:bit, and one of his tutorial already acknowledged above. Also a special thanks to Github for providing their free repository to facilitate sharing. MIT App Inventor and Microbit coding sites also have special right to acknowledgements for their free services.