Categories
micro:bit Monday

Using The Pins

This week we will take a look at what we can do with the General Purpose Input Output (GPIO) pins. You can do a lot of things using the pins at the bottom of the micro:bit including using touch, connecting them to tinfoil, fruit, headphones or other electronic components using crocodile clips. You can even use them with add-on boards like motor controllers, LED screens and more.

MakeCode

  1. open MakeCode within your favourite browser
  2. Click on the on start block and drag it to the left and drop it in the bin. Do the same for the forever block
  3. Click on Input Click and drag a on p0 pressed block to the code area and drop it
  4. Click on Basic Click and drag a show string "Hello!" block to the code area and attach it within the on p0 pressed block

Your code is now complete and ready to download to your micro:bit.

NOTE: You can use this code different ways. You can just hold the GND pin and press pin 0 or you can glue some tinfoil to cardboard and connect the pins with crocodile clips.

Completed Code

Completed Code within MakeCode

EduBlocks

  1. Open EduBlocks within your favourite browser
  2. Click on Basic Click and drag a from microbit import * block to the code area and drop it
  3. Click on Basic Click and drag a while True: block to the code area and attach it under the from microbit import * block
  4. Click on Basic Click and drag a if True: block to the coding area and attach it within the while True: block
  5. Click on Pins Click and drag a pin 0.is_touched() block to the code area and attach it where it says True in the if block
  6. Click on Display Click and drag a display.scroll("Hello World") block to the code area and attach it within the if pin 0.is_touched() block

Your code is now complete and read to download to your micro:bit and try out.

Completed Code

Completed Code within EduBlocks

Python

  1. Open your favourite Python editor to use with the micro:bit
  2. Type from microbit import * This imports the Python library for micro:bit so we can now interact with the micro:bit
  3. Type while True: This creates a loop that will carry on while the conditions are true
  4. Type if pin0.is_touched: Creating a condition on pin 0, so when pin 0 is touched
  5. Type display.scroll("Hello World!") When pin 0 is touched Hello World! will scroll across the LED display.

Your code is now complete and ready to try out.

Completed Code

from microbit import *

while True:
    if pin0.is_touched:
        display.scroll("Hello World!")

That’s it for this week. Come back next Monday where we will dig into the pins a little bit deeper and create a simple robot.

Categories
micro:bit Monday

Using The Compass

Welcome to another micro:bit Monday blog post. This week we are going to look at creating a simple compass which shows the bearing from magnetic North in degrees.

The built-in compass sensor is called a magnetometer. This can be used to measure the Earths magnetic field.

Here is how to code it.

MakeCode

  1. Open MakeCode editor within your favourite browser
  2. Click and drag the forever block to the left and drop it in the bin
  3. Click on Basic Click and drag a show string "Hello!" block to the coding area and attach it within the on start block
  4. Click where it says Hello! and type Press button A
  5. Click on Input Click and drag an on button A pressed to the coding area and drop it
  6. Click on Basic Click and drag a show number 0 block to the coding area and attach it within the on button A pressed block
  7. Click on Input Click and drag a compass heading (°) block to the coding area and attach it within the 0 of the show number block

Your code is now ready to download to your micro:bit and test out

Completed Code

Completed code within MakeCode

EduBlocks

  1. Open EduBlocks within your favourite browser and click on micro:bit
  2. Click on Basic Click on from microbit import * and drop it within the coding area
  3. Click on Compass Click on compass.calibrate() and attach it under from microbit import *
  4. Click on Display Click and drag a display.scroll("Hello World") and attach it under compass.calibrate()
  5. Click on Hello World and type Press button A
  6. Click on Basic Click on while True: and attach it under display.scroll("Hello World")
  7. Click on Basic Click and drag an if True: block to the code area and attach it within the while True: block
  8. Click on Button Click and drag a button_a.was_pressed block to the code area and attach it within the True of the if block
  9. Click on Display Click and drag a display.scroll(0) block to the coding area and attach it within the if button_a.was_pressed
  10. Click on the 0 within the display.scroll block and type str(compass.heading())

Your code is now complete and ready to download to your micro:bit to test it.

Completed Code

Completed code within EduBlocks

