Sean's Technology and Writing Blog

How to use the micro:bit with Scratch

18 March 2020


When I wrote the updated version of Scratch Programming in Easy Steps, I was keen to cover devices such as the micro:bit and the Raspberry Pi Sense HAT, which are not covered in most other books. Using the new Extensions feature in Scratch 3, it's now possible to add blocks to the Blocks Palette to support these devices. In this blog, I'll tell you more about using the micro:bit.

BBC Microbit photo

The micro:bit is a small device (about 6cm measured diagonally) that provides an easy introduction to physical computing with Scratch. It includes a 5x5 grid of red LEDs, two buttons, and tilt sensors. There are also GPIO pins that enable you to connect up circuits easily using crocodile clips. At about £15, the micro:bit is a great investment.

You can use all of these micro:bit features from the latest version of Scratch, by connecting to the micro:bit over Bluetooth. To set up your micro:bit for Scratch, follow these steps:

  1. Install the Scratch Link software on your PC, if you haven't done this already.
  2. Connect your micro:bit to your PC using a USB cable. Download the HEX file and copy it to your micro:bit using drag and drop in Windows. You only need to do this once.
  3. Run Scratch Link.
  4. Start Scratch. In the bottom left, use the Add Extension button to add the micro:bit extension.
  5. You'll see any available micro:bits with their code. When connected to power, your micro:bit scrolls its identity code across it too. Select your micro:bit to connect.
  6. You can now use the new Scratch blocks in the Blocks Palette to interact with your micro:bit.

The new blocks are shown below:

new micro:bit blocks in Scratch

These blocks include hat blocks to start a new script when the A, B or either button is pressed; when the micro:bit is moved, shaken or jumped; or when the micro:bit is tilted in a particular direction or in any direction. There are also blocks you can use to find out whether the micro:bit is tilted in a particular direction, or what the tilt angle is in a particular direction.

For the updated edition of Scratch Programming in Easy Steps, I created a game called Balloon Floater as a documented example to show how the micro:bit works with Scratch. To play it, you tilt the micro:bit to change the velocity of a balloon as it floats through a cave. I included "zoom to end" and "brake" controls using the A and B buttons. The game looks like this:

Balloon Floater screenshot from Scratch Programming in Easy Steps

I've also written a project for the latest issue of micro:mag magazine, which is available for free download or pre-order in print. You can download the Scratch file for this project here. This is an audio game, which uses the new text-to-speech extension to tell you how to move the micro:bit and times how long you take to do so. As written, the game is fairly easy but becomes a test of focus, the longer the game goes on. The arrows in the game are irrelevant and are there to try to confuse you! How long can you focus on responding quickly? The game can be adapted so it challenges you to repeat a pattern, or requires you to respond quickly to stay in the game. Here's a video demo:

Here are some observations I made from this project, and the Balloon Floater project:

  • If you want to detect a deliberate tilt motion look for the tilt angle being more than 20 or 30 degrees. If you use the "tilted?" or the "when tilted" blocks, it's easy for accidental movements to register. That was a problem particularly with the audio game. For that reason, I didn't use the "when tilted" blocks, and instead used a loop that continuously checks whether the tilt angle is more than 20 or 30 degrees in each direction.
  • I couldn't include the jump or shake movements in the audio game (which would have been a fun addition), because those motions also triggered the tilt motions. It was difficult to separate them out. There might be workarounds, but within the confines of creating a simple tutorial, the code required to use hat blocks for some movements and if blocks for others was too complex anyway. I'm not sure it's possible to guarantee that a jump or shake registers as one of those movements before it is detected as a tilt.
  • You can use Blu Tack to fix the battery pack to the back of the micro:bit. I'm sure fancy cases are available, but a blob of the blue does the job just fine. It enables you to move the device freely so you can play the game effectively.
  • The new text-to-speech function in Scratch 3 is great. You can use it to say predefined text out loud, but it can also read out variable values, including numbers. That might be obvious to some, but it is such a cool feature, I think it's worth mentioning. When I updated Scratch Programming in Easy Steps, I also used this feature for the word game inspired by Hangman and the simple chatbot project.
  • The new pitch change effects make the music higher and faster with each successful round of the audio game, which creates tension. This effect could be used well in arcade games too, and can also be used for music. I used it in my Space Opera project (in the book) to change the pitch of a singing sound effect for a virtual instrument.

