Whenever you’re developing your projects, debugging with Makecode and micro:bit is often necessary to iron out any problems that may occur.

This guide will teach you the basics of setting up a debugging function that you can use with any project.

1. Create a debug function

Creating a debug function ensures that you can reuse it wherever you might need it, making it the most efficient way of debugging.

  • Go to https://makecode.microbit.org/ and create a new document. Name it Debugger.
  • Click on advanced>function>make function and name it debugger.
  • Add text and number fields.

edit function

  • From Advanced>Serial, add the following:

debugger function

  • Complete the on start and forever blocks like this:

Makecode micro:bit debugger

The forever block, will send the string “rotation value:” together with the rotation sensor reading to the debug function which will, in turn, send it all to the serial port which is redirected to the USB connection from the on start block. The info will then be available to see on your computer.

 

2. Monitor the output.

  • Connect the micro:bit to your computer using a micro USB cable.
  • Download the code you just created to the micro:bit.
  • In Makecode, click on Show console Device.
  • If you now tilt the micro:bit, you’ll see the rotation data displayed numerically and on a graph.

show console device

 

3. Do more

You can use the debugger function anywhere within your project to monitor what’s actually happening behind the scenes. To do this, adjust the label and pin to read when calling the function. As an example, below you can see the debugger function being called with Pin 2 value: as the label and Pin 2 as the displayed value.
debugger function

You can reuse the same function to display more than one value by calling it multiple times as shown below.

debugger multiple values

 

Like what you read? Why not show your appreciation by giving some love.

From a quick tap to smashing that love button and show how much you enjoyed this project.

Privacy

Our website uses cookies and similar technologies to provide you with a better service while searching or placing an order, for analytical purposes and to personalise our advertising. You can change your cookie settings by reading our cookie policy. Otherwise, we’ll assume you’re OK with our use of cookies.

Location

Please select an option to see content specific to your location and shop online.

Browse the US site