programming

Contents

What is programming?

The above video is from the Khan academy, here is a nice intro level course to programming in the Khan Academy using Javascript (what makecode uses behind the scenes). Of course this is optional, and perhaps a bit of extra fun, but you can simply use the Block coding approach in the makecode environment.

Embedded programming

Embedded programming a term used for programming (writing code for) microcontrollers. It is also known as embedded software development or embedded systems programming. Essentially, embedded programming is useful in the design of software for automotive features, small facilities-handling devices like thermostats, wearable technology, handheld games or other small devices.

In a sense this topic could be seen as an extension of the electronics topic, since it focuses on the actual writing of the programs to tell the microcontroller how to do stuff with the input/output devices and with any connected network devices. Essentially, try to create as many different programmes that do as many different things in as many different ways as possible! You can do this entirely using block coding within makecode, you don’t have to use other languages or interfaces but you can if you want to try them!

Some suggested things you could do on this topic:

  • the focus could simply be on exploring the different elements of programming, including using loops, reading and writing content, data types (strings, integers, floating point, boolean etc). This could all be done in makecode, or you could look at how things differ in different languages (they are mostly the same, but there are some variations). For a holistic intro to the topic, check out the embedded programming week on the fabacademy site here.
  • you could try to consider different ways of tackling the same problem using different programming approaches – not that programming here can be more general, not necessarily interacting with input/output devices, it could just be a programme that does a calculation (e.g. work out how many days until your birthday, or work out the area of a polygon where the user inputs the side length and number of sides) or processes some data (e.g. a unit converter), or displays data in various ways.
  • you could experiment with embedded programming your microcontrollers using a variety of languages (makecode or java, python, C, etc). This site has a great breakdown of the different programming languages that can be used with the Micro:bit and with links to tutorials.
    • One example we can use is to programme the 12864 I2C OLED in micro Python and in the Arduino IDE (which uses a version of C) too in addition to using just the Makecode environment. That way we will have covered block coding, javascript, python and C!
  • you could play around with programming your microcontroller to do as many things as you can with input and output devices, and networked devices such as the OLED which uses I2C, or serial data to stream data to your computer
  • you could write your own computer games using the makecode arcade environment – it is really quite cool!
  • you could also try other programming techniques that interact with the microcontroller data (rather than be embedded on the microcontroller). For this, check out the interface and application programming week on the fabacademy site here
  • for a bit of a challenge: what about running an machine learning model (AI!) on a microbit!? here’s a tutorial that does just that using EdgeImpulse, or if you really want to push the boat out, here is a great free coursera course on building machine learning models on arduino microcontrollers (about 15 hours worth of learning)

Programming elements in makecode

Here is a link to some information about the various blocks and built in objects available in makecode. This will really help to understand what these work and how to use them in your programs. These are pretty much the same in any programming language.

blocks and objects in makecode

The above link is also a good reference page to the Basics (input, music, LEDs, radio), Advanced (games, images, pins, serial, control), and Bluetooth (bluetooth and devices). There really is some excellent stuff in there, this shows what can be done with the tools in these block areas. It is worth spending some time to explore these, and play!

makecode basics

makecode advanced options

make code bluetooth

Makecode Arcade

For a real bit of fun, you can also use the Makecode Block coding environment to make games! this is called Makecode Arcade, and is an online simulator to make games. Here is the makecode arcade environmentwhere you can write your own computer games! there are also some microbit consoles that you can buy to programme them with this code (they are basically microbits with a screen built in – my daughter has one called a kittenbot, but there are loads of new products like this out there now).

makecode arcade game example

Using Arduino IDE to programme Microbit

This can be a useful thing to do, in particular if extensions aren’t available for particular boards, or if the block programming is limiting your abilities – programming in the Arduino IDE can provide some more advanced capabilities. To do this, goto:

TOOLS MENU > MANAGE LIBRARIES

Then search for “microbit”

Select the “Adafruit microbit library” and “Install” then “install all” (with dependencies if you can).

adafruit microbit library in arduino IDE

From there, goto:

FILES > EXAMPLES > ADAFRUIT MICROBIT LIBRARY

and you will see a range of examples relating to:

  • using the button
  • blinking the LEDs and displaying the matrix of LEDs
  • sending accelerometer data to the serial port
  • using bluetooth low energy (BLE) – although this may only be useful with other boards attached

Note that try the simple ones first – there can sometimes be issues with libraries – don’t get too bogged down with this if things don’t work.

These examples are nice in that they give all the framework for interacting with the input devices (e.g. button, accelerometer, temperature sensor) and output devices (e.g. LEDs). You can then use the general examples that cover a vast amount of typical uses (e.g. input, output, serial, etc), these are of course found in:

FILES > EXAMPLES > 01.BASICS, 02.DIGITAL…etc

Why use micropython?

it allows for using added modules to add extra functionality to the microbit that isn’t possible through the standard makecode environment. Essentially you can bring in the use of python modules as you would in a normal python programme.

There are lots of examples of simple programs that can be used in the online micro python editor available here. These are essentially snippets code that relate to all the input/output devices and these can be edited and added together to make more sophisticated programs.

A nice simple example is using Python in Makecode to put text on the OLED screen and here is a tutorial developed by a previous student, Kyle. This is a nice example because there is a block equivalent, and you can simply move between the block & python environments in makecode to see how they compare….block coding seems a bit easier I think!

text python microbit

Kyle has also produced another tutorial showing how to display an image on the OLED by programming the microbit using micropython.

kyle logo python microbit2

Another great project example is this one, where the author makes a ‘frogger’ style game using the OLED screen, programming the microbit with micropython.

micropython interface

Here are some further resources:

General:

Electronics and hardware interface:

APIs, web and software

Engineering

Print Friendly, PDF & Email
Skip to toolbar