Python

  1. Open up your favourite Python editor for the micro:bit
  2. Type from microbit import * This imports the micro:bit library to use within python so we can program with the micro:bit
  3. Type compass.calibrate() This tells the micro:bit to calibrate the magnetometer sensor
  4. Type display.scroll("Press button A") This scrolls Press button A across the LED Matrix
  5. Type while True: This create a loop that will go on forever
  6. Type if button_a.was_pressed() This creates a statement to check if button A on the micro:bit was pressed
  7. Type display.scroll(str(compass.heading())) This will scroll the direction the compass is facing in Degrees across the display

Your code is now ready to download to the micro:bit and test out.

Completed Code

from microbit import *

compass.calibrate()

display.scroll("Press button A")

while True:
    if button_a.was_pressed()
    display.scroll(str(compass.heading()))

That’s it for this week comeback next week where we discover how to use the pins on the bottom edge of the micro:bit

Categories
micro:bit Monday

Temperature Sensing

This week in micro:bit Monday we will be looking at the temperature sensor to detect what the temperature is and display it on the LED matrix.

You can do this indoors tethered to your computer by the USB cable or why not attach a battery pack and take it outdoors and see what the difference in temperature is!

MakeCode

  1. Open MakeCode within your favourite browser and open a new project
  2. Click and drag the on start block to the left of the screen and drop it in the bin
  3. Click on Basic, click and drag a show number 0 block to the code area and attach it within the forever block
  4. Click on Input, click and drag a temperature (°c) block to the code area and drop it within the 0 of the show number block

Now you can download your code and test on an actual micro:bit!

Completed Code

Completed code within MakeCode

EduBlocks

  1. Open EduBlocks within your favourite browser and click on micro:bit
  2. Click on Basic, click and drag a from microbit import * block to the code area and drop it
  3. Click on Basic, click and drag a while True: block to the code area and attach it under from microbit import *
  4. Click on Display, click and drag a display.scroll(0) block to the code area and attach it within the while True: block
  5. Click within the 0 of the display.scroll block and type temperature ()

Your code is now completed and ready to download to your micro:bit

Completed Code

Completed code in EduBlocks

Python

  1. Open your favourite Python editor used to code the micro:bit
  2. Type from micro:bit import * This will import the micro:bit library and allow you to interact with the micro:bit
  3. Type while True: This will create a loop that will keep executing the instructions inside it forever
  4. Type display.scroll(temperature()) This will scroll the current temperature across the LED matrix

Your code is now complete and ready to download(flash) to your micro:bit

Completed Code

from microbit import *

while True:
    display.scroll(temperature())

That’s it for this week come back next Monday to find out how to use the compass on the micro:bit

Categories
micro:bit Monday

Using The Accelerometer

This week we are going to look at the accelerometer. The accelerometer allows us to use the micro:bit to detect movement, whether this is counting steps, detecting if someone or something is falling.

There are two ways to use the accelerometer, either through the shake function or the acceleration block, We will be consentrating on the accelerometer block.

Let’s take a look at the code!

MakeCode

  1. Open MakeCode editor within your favourite browser
  2. Click and drag the on start block to the left and drop it in the bin
  3. Click on Variables Click on Make a Variable… Type reading and click on Ok
  4. Click on Variables Click on set reading to 0 and drag it to the coding area and attach it within the forever block
  5. Click on Input Click and drag acceleration (mg) x to the coding area and attach it within the 0 of the set reading to block
  6. Click on Logic click and drag a if true then else block to the coding area and attach it under set reading to acceleration (mg) x block
  7. Click on Logic Click and drag a 0 < 0 block to the coding area and attach it within the true of the if then block
  8. Click on Variables click and drag reading to the coding area and attach it within the first 0 of the if then block
  9. Click on Basic Click and drag a show string "Hello" block to the coding area and attach it under if reading < 0 then Click where it says Hello and type R Click on the small + below else
  10. Click on Logic Click and drag a 0 < 0 block to the code area and attach it within the blank space of the else if block
  11. Click on Variables click and drag a reading block to the coding area and attach it within the first 0 of the else if block
  12. Click on Basic Click and drag a show string "Hello" block to the coding area and attach it under else if reading > 0 then Click on **Hello and type L
  13. Click on Basic Click and drag a show string "Hello block to the code area and click on Hello and type

Your code is now ready to download to your micro:bit and test out.

Completed Code

Completed Code In makeCode