The article in micro:mag shows you how to build the audio game, and I hope it will prove a fun basis for experimentation for teachers, students and hobbyists. I hope the article is clear, but if you're experiencing difficulties, here are some debugging tips that didn't fit in the magazine:

  • Don’t hear anything? Check your PC volume. The sound comes from the computer, not the micro:bit.
  • Game behaves strangely? Check there are no extra spaces wherever the “game over” variable is being used.
  • Movements not working correctly? Check the “get player’s move” and “set up variables” scripts.

I'd like to give a shout out to the team that puts micro:mag together, including Joshua Lowe, Kerry Kidd and Luke Castle. It really is an awesome resource for the edtech community, and they are all volunteers, making it happen. You can support the mag by sharing it, buying it or the associated merchandise, or contributing. You can also donate to the magazine, or place an advert if you have a related product.

Find out more about micro:mag and download the latest issue here. There's more information about the new edition of Scratch Programming in Easy Steps on my blog here. You can find my hub for Scratch resources here.


Permanent link for this post | Blog Home | Website Home

Comments

Post a Comment

Dip into the blog archive

June 2005 | September 2005 | January 2006 | March 2006 | April 2006 | May 2006 | June 2006 | July 2006 | August 2006 | September 2006 | October 2006 | November 2006 | December 2006 | February 2007 | March 2007 | April 2007 | May 2007 | June 2007 | July 2007 | August 2007 | September 2007 | October 2007 | November 2007 | December 2007 | January 2008 | February 2008 | March 2008 | April 2008 | May 2008 | June 2008 | July 2008 | August 2008 | September 2008 | October 2008 | November 2008 | December 2008 | January 2009 | February 2009 | March 2009 | April 2009 | May 2009 | June 2009 | July 2009 | August 2009 | September 2009 | October 2009 | November 2009 | December 2009 | January 2010 | February 2010 | March 2010 | April 2010 | May 2010 | June 2010 | August 2010 | September 2010 | October 2010 | November 2010 | December 2010 | March 2011 | April 2011 | May 2011 | June 2011 | July 2011 | August 2011 | September 2011 | October 2011 | November 2011 | December 2011 | January 2012 | February 2012 | March 2012 | June 2012 | July 2012 | August 2012 | September 2012 | October 2012 | December 2012 | January 2013 | February 2013 | March 2013 | April 2013 | June 2013 | July 2013 | August 2013 | September 2013 | October 2013 | November 2013 | December 2013 | January 2014 | February 2014 | March 2014 | April 2014 | May 2014 | June 2014 | July 2014 | August 2014 | September 2014 | October 2014 | November 2014 | December 2014 | January 2015 | February 2015 | March 2015 | April 2015 | May 2015 | June 2015 | September 2015 | October 2015 | December 2015 | January 2016 | February 2016 | March 2016 | May 2016 | July 2016 | August 2016 | September 2016 | October 2016 | November 2016 | December 2016 | January 2017 | July 2017 | August 2017 | October 2017 | November 2017 | January 2018 | February 2018 | August 2018 | October 2018 | November 2018 | December 2018 | January 2019 | March 2019 | June 2019 | August 2019 | September 2019 | October 2019 | January 2020 | February 2020 | March 2020 | Top of this page | RSS

Credits

© Sean McManus. All rights reserved.

Visit www.sean.co.uk for free chapters from Sean's coding books (including Mission Python, Scratch Programming in Easy Steps and Coder Academy) and more!

Discover my latest books

Mission Python book

Mission Python

Code a space adventure game in this Python programming book published by No Starch Press.

Coder Academy book

Coder Academy

Learn to make games and other programs in Scratch, and make a web page in HTML. Highly interactive book for 7-10 year olds.

Cool Scratch Projects in Easy Steps book

Cool Scratch Projects in Easy Steps

Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!

Walking astronaut from Mission Python book Top | Search | Help | Privacy | Access Keys | Contact me
Home | Newsletter | Blog | Copywriting Services | Books | Free book chapters | Articles | Music | Photos | Games | Shop | About