Run BASIC on a BBC micro:bit

It was recently BASIC’s 57th birthday, the programming language many of us first used to do any computer programming on computers from the 1970s and 1980s like the Commodore PET, Sinclair ZX Spectrum or Apple 2. Worth remembering too that part of the team that created BASIC was Sister Mary Kenneth Keller, the first woman and one of the first people in the US to get a PhD in computer science.

I’d known for a while that there was a Japanese port of TinyBASIC for the BBC micro:bit. To be honest I thought it was a bit of a novelty as you need a computer to connect to it that will be more powerful than the micro:bit and able itself to run proper BASIC, but it’s actually very, very clever. It will allow you to access features of the micro:bit itself, like the LED display, the buttons, GPIO pins and so on, meaning you can do real physical computing with the micro:bit in BASIC. You don’t need any special hardware, just a micro:bit and some sort of serial terminal on a computer connected to the micro:bit by USB.

To get it running go to https://github.com/Tamakichi/ttbasic_microbit – I used Google translate to help me navigate the page. Download the ZIP file and unpack the hex file and flash it to a V1 micro:bit. (It looks like it’s not yet been updated to work on the newer micro:bit with sound).

You can use terminal software to communicate with it, but it’s simpler to use Chrome and a web-based alternative. You can use the online micro:bit Python editor, but this is probably better as it handles scrolling well: https://googlechromelabs.github.io/serial-terminal/. The video at the top of this page shows how to set it up.

A very cool feature is that you can save files to flash memory, just as you’d save programs to cassette or disk on an 8-bit computer like the ZX Spectrum. There are 16 slots for programs, accessed with the SAVE and LOAD commands. FILES lists everything in the file system.

The program in slot 0 can be made to run automatically at start up – press button B at reset or, if on batteries, Press and hold Button A and Button B for 5 seconds, then release only Button A

You can play music out of piezo speaker attached to pin 8. It also supports NeoPixel 8×8 matrix displays, for example for displaying Japanese characters.

It also has a real time clock, though it’ll lose its time when you power off. Use
SETDATE Year, month, day, hour, minute, second
eg
SETDATE 2021,5,3,12,0,0

There’s a lot more you can do with TinyBASIC on the micro:bit. There’s a comprehensive PDF manual in Japanese which you can translate using Google Translate to discover more.

Here are some sample programs featured in the video:

Blinking LED

1 'blink
5 MATRIX OFF
10 GPIO 3,OUTPUT
20 OUT 3,LOW
30 GPIO 26,OUTPUT
35 "@loop"
40 OUT 26,HIGH
50 WAIT 300
60 OUT 26,LOW
70 WAIT 300
80 GOTO "@loop"

Button input

10 CLS
20 IF !IN(BTNA) ?"Button A"
30 IF !IN(BTNB) ?"Button B"
40 WAIT 200
50 GOTO 20

Fill all the LEDs

10 CLS 1
20 D=1
30 FOR Y=0 TO 4
40 FOR X=0 TO 4
50 PSET X,Y,D
60 WAIT 100
70 NEXT X
80 NEXT Y
90 IF D D=0 ELSE D=1
100 GOTO 30

LED matrix message display

10 CLS 1
20 MSG LEFT,200,"Hello world! "
30 FOR I=O TO 30
40 MSG DOWN,50,I/10
50 WAIT 50
60 MSG LEFT,100,I%10
70 NEXT I
80 WAIT 500
90 GOTO 20
This entry was posted in computers and tagged , , . Bookmark the permalink.

2 Responses to Run BASIC on a BBC micro:bit

  1. Keith says:

    This looks extremely interesting!

    I learned BASIC on the ZX81, ZX Spectrum, and BBC Micro many years ago as a teenager. I bought a FUZE BASIC Micro to help my son with programming, as neither of us are very adept with Arduino programming, nor Python. But we have managed a lot of Animatronic control using FUZE BASIC. Although my son appears to have really mastered Makecode Block programming of IO Control on the BBC Micro:bit.

    So I am going to “borrow” one of his many Micro:bits to try some good old BASIC programing. Looks like I have a lot of Google Translating to do, unless you have plans to share your English Notes? But to be able to control iO on a BBC Micro:bit using BASIC sounds brilliant!

    Does the Micro:bit BASIC make any use of the Micro:bit’s Radio and Bluetooth functions? We are currently working on “automating” some of our garden lights and Water Feature using Micro:bits. These will be governed by the Hub Micro:bit which (currently) has an LCD and RTC attached. The Remote Micro:bits have “local” control functions but rely on comms to and from each other over the Micro:bit Radio function all based on ideas from https://github.com/jimbobbennett/smart-garden-ornaments

    I am also going to have to see if I kept a PS/2 Mouse in the loft, as your Micro:bit Keyboard is something else for us to try out too.

    Many thanks for your blog

    Kind regards

    Keith

    • blogmywiki says:

      Hi Keith – sorry for the delay responding, I was on holiday. Sounds like you have lots of great ideas for projects! I do think Python – or MakeCode – would be the best way to go to, not least because there’s a lot of support online in general and from microbit.org in particular. I’ve not explored the Japanese BASIC port any more, so not sure if it supports radio. I know Ichigon Quest does have a weird radio mode, but I very much doubt Bluetooth would be supported in BASIC. MakeCode’s advanced blocks allow you to do some lower level stuff and I can really recommend it if Python isn’t appealing.
      best wishes
      Giles

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>