EduBlocks

  1. Open EduBlocks within your favourite browser and click on micro:bit
  2. Click on Basic Click on from microbit import * and drop it within the coding area
  3. Click on Basic Click on while True: and attach it under from microbit import *
  4. Click on Variables Click on Create variable… Type reading and click on OK
  5. Click on Variables Click and drag a reading = 0 block to the code area and attach it within while True
  6. Click on Accelerometer Click and drag a accelerometer.get_x() block to the code area and attach it within the 0 of the reading = 0 block
  7. Click on Basic Click and drag an if True: block to the coding area and attach it under reading = accelerometer.get_x()
  8. Click on Basic Click and drag a 0 == 0 block to the coding area and attach it within True of the if True: block. Click on the little arrrow next to == and click on <
  9. Click on Variables Click and drag reading to the code area and attach it within the first 0 of the if block
  10. Click on Display Click on display.show(Image.HAPPY) and drag it to the coding area and attach it under if reading < 0: Click where it says Image.HAPPY and type "R"
  11. Click on Basic Click and drag a elif True: block to the coding area and attach it under the if reading < 0: block
  12. Click on Basic Click and drag a 0 == 0 block to the coding area and attach it within the True of the elif True block. Click on the small arrow next to == and click on >
  13. Click on Variables Click and drag a reading block to the code area and attach it within the first 0 of the elif
  14. Click on Display Click and drag a display.show(Image.HAPPY) to the code area and attach it within the elif reading > 0 block Click on Image.HAPPY and type "L"
  15. Click on Basic Click and drag a else: block to the code area and attach it under the elif reading > 0
  16. Click on Display Click and drag a display.show(Image.HAPPY) block to the code area and attach it within the else: block. Click on Image.Happy and type "-"

Your code is now complete and read to download to your micro:bit to test it.

Completed Code

Completed Code in EduBlocks

Python

  1. Open up your favourite Python editor for the micro:bit
  2. Type from microbit import * This imports the micro:bit library to use within python so we can program with the micro:bit
  3. Type while True: This create a loop that will go on forever
  4. Type reading = accelerometer.get_x() This create a variable callled reading and sets it to the x axis of the accelerometer
  5. Type if reading < 0: This creates a statement to check if the micro:bit is tilted to the left
  6. Type display.show("R") If the micro:bit is tilted to the left it displays an "R" on screen to get you to tilt it back to the centre
  7. Type elif reading > 0: This checks to to see if the micro:bit is tilted to the right
  8. Type display.show("L") if the micro:bit is tilted to the right it displays an "L" on screen to get you to tilt the micro:bit back to the centre
  9. Type else: This checks to make sure the micro:bit is centre
  10. Type display.show("-") This displays a line on the screen if the micro:bit is sat centered.

Your code is now ready to download to the micro:bit and test out.

Completed Code

from microbit import *

while True:
    reading = accelerometer.get_x()
    if reading < 0:
        display.show("R")
    elif reading > 0:
        display.show("L")
    else:
        display.show("-")

Conclusion

You may have noticed that we have just created a simple spirit level, so you can now go and check whether the surfaces within your house or classroom are level.

I have shown you one way here to use the accelerometer another way is to use the on shake function.

Hope you enjoyed this and come back next week where we explore the temperature sensor.

Categories
micro:bit Monday

Sensing Light

This week in micro:bit Monday we are going to discover how to use the micro:bit to detect light.

The micro:bit doesn’t have a light sensor built in, but we can use the LED matrix to detect how much light there is in a room. This can be then used to make a night light, or a light for the front of a scooter or bike or even just attached to you and it will turn on when it starts to get dark.

Let’s take a look at the code.

MakeCode

  1. Open MakeCode within your favourite browser
  2. Click and drag on start to the left and drop it in the bin
  3. Click on Logic Click and drag a if true then else block to the coding area and drop it inside the forever block
  4. Click on Logic Click and drag a 0 < 0 block to the code area and attach it within the ** if** block where it says true
  5. Click on Input click and drag a light level block to the code area and attach it wihtin the first 0 within the if block type 100 within the second 0
  6. Click on Basic Click and drag a show leds block to the code area and attach it within the if light level < 100 then block CLick on all the squares to turn them white
  7. Click on Basic Click on more Click and drag a clear screen block to the coding area and attach it within the else block.

You are now ready to download the code to your micro:bit and detect light.

Completed Code

Completed Code

