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