I’ve been exploring writing a very, very simple text-based language for the micro:bit, in Python. I think it could be an educational project in two ways:
- A task for older students to design and create their own language.
- Make a text-based language for younger students that’s simpler than Python, simpler even than BASIC or TinyBASIC.
I made a few rules for myself, the main one being that no quotation marks will be used. This poses a few challenges, but I wanted users to be able to code it using just words and numbers and maybe a few operators like =, +, -, <, >
It should also be so relaxed about variable types it makes even Python look uptight.
This is still very much a work in progress, but I think it’s got potential. Its main differences from BASIC are:
- Commands you enter aren’t executed, they get added to the program listing
- Line numbers are assigned automatically and run from 0 in steps of 1
- You can delete and amend lines but you can’t, currently, insert lines. I should probably fix this.
Here’s how it works.
You’ll need a BBC micro:bit and a computer. You type your program on the computer in a serial console (which can just be a web page), and the micro:bit will output to the console, its LED display and sound on pin 0 (or the built-in speaker if you have a V2 micro:bit).
Flash the Python program file to a BBC micro:bit and connect a serial console to it. You can use the Chrome browser and either the micro:bit Python editor or an online console like the Chromelabs one. If you use the Python editor, click ‘Connect’ and then ‘Open serial.’
You should now be in ‘Mi:Little Coder’, or ‘smolBASIC’ as I’m now calling it, because it’s smaller than TinyBASIC.
If you enter
you should see three icons display on the micro:bit.
Type list and you’ll see your program listed:
If you want to get rid of the ghost, type del 2 to delete that line.
You can replace lines by typing a new instruction starting with the line number:
You can scroll words on the display. Type ‘scroll hello world’ and list your program again:
2 scroll hello world
Start a fresh program by typing new
You can play notes and tunes with
You can save and load your program with save and load. You can only save one program at a time, but it’s stored in non-volatile memory, so if you unplug the micro:bit, then plug it back in you can type load to get your last program back. I think this is pretty neat.
I’m not sure this language is ‘Turing complete’ but it must be close: it also has the ability for the user to enter data, store it in variables, test it and branch according to the results.
Here’s a program that asks how old you are and gives different responses in the console:
0 print enter your age
1 input a
3 if a>b goto 6
4 print you are too young to vote
6 print you can vote
Have a play with it, and see what you think. It was created on a whim, I know my Python code is terrible, it can be made more compact and should probably work more like BASIC to run commands whether run from a listing or typed direct. Or should it? What do you think?
I’ll also be doing some more reading about the roots of Tiny BASIC – I’ve been enjoying reading ancient copies of the People’s Computer Company from 1975, it’s fascinating to see the concerns and ideas of some of the pioneers of home computing, including those who wanted to create a simple, text-based language that fitted in very little memory on cheap systems and that was given away for free… unlike Microsoft BASIC, you didn’t have to steal or buy Tiny BASIC, it was ‘copy left’ and free.