EduBlocks

  1. Open EduBlocks within your favourite browser
  2. Click on Basic Click and drag a **from microbit import *** to the code area and drop it
  3. Click on Display click and drag an image = () block to the coding area and attach it under the **from microbit import **. Replace all the 0 with a 9
  4. Click on Basic Click and drag a while True block to the coding area and attach it under the image = () block
  5. Click on Basic Click and drag an if True block to the coding area and attach it within the the while True block
  6. Click on Basic click and drag a 0 < 0 block to the code area and attach it within the True of the if block. Click on the first 0 and type display.read_light_level() click on the second 0 and type 100
  7. Click on Display Click and drag a display.show(Image.HAPPY) block to the code area and attach it within the if display.read_light_level() < 100: block
  8. Click on Variables Click and drag a image block to the code area and attach it within the display.show block where it says Image.HAPPY
  9. Click on Basic Click and drag an else block to the code area and attach it under the if block
  10. CLick on Display Click and drag a display.clear() block to the code area and attach it within the else block.

Your code is now complete and ready to download to your micro:bit.

Completed Code

Completed Code

Python

  1. Open your favourite Python editor

  2. Type from microbit import * This imports the micro:bit library

  3. Type while True: This creates a loop that runs while the conditions are True

  4. Type if display.read_light_level() < 100: This checks that the light level is less than 100

  5. Type

    display.show(Image(
         "99999:"
         "99999:"
         "99999:"
         "99999:"
         "99999"))
    

    This makes the LED display light up if the light is less than 100

  6. Type else: This creates a condition for when the light is 100

  7. Type display.clear() this clears the LED matrix.

Your code is now complete and ready to download and run on your micro:bit.

Completed Code

from microbit import *

while True:
    if display.read_light_level() < 100:
        display.show(Image(
        "99999:"
        "99999:"
        "99999:"
        "99999:"
        "99999"))
    else:
        display.clear()

Thats it for another week! Come back next week where we will be looking at the micro:bit tilt function.

Categories
micro:bit Monday

Using The Radio

This week in micro:bit Monday we are going to discover how to use the micro:bit radio.

MakeCode

  1. open MakeCode within your favourite browser
  2. Click and drag the forever block to the left to delete it as we will not be using that block
  3. Click on Radio Click and drag a radio set group 1 to the code area and attach it within the on start block
  4. Click on Input Click and drag a on button A pressed block to the code area
  5. Click on Basic Click on …more click and drag a clear screen block to the coding area and attach it within on button A pressed block
  6. Click on Radio Click and drag a radio send string "" block to the coding area and attach it under the clear screen block within the on button A pressed block
  7. Click within the blank space of the radio send string block and type Hello
  8. Click on Radio Click and drag a on radio received receivedString block to the coding area
  9. Click on Basic Click and drag a Show String "Hello" block to the coding area and attach it within the on radio received receivedString block.

Your code is now complete and ready to download to a micro:bit.

Completed Code

Completed Code within MakeCode

EduBlocks

  1. Open EduBlocks within your favourite browser and click on micro:bit
  2. Click on Basic Click and drag a **from microbit import *** block to the coding area
  3. Click on Radio Click and drag a import radio block to the code area and attach it under the **from microbit import *** block
  4. Click on Radio click and drag a radio.on() block to the coding area and attach it under the import radio block
  5. Click on Radio Click and drag a radio.config(channel=7) block to the code area and attach it under radio.on()
  6. Click on Basic Click and drag a while True: block to the code area and attach it under radio.config(channel=7) block
  7. Click on Display Click and drag a display.clear block to the coding area and attach it within the while True block
  8. Click on Basic click and drag an if True: block to the code area and attach it under display.clear
  9. Click on Buttons Click and drag a button_a.is_pressed() block to the coding area and attach it within the if block where it says True
  10. Click on Radio click and drag a radio.send("hello") block to the coding area and attach it within the if button_a.is_pressed() block
  11. Click on Radio click and drag a incoming=radio.receive() block to the code area and attach it under the if button_a.is_pressed(): block
  12. Click on Radio Click and drag a if incoming == "hello": block to the code area and attach it under the incoming=radio.received() block
  13. Click on Display Click and drag a display.scroll("Hello World") block to the coding area and attach it within the if incoming =="hello" block
  14. Click on Basic Click and drag a sleep(1000) block to the code area and attach it under the if incoming == "hello": block.

Your code is now complete and ready to download.

Completed Code

Completed EduBlocks Code

