BBC micro:bit Temperature Measurement with Scilab

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

In my previous tutorial here in this blog,I showed how to read temperature with a purpose written app in App Inventor for Android phone that connects to BBC micro:bit through Bluetooth Low Energy (BLE). With an edge connector more pins can be accessed facilitating connection to other devices. Despite BBC micro:bit having hardware capable of allowing the device to work as a BLE device, it has disadvantage that only has 16k of RAM. The BLE stack alone takes up 12k RAM which means there is little room to run MicroPython and bigger codes.

Scilab is a free and open-source, cross-platform numerical computational package and a high-level, numerically oriented programming language. It can be used for signal processingstatistical analysisimage enhancementfluid dynamics simulations, numerical optimization, and modeling, simulation of explicit and implicit dynamical systems and (if the corresponding toolbox is installed) symbolic manipulations.

Scilab is one of the two major open-source alternatives to MATLAB, the other one being GNU OctaveScilab puts less emphasis on syntactic compatibility with MATLAB than Octave does, but it is similar enough that some authors suggest that it is easy to transfer skills between the two systems.

Objectives

Connect BBC micro:bit to Scilab for reading anf plotting temperature of the processor on micro:bit. Write the codes, using the simplest ways, for the BBC micro:bit and Scilab, and test the setup.

Requirements

  • BBC micro:bit
  • Edge-connector for BBC micro:bit: We used micro:bit IO F5 board  ( 8x OUTPUT, 6x INPUT) – INPUT signal to 5V)  Note that it is not needed in this project, only in next one when we will do control with Scilab.

  • Mini-USB cable connector for programming and serial connection
  • Scilab duly installed in your PC

Our Setup

Connect the small end of the cable to your micro:bit and the other end to your computer’s USB port.

Windows 10 & 8.1: Windows Update will fetch any necessary drivers. For earlier versions of Windows, (Windows 7, or Vista) if you would like to use serial communication (not necessary to program your micro:bit) you will also need the Arm MBED serial port driver.

Mac OS and LInux require no driver installs.

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.

We will use Serial communication with Scilab. Before we can use the micro:bit serial port, we need to install a serial terminal program, and we also need to install the USB serial driver. In this tutorial, we will be using Tera Term. To get the driver, start by following the links below, then follow the installation instructions.

The following image shows the Blocks we are going to chose that is available for USB serial communication found under Advanced blocks;

Now you are ready to write the code. Let’s code! We will write the following code with Blocks:

You can review the code under Javascript tab which will be as follows:

serial.redirect(
    SerialPin.USB_TX,
    SerialPin.USB_RX,
    BaudRate.BaudRate9600
)
basic.forever(function(){
    serial.writeString("\n" + "\r" + input.temperature())
    basic.pause(100)
})

Save the code giving it a name. And download the respective .hex file. I have also provided the hex file you can download from here. At this stage you should connect the BBC micro:bit to your PC (in my case with Windows 7 OS).

You are now ready to install the firmware on 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.

2. Testing the set up

We need to verify that the BBC micro:bit is sending the temperature readings through the USB. Im our case we tested with Tera Term that is free and open source and can be installed in one’s PC with Windows.

Download the Arm Mbed Windows serial port driver and install it.

We need to know the port name that our PC has given to the BBC micro:bit through USB connection.

To check the BBC micro:bit is seeen by PC As a serial device we open Device Manager and look under Ports (COM and LPT):

In our case here it is COM4. So let us view it on Tera Term. We select Serial and chose our Port (in our case COM4).

Clicking on OK immediately we will see on the Terminal opened by Tera Term the temperature readings:

3) Read temperture and plot with Scilab 

The test was carried on Scilab 5.5.1 as besides being stable has many modules. The most recent version of Scilab 6.0.1 presented problems and it is unwise to use it at the moment. We will not explain how to install Scilab 5.5.1.- There are plentiful of tutorialsshowing how to do.

Assuming Scilab is intalled we will ass he Serial communication module by a simple command:

atomsInstall("serial")

You may need to update the database of Scilab, and to install ATOMS library.

To avoid mistakes in script writing to read and plot the temperature, it is availalbe for download.

Once downloaded and opened in Scilab verify the line 62 position 4 and change the name of the port from “= 4” to whatever is port number is BBC micro:bit recognised by your PC:

We are now ready to run the script. Run the script by clicking onto Execute:

The script will open a window as shown with indiaction “Waiting for start”:

Clicking onto “Start measuring…” button Scilab will read the temperature and plot it as shown:

 The plot shows variation of temperature by blowing air with mouth, over the processor. If we click onto “Stop measuring“, Scilab will stop reading the temperature and the plot will stop.

Clicking again on “Start measuring…” button, Scilab will continue reading the temperture and plotting it.

Conclusions

Of course you can do more things with Scilab and BBC micro:bit, as we expect to do in our future post. Scilab is a powerful tool that can be used for signal processingstatistical analysisimage enhancementfluid dynamics simulations, numerical optimization, and modeling, simulation of explicit and implicit dynamical systems and symbolic manipulations.

Acknowledgments

A special thank you to Github for providing their free repository to facilitate sharing. Scilab and  Microbit coding sites also have special right to acknowledgements for their free services. Also a special mention is due to Paraschos Paraschos for inspiring me towards this post.

DISCLAIMER

THE SOFTWARE HERE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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, Information Technolody, Programming 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