Remote Reading of Temperature with BBC micro:bit and Bluetooth Low Energy BLE

Introduction

The Micro Bit also referred to as BBC Micro Bit, stylised as micro:bit is an ARM-based embedded system designed by the BBC for use in computer education.

microbit

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.

Important: The micro:bit does not include any cables or power sources. This is just the board. We recommend picking up a micro:bit AA battery holder or a micro USB cable as well to power your board.

Features:

  • 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

Objectives

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.

Setup

Duly connected BBC micro:bit  through USB connector to PC and use an Android smartphone compatible with Bluetooth Low Energy BLE.

microbit3

1. Coding the BBC micro:bit

Coding can be of several type offered for BBC micro:bit. You can code your BBC micro:bit using Blocks, JavaScript, Python, and mbed platform. We will use Blocks offered at http://microbit.org/code/ to install the firmware in simplest way. Blocks provide a visual programming, drag-and-drop tool involving building application logic by arranging graphical programming blocks representing predefined, parameterised functions. And it’s very easy to use.

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.

codethemicrobit

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

codethemicrobit2

Now you are ready to write the code. Let’s code! Drag and drop the blocks to get the following result:

microbit4

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

microbit5

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:

microbit6

The hex file once dropped or pasted (“Colar” in above image means “Paste”) will install itself in BBC micro:bit, and run.

microbit7

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.

MIT App Inventor is an open-source web application originally provided by Google, and now maintained by the Massachusetts Institute of Technology (MIT).

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:

http://iot.appinventor.mit.edu/assets/com.bbc.microbit.profile.aix

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:

  1. 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!
  2. 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.
  3. 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.
  4. 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:

Screenshot_20180307-143806

Click on icon to start the App. Click on Scan button:

Screenshot_20180307-143815

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:

Screenshot_20180307-143822

If all is well you will see the Status as Connected and read the temperature in ºC:

Screenshot_20180307-144046

You will see the right sign on the BBC micro::bit:

microbit8

If Bluetooth is disconnected by pressing Disconnect button or for any other reason, the display will show X which means disconnected!

PSX_20180307_172216

Conclusions

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.

Acknowledgmenets

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.

Advertisements

About Tayeb

Electronics engineer, part-time webmaster and owner of "Aliatron", a tech-oriented company registered in Portugal and Mozambique. Owner of "EU Halal", a trading and consulting company in Halal & Tayyib, 100% stun-free compliant.
This entry was posted in Electronic Projects, Internet of Things, Mobile Apps, Programming, Uncategorized and tagged , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s