Python

  1. Open your favourite micro:bit Python editor
  2. Type from microbit import * this impoorts the micro:bit libaray for us to communicate with the micro:bit
  3. Type import radio this will import the radio libaray for us to communicate with the radio on the micro:bit
  4. Type radio.on() This will turn the radio module on so we can interact with it
  5. Type radio.config(channel=1) this sets the radio channel to 1. It is important to make sure the micro:bits you are using are on the same channel. These can be numbered from 1-255.
  6. Type while True: This will create a loop that will run forever
  7. Type dispplay.clear() this clears the display on the micro:bit
  8. Type if button_a.is_pressed(): this executes the next instuction if button a on the micro:bit is pressed
  9. Type radio.send("hello") This sends the message hello to another micro:bit that is listening on the same channel
  10. Type incoming=radio.receive() This sets a variable called incoming to radio.receive
  11. Type if incoming == "hello": This executes the next lot of instructions if the incoming message = hello
  12. Type display.scroll("Hello World") this will scroll Hello World accross the micro:bit display
  13. Type sleep(1000) this will pause the program for 1 second.

Your code is now complete and ready to be flashed to the micro:bit.

Completed Code

from microbit import *
import radio

radio.on()

radio.config(channel=1)

while True:
    display.clear()
    if button_a.is_pressed():
        radio.send("hello")
    incoming=radio.receive()
    if incoming == "hello":
        display.scroll("Hello World")
    sleep(1000)

Challenge

Why not send a message to your partner with your name.

Categories
micro:bit Monday

micro:bit Buttons

Welcome to another micro:bit Monday post. Today we will be looking at what we can do with the buttons on the micro:bit.

MakeCode

Here is how to use the buttons within the Microsoft MakeCode editor.

  1. Open MakeCode within your favourite browser.
  2. Click and drag the forever block from the coding area to the left side of the screen and drop it in the bin.
  3. Click on Basic. Click and drag a show string "Hello!" block to the coding area and attach it within the on start block.
  4. Within the show string block click on "Hello!" and type Press button A.
  5. Click on Basic. Click and drag a show leds block to the coding area and attach it under the show string "Press button A" block. Now create an arrow pointing left like this:
Left-facing Arrow
  1. Click on Input. Click and drag an on button A pressed block to the coding area and drop it.
  2. Click on Basic. Click and drag a show icon block to the coding area and attach it within the on button A pressed block. Change the icon by clicking on the white arrow to a happy face.
  3. Click on Basic. Click and drag a show string "Hello!" block to the coding area and attach it under the show icon block. Now change the text to read Press button B.
  4. Click on Basic. Click and drag a show leds block to the coding area and attach it under show string "Press button B block. Now create a right facing arrow.
Right-facing arrow
  1. Click on Input. Click and drag an on button A pressed block to the coding area and drop it. Click on the small arrow next to A and click on B.
  2. Click on Basic. Click and drag a show icon block to the coding area and attach it within the on button B pressed block. Change the icon by clicking on the white arrow to a happy face.
  3. Click on Basic. Click and drag a show string "Hello!" block to the coding area and attach it under the show icon block. Now change the text to read Press button A + B.
  4. Click on Basic. Click and drag a show leds block to the coding area and attach it under show string "Press button A + B block. Now create a right and left facing arrow.
Left and right-facing arrows
  1. Click on Input. Click and drag an on button A pressed block to the coding area and drop it. Click on the small arrow next to A and click on A+B.
  2. Click on Basic. Click and drag a show icon block to the coding area and attach it within the on button A+B pressed block. Change the icon by clicking on the white arrow to a happy face.
  3. Click on Basic. Click and drag a show string "Hello!" block to the coding area and attach it under the show icon block. Now change the text to read You now know how to use the buttons!.

Your completed code should look like this:

Completed Code

EduBlocks

Here is how to use buttons within EduBlocks.

  1. Open EduBlocks within your favourite browser and click on micro:bit.
  2. Click on Basic. Click and drag a **from microbit import *** block to the coding area and drop it.
  3. Click on Display. Click and drag a display.scroll("Hello World") block to the coding area and attach it under the **from microbit import *** block.
  4. Click where it says Hello World and delete it, now type Press button A.
  5. Click on Basic. Click and drag a sleep(1000) block to the coding area and attach it under display.scroll("Press button A").
  6. Click on Display. Click and drag a display.show(Image.HAPPY) block to the coding area and attach it under sleep(1000) block. Click on where it says Image.HAPPY and delete it, now type Image.ARROW_W.
  7. Click on Basic. Click and drag a while True: block to the coding area and attach it under display.show(Image.ARROW_W) block.
  8. Click on Basic. Click and drag an if True: block to the coding area and attach it within the while True: block.
  9. Click on Buttons. Click and drag a button_a.is_pressed() block to the coding area and attach it within the True of the if True: block.
  10. Click on Display. Click and drag a display.show(Image.HAPPY) block to the coding area and attach it within if button_a.is_pressed block.
  11. Click on Basic. Click and drag a sleep(1000) block to the coding area and attach it under display.show(Image.HAPPY)
  12. Click on Display. Click and drag a display.scroll ("Hello World") block to the coding area and attach it under the sleep(1000) block.
  13. Click where it reads Hello World and delete it, now type Press button B.
  14. Click on Display. Click and drag a display.show(Image.HAPPY) block to the coding area and attach it under display.scroll("press button B").
  15. Click where it says Image.HAPPY and delete it, now type Image.ARROW_E.
  16. Click on Basic. Click and drag an if True: block to the coding area and attach it under the if button_a.is_pressed(): block.
  17. Click on Buttons. Click and drag a button_a.is_pressed() block to the coding area and attach it within the True of the if True: block. Click on the little arrow next to a and click on b.
  18. Click on Display. Click and drag a display.show(Image.HAPPY) block to the coding area and attach it within if button_b.is_pressed block.
  19. Click on Basic. Click and drag a sleep(1000) block to the coding area and attach it under display.show(Image.HAPPY)
  20. Click on Display. Click and drag a display.scroll ("Hello World") block to the coding area and attach it under the sleep(1000) block.
  21. Click where it reads Hello World and delete it, now type Well done! you now know how to use buttons!

Your completed code should look like this:

Completed Code

Python

There are two common ways to program the micro:but using microPython. The first one is to open the web version in your browser Python or by downloading the Mu editor from downloading Mu (within this post I am using My)

  1. Open your preferred method for programming Python.
  2. Type from microbit import * this will import the micro:bit library to use with Python and press enter.
  3. Type display.scroll("Press button A this will display press button A scrolling accross the LED matrix.
  4. Type sleep(1000) This will pause the program for 1 second.
  5. Type display.show(Image.ARROW_W) this will display a left facing arrow on the LED matrix.
  6. Type while True: this will make the code loop forever.
  7. type if button_a.is_pressed(): this will run the next lot of code only if the A button on the micro:bit has been pressed.
  8. Type display.show(Image.HAPPY) this will show a happy face on the LED matrix.
  9. Type sleep(1000) this will pause the program for one second.
  10. Type display.scroll("Press button B") this is will scroll Press button B accross the LED display.
  11. Type display.show(Image.ARROW_E) this will display a right facing arrow on the LED matrix.
  12. Type if button_b.is_pressed(): this will execute the next bit of code if button B is pressed.
  13. Type display.show(Image.HAPPY) This will show a happy face on the LED matrix.
  14. Type sleep(1000) this will pause the program for 1 second.
  15. Type display.scroll("Well done! You can now use buttons!") this will scroll accross the LED matrix.

Completed code

from microbit import *

display.scroll("Press button A")
sleep(1000)
display.show(Image.ARROW_W)
while True:
    if button_a.is_pressed():
        display.show(Image.HAPPY)
        sleep(1000)
        display.scroll("Press button B")
        display.show(Image.ARROW_E)
    if button_b.is_pressed():
        display.show(Image.HAPPY)
        sleep(1000)
        display.scroll("Well done! You can now use buttons!")

Challenge

Now that you know how to use the buttons on your micro:bit why not go back to to last weeks challenge and add more to your name badge so different messages or images display when you press a button.

Categories
micro:bit Monday

micro:bit LED Matrix

Within this post we are going to get to know what we can do with the LED matrix on the front of the micro:bit.

I will include code for the MakeCode, EduBlocks and microPython editors.

Lets get started!

Displaying Text

The first thing we will look at is to display text on the micro:bit, This could be used to send messages or used as a name badge.

MakeCode

Here is how to display text using MakeCode:

  1. Open the MakeCode editor in your favourite browser MakeCode
  2. Delete the on start block by clicking and dragging it to the left odf the screen and dropping it on the recycle bin.
  3. Click on Basic. Click and drag a show string "Hello!" block to the code area and attach it within the forever code block.
  4. Click on Download to download the code to your computer.
  5. Plug your micro:bit into your computer using a microUSB cable.
  6. Navigate to where your code downloaded to, This will normally be the downloads folder on your computer. Copy the file to the MICROBIT drive.

Once the code has copied to the micro:bit you will see Hello! scroll across the LED Matrix.

Completed Code

Completed code for Displaying text on a micro:bit in MakeCode

Simulation of micro:bit

EduBlocks

  1. Open the EduBlocks editor in your favourite browser EduBlocks
  2. Click on micro:bit.
  3. Click on Basic. Click and drag a **from microbit import *** and drop it within the coding area.
  4. Click on Basic. Click and drag a while True: block to the code area and attach it under **from microbit import ***.
  5. Click on Display. Click and drag a display.scroll("Hello World") to the coding area and attach it within the while True: block.
  6. Click on Download Hex, this will download the code to your computer.
  7. Plug your micro:bit into your computer using a microUSB cable.
  8. Navigate to where your code downloaded to, This will normally be the downloads folder on your computer. Copy the file to the MICROBIT drive.

Once the code has copied to the micro:bit you will see Hello World scroll across the LED Matrix.

Completed Code

Completed code for displaying text on a micro:bit using EduBlocks

Simulation of micro:bit

Python

There are two common ways to program the micro:but using microPython. The first one is to open the web version in your browser Python or by downloading the Mu editor from downloading Mu (within this post I am using My)

  1. Open your preferred method for programming Python.
  2. Type from microbit import * this will import the micro:bit library to use with Python and press enter.
  3. Type while True: this will create a while True loop meaning that the code inside it runs forever press enter.
  4. Type display.scroll("Hello World") This will display Hello World on the micro:bit LED matrix forever.
  5. Plug your micro:bit into your computer using a microUSB cable.
  6. Click on Flash, this will download the code to your computer (if this gives you an error click flash again and it should work).

Completed code

from microbit import *

while True:
    display.scroll("Hello World")

Simulation of the micro:bit

Displaying Images

The other thing we can use the LED matrix for is displaying images. Let’s look and see what we can do by expanding on the code above.

MakeCode

  1. Click on Basic. Click and drag a show icon block to the code area and attach it under the show string "Hello! code block.
  2. Click on Download to download the code to your computer.
  3. Navigate to where your code downloaded to, This will normally be the downloads folder on your computer. Copy the file to the MICROBIT drive.

Once the code has copied to the micro:bit you will see Hello!+heart scroll across the LED Matrix (see the simulator below).

you can also change the icons by clicking the white arrow next to the heart.

Completed Code

Completed code to show Text and images together on a micro:bit using MakeCode

Simulation of micro:bit

EduBlocks

  1. Click on Display. Click and drag a display.show(Image.HAPPY) block to the code area and attach it under the display.scroll("Hello World") code block.
  2. Click on Basic. Click and drag a sleep(1000) block to the code area and attach it under display.show(Image.HAPPY)
  3. Click on Download Hex to download the code to your computer.
  4. Navigate to where your code downloaded to, This will normally be the downloads folder on your computer. Copy the file to the MICROBIT drive.

Once the code has copied to the micro:bit you will see Hello Wold +a happy face scroll across the LED Matrix (see the simulator below).

you can also change the icons by typing a name of an image all in CAPS after Image. here is a list of supported Images Supported Images

Completed Code

Completed code to show Text and images together on a micro:bit using EduBlocks

Simulation of micro:bit

Python

  1. Type display.show(Image.HAPPY) and press enter. This will display a picture of a happy face.
  2. Type sleep (1000). This will pause your program for 1 second. If this isn’t included your program will skip over the happy face.
  3. Click on Flash to download the code to your micro;bit.

Once the code has copied to the micro:bit you will see Hello Wold +a happy face scroll across the LED Matrix (see the simulator below).

you can also change the icons by typing a name of an image all in CAPS after Image. here is a list of supported Images Supported Images

Completed Code

from microbit import *

while True:
    display.scroll("Hello World")
    display.show(Image.HAPPY)
    sleep(1000)

Simulation of micro:bit

Challenge

Use what you have learned within this blog post to make a custom Name badge.

That’s all for Today! Come back next week to learn all about another feature of the micro:bit.

Categories
Robotics

Robot Coding Lab

On the 25th and 26th of January 2020, RaspiKidd ran a Robot Coding Lab within the V&A Dundee.

Over the two days, a group of kids learned how to code robots using various robots and applications.

All Setup and ready to go

Day 1

On day one the kids got to have a tour of the robot exhibition though I think the biggest hit with them was the drawing robots on the way out (See the images below). After this they got to learn how to program robots, the robots available were Giggle bot from Dexter Industries, K8 From Inksmith a sphero mini and a sphero R2D2.

The Giggle bot and K8 were coded using micro:bits and the microbit app. The sphero robots were coded using the sphero edu app on ipads.

The kids had great fun working out how each robot worked and how they could improve the code to make it run better.

This was all in practice and getting used to the micro:bit, so they were ready to build and code their own robots on Day 2.

K8 coded to follow lines

Day 2

On day two once all the kids had a arrived they got shown the equipment they would be using throughout the day this included:

  • 1 x micro:bit
  • 1 x battery pack and 4 AA batteries
  • 1 x 4Tronix DriveBit motor controller
  • Ipad/computer
  • 2 x DC hobby motors and wheels
  • Cardboard and other craft materials

With this equipment, the kids were given free rein to design and build their robots as they wanted.

They ended up splitting their selves into 3 teams, the team split them selfs up into who was doing the coding of the robot and who was building it.

To give the day more of a purpose we set the challenge of football-playing robots. The kids got so enthusiastic over this that they built the football arena before starting their robots. Adding a bit more fun to this too and because we had enough micro:bits the team got the challenge of coding a second micro:bit to control their robot.

In the end, we only had two out of the three robots able to play football due to one team making their robot chassis too heavy that the motors couldn’t turn properly.

The three robots

Once all the robots were finished we got on with the game of football though at one point this turned out more like a bit of sumo wrestling.

All in all the weekend was a huge success the kids had great fun and even though they were learning it did not seem like it. See the video below for a full highlights tour of the weekend.

Video round-up
Categories
Installation Guide

Installing Mu

Mu is a simple code editor developed in Python for Python. Mu has built-in support for Adafruit Circuit Playground Express, micro:bit, PyGame and Python. Mu runs on Windows, Mac, Linux and even the Raspberry Pi.

Installing on Windows

Installing on Linux

Installing on Raspberry Pi

Installing Mu On Windows

  1. Go to codewith.mu
  2. Click on Download
  3. Under Windows Installer click on either 32 bit or 64 bit depending on the Operating System you are running. To find out what version of Windows you are running follow these instructions:
    1. Open Explorer
    2. Right click on this PC
    3. Click on properties. Under system type it will say either 32 bit or 64 bit
  1. Once the installer has downloaded. Locate where the file was downloaded to (normally your Downloads folder)
  2. Double click on the file to run the installer
  3. Follow the instructions on screen

You have now got Mu installed on your computer Happy Coding.

Installing Mu On Linux

Each Linux distro is a bit different, so for this guide, I am going to focus on Ubuntu.

  1. Open up a Terminal window.
  2. Mu requires Python3. You can check and see if you have Python3 installed by typing python3 --version If nothing is displayed type sudo apt install python3to install Python3.
  3. You also need pip3 installed type pip3 --version If it shows nothing you need to install pip3 by typing sudo apt install python3-pip
  4. Finally to install Mu type pip3 install mu_editor
  5. You can now run Mu from the command line by typing Mu

Now that you have Mu installed you can go and develop in Python3, MicroPython for micro:bit or even CircuitPython for the Adafruit Circuit Playground Express.

Installing Mu On Raspbian

If you are running the latest version of Raspbian (Buster) Mu is in the recommended software menu.

  1. Click on the Raspberry in the top left corner to open the menu
  2. Hover over preferences
  3. Click on Recommended Software
  4. Click on Programming
  5. Click on Mu and then click on OK.

If Mu isn’t already under the Recommended Software update your Raspberry Pi by following these steps:

  1. Open a terminal by clicking on the black square on the menu bar at the top
  2. Type sudo apt update and press enter
  3. Type sudo apt dist-upgrade and press enter
  4. Once this has complete follow the instructions above to install Mu

Well done you now have Mu installed you can now write some Python code.