Getting Started With BBC Micro:Bit

What is BBC micro:bit?

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

The board is 4 cm × 5 cm and has an ARM Cortex-M0 processor, accelerometer and magnetometer sensors, Bluetooth and USB connectivity, a display consisting of 25 LEDs, two programmable buttons; and it can be powered by either USB or an external battery pack.The device inputs and outputs are through five ring connectors that are part of the 23-pin edge connector. And, we can do pretty cool stuff with this micro:bit. I am going to show you one of them.

Hardware Description


Picture Source: MIcro:bit developer community 

Pre-requisites
  1. Micro:bit(1 pcs)
  2. usb cable (1 pcs)
  3. Battery AAA 1.5V(2 pcs)
  4. Battery Box (1 pcs)


Pre-Test

So, let's test our Micro:bit before programming it. So, there are two ways to test your micro:bit.
  1. via USB cable
    You can test your micro: bit just to see if it is working fine or not. To do so connect your micro bit to your computer via USB cable and wait for a second your micro: bit will display "HELLO" by blinking LEDs. If it does then it is working fine.

  2. via Battery Connector
    Insert batteries into battery box and connect your micro bit via power pins and then see if it is displaying "HELLO". If it is then it is working fine.
So now, let's move to the coding part. Let us see how we can code and display "Hello" manually. Below are some steps to follow.

Go to Makecode.com

Microsoft Make Code is actually a platform that allows us to code for a micro:bit device and also provides an interactive simulator where we can debug and run our code. Also, we are able to see the expected result right there on the site.
Go to make code and choose Micro bit and click on code.



After this, you will see the following screen. As we can see, there is one micro:bit simulator which will show the output instantly when we finish writing our code.

We can see that there are different tools to program the micro:bit, just next to simulator. It is quite easy to program by dragging and dropping the blocks and if you want to see the codes behind, then you can click on JavaScript. It will displaythe JavaScript code there in IDE.



So, let's get started and display HELLO on our micro:bit. To do so, you just need to go to Basic and scroll down to see an onStart block. Now, drag and drop. Again go to basic and search for the show string <hello> block.
 
That's all. Now, you will see "HELLO" on your simulator.



After completing this step, micro:bit will restart itself and run the code. It will display HELLO there on the simulator. Yeah! quite easy. So let's move on and write code for the rest.

To display a rectangle on a micro:bit, go to Basic and find see forever block and drag and drop it. gain you go to Basic and drag show led block and turn on all the LEDs you want.for me, it is square/rectangle. It will display rectangle/square on the micro:bit.
 
For the button pressed event, go to input and drag button A is pressed block out and insert one showString block inside it. Then, customize the text you want to display when button A is pressed. For me, it is MICRO. 

Same goes for button B pressed and customize the text. Here is the sample.


So that's all for coding part.

Now, let us see how to run our code on actual Micro:bit. Just follow these steps.
  1. Plug in the Micro:bit device to a computer via USB.

  2. After plugging in, you should see HELLO on your Micro:bit by default.

    Go to your computer or press Windows +E (PC). For Linux, go to Files and you will see MICROBIT Drive there.



  3. Now, go to Makecode.com and download your program that you have written there.



  4. Go to your download folder and copy the downloaded Hex file in MICROBIT Drive. 

Now, wait for a second as the Micro:bit restarts. It will start displaying output automatically after that. That's all.

The output demo can be seen here:-https://www.youtube.com/watch?v=1YtSmww6bbc