Pages

Wednesday, March 15, 2017

Micro:bit introduction


While surfing the net looking at my favorite technology sites I stumbled upon a small microcontroller board called the Micro:bit. I never really dug into that as it was not easily onbtainable in the Netherlands. And then suddenly my favorite (non-china based) reseller Kiwi-Electronics (I am not related to them in any way) was stocking them. So it drew my attention and I decided to buy one of these.

A bit of background.

In England the Micro:Bit was free of charge distributed amongst all 7th graders in schools all over the UK. It was a initiative of the BBC and some large names are involved like Microsoft, The British Council, Lancaster university etc. etc. The purpose is (like many years ago with the legendary BBC computer) to get kids coding.

Because the impact of distributing the Micro:bit for free amongst kids (1.000.000 pieces were given away) is so big there has to be a lot of assistance and there is.

There are several programming languages available amongst whom are Python, Blocks, Java, Microsofts Touch, Fuze Basic and Forth. ARM Mbed even has an on-line IDE for C/C++ development available at http://developer.mbed.org.
You can find many examples, projects and interactive programming on the official website: http://microbit.org

So what's the fuzz all about.




Well first Micro:bit has a great programming environment. At the microbit.org website just choose Let's code and you can choose from several languages which all have a web-ide. This makes programming a piece of cake. Many languages even have an onboard web-simulator so you can test your code before transferring tit (through USB) to the Micro:bit itself.

Next to that you can program it from an Android device by pairing it with it's build in Bluetooth. And naturally you can program it from my second favorite devellopment machine: the Raspberry Pi.

The hardware.

Besides having a great software backup the hardware is impressive.


The Micro:bit can use a USB connection (think powerbank) or batteries as a power source.
There are two buttons available for interaction with programs.
It has an array of 5 x 5 leds on which you can scroll texts or have simple graphics. The individual leds brightness can be controlled.

It's got 3 large I/O connections to be used as a digital input or output but also as an analog input.
And onboard there is a compass, thermometer and an accelerometer.
And last but not least the Micro:bit has build in Bluetooth LE so it can be paired with your smart-phone, tablet, Raspberry Pi or even another Micro:bit.

The first project.

So when I first laid my hands on a Micro:bit I started with scrolling some text on its array of leds. I downloaded a few examples and played a bit with it getting familiar with the programming environment.

Next step was a small project to test the analog input and the capability of controlling a servo. And that is what I am going to demonstrate here.

To test the analog input I used a flex sensor. Flex sensors are resistors who's value alter when you bend them. A variation on this are the pressure sensors who's resistance vary when you put pressure on them. Both kinds are rather expenisive. So you can substitute the flex-sensor by a regular potmeter.

However you can also make your own flex-sensors for next to nothing with some velostat. You can read how to build your own flex-sensors in an upcoming story. So stay tuned.

The hardware setup.



As you can see in the schematic above the setup is simple.
The flex sensor is connected with a pull-up resistor to pin 0 of the Micro:bit and the servo is connected to pin 1
I powered the servo and the Micro:bit seperately as I was afraid that the Micro:bit was not able to deliver sufficient power. In the end I was wrong. The Micro:bit is capable of powering the servo by itself, however that is pushing the limit of its onboard power regulator.



The picture above shows you my real-life setup.
At the bottom on the right side connected with the alligator clips is my home made flex-sensor in strecthed shape.

Reading analog

For programming I chose Microsoft PXT which is a block-based editor (like Scratch or App-Inventor) which translates the blocks into Javascript.


So the blocks shown here read the analog pin, then show the read number on the led matrix and pause 500 miliseconds before taking another reading. The Forever blocks makes thism program run infinit.


And this is the Javascript code it automatically translates into.

Adding the servo

Next step was to translate the reading of the flex sensor into a servo movement. This means that the more you bend the flex-sensor the farther the arm of the servo will turn.


The block code is really simple again.
I read the analog input and limit it on the upperside to 100 and on the lower side to 40.
The difference between the minimum of 40 and maximum of 100 gives me a range of 60 which can easily be translated into servo steps. A servo can move in 180 degrees. So each of my 60 steps represent 3 degrees of the servo.
So the program displays the angle on the led matrix and puts the servo in that position.
Done in essentially 13 lines of code.


And here is the translated Javascript code.

Fun

The Micro:bit is fun to play with. The PXT block editor is easy to use and gives results very fast. And the results can be tested by the build in emulator which makes it even easier to test your projects. I surely can see that this is a great tool to get children interested in programming and electronics. And for adults it is a fast way to learn the basics of Python and get immediate results.

Limitations and expansion


For what it is intended to do the Micro:bit is really great. However when you need to do some real world projects the 3 standard I/O ports are a bit limited and as the Micro:bit has no wifi it is really restircted in its communication.


For the adventurous amongst us there is a break-out board with headers. So attaching the Micro:bit with Dupont wires to a breadboard is possible and you will get a load of I/O ports on the way.


The picture above shows you all the available I/O ports when using the break-out board. You can find a full description of the pins on the Micro:bit website in this link https://www.microbit.co.uk/device/pins

These I/O ports will make the Micro:bit much more usable for projects. However it will then be more competing with the Arduino series of boards as there is still the lack of wifi communication.

The competitions answer.

In the educational world there is a big competitor for the Micro:bit being the Raspberry. Well the Raspberry is much more advanced as it is a complete linux machine with HDMI output to a TV screen or monitor. However the big barrier for the Raspberry for kids is its price-tag. The Raspberry Pi 3 costs about 39 euro which is a lot of money for kids. Do not get me wrong, the Raspberry foundation does a tremendous job in teaching kids programming with the Raspberry but loads of projects made with the Raspberry are real-world projects because it is a full fledged computer and a fast one to !!!



In comes the Raspberry Pi Zero. This will be a game-changer as it is a full Raspberry Pi (be it a slower version, it is a bit faster as the Pi 1) and has the incredible price-tag of 5.50 Euro. That's right a full fledged linux machine with USB and HDMI for less as 6 euro. And just released is the Pi Zero W which has on board Wifi and Blue-Tooth for just 11 Euro. Now that is amazing !!
This is a price-tag which is affordable for kids but also makes it a real competitor for Arduino and ESP projects.


Let's compare the prices of both; Remember that the Micro:bit was free distributed amongst kids in the Uk but if you want to buy one extra for your products it is at the moment that I am writing this about 14 Euro. So the Raspberry Pi Zero is about at one third of that price and even the Pi Zero W with Wifi and Bluetooth is cheaper.

There will be more stories coming up on the Micro:bit and on the amazing Raspberry Pi Zero. So watch this space.

Till then, have fun.

Luc Volders