Getting Started with Basic Programming on microbit

This year marks the 57th anniversary of the Basic programming language. For many, their first experience with programming was in the 1970s to 1980s using Basic on Commodore PET, Sinclair ZX Spectrum, or Apple 2. Notably, Sister Mary Kenneth Keller, a member of the team that created the BASIC language, was the first woman in the United States to earn a Ph.D. in computer science and one of the first people to earn a Ph.D. in computer science.

On the microbit, in addition to using micropython and makecode for programming, we can also program using the Basic language. By using Tiny Basic for microbit, we can experience programming on the microbit as if we were using an APPLE II computer.

Note:

  • Tiny Basic for microbit is a port of TOYOSHIKI Tiny BASIC for Arduino. The original website is at https://github.com/vintagechips/ttbasic_arduino.

Getting Started with Basic Programming on microbit

First, we need to download the Tiny Basic for microbit firmware (please check the link in Read More below). After extracting the zip file, copy the ttbasic_microbit.ino.hex file to the microbit. Note that you need to use the V1 hardware version of the microbit (the main MCU is nRF51822, and there is no notch on the bottom gold finger) because the software currently does not support the V2 hardware version of the microbit.

Then open a terminal software (such as putty, mobaxterm, terminal-s, Thonny, etc.), with the same settings as micropython:

  • Baud rate 115200

  • Data bits 8

  • Stop bits 1

  • Parity None

  • Flow control None

After connecting, press the reset button on the microbit. If you see the prompt below, it means the Basic system is up and running. Otherwise, you need to re-download the firmware or check the parameter settings.

Getting Started with Basic Programming on microbit

You can directly input Basic programs in the terminal, for example:

Getting Started with Basic Programming on microbit

If you have never used Basic or have forgotten the syntax, don’t worry. Compared to modern programming languages, Basic is very simple, with few keywords. Just look at the examples to understand the basic usage.

Some commonly used commands:

  • After entering the code, you need to enter the RUN command to run the program.

  • Use the LIST command to view the program.

  • If you enter an error, you can modify a specific line by entering the line number.

  • To stop running, press the ctrl-c key combination or press the Esc key twice.

  • The CLS command clears the screen display.

  • The NEW command starts a new program.

Programs can also be entered by copying and pasting, but the system limits the buffer size to 80 characters at a time. If the program is longer, you need to copy and paste in multiple batches.

Here are a few examples of operating the microbit.

LED Pixel Blinking

1 'blink5 MATRIX OFF10 GPIO 3,OUTPUT20 OUT 3,LOW30 GPIO 26,OUTPUT35 "@loop"40 OUT 26,HIGH50 WAIT 30060 OUT 26,LOW70 WAIT 30080 GOTO "@loop"

Read Button Input Status

10 CLS20 IF !IN(BTNA) ?"Button A"30 IF !IN(BTNB) ?"Button B"40 WAIT 20050 GOTO 20

Fill LED Pixels Sequentially

10 CLS 120 D=130 FOR Y=0 TO 440 FOR X=0 TO 450 PSET X,Y,D60 WAIT 10070 NEXT X80 NEXT Y90 IF D D=0 ELSE D=1100 GOTO 30

Display Scrolling Text

10 CLS 120 MSG LEFT,200,"Hello world! "30 FOR I=0 TO 3040 MSG DOWN,50,I/1050 WAIT 5060 MSG LEFT,100,I%1070 NEXT I80 WAIT 50090 GOTO 20

More commands:

WAIT n:Wait time (microseconds)LOCATE:Move cursorCOLOR:Specify text colorACCEL x,y,z:Get accelerometer valuesPSET x,y,c:Draw pointLINE x1,y1,x2,y2,c:Draw lineRECT x1,y1,w,h,c,mode:Draw rectangleCIRCLE x,y,r,c,mode:Draw circleMSG direction,speed,"string": Display text messageGSCROLL x1,y1,x2,y2,direction:ScrollGPRINT x,y,"string": Display character at specified positionBITMAP x,y,data storage address,index,h,w [,magnification]:Bitmap displayMATRIX ON| OFF:LED screen switch

In Tiny Basic, you can save up to 16 programs, each with a maximum of 4096 bytes. Here are some usages related to programs.

Save Current Program to a specified location (n ranges from 0-15)

save n

Load Program from a Specified Location (n ranges from 0-15)

load n

View Saved Program List

files0:PRINT "hello"1:FOR I=1 TO 102:'demo13:(none)4:(none)5:(none)6:(none)7:(none)8:(none)9:(none)10:(none)11:(none)12:(none)13:(none)14:(none)15:(none)OK

If you hold down the B key on the microbit and press the reset button, it will automatically run the first saved program.

Tiny Basic also supports 4×4 matrix keyboards, displaying custom icons, Neopixel RGB lights, and matrices. For more usages, please click Read More to see.

Leave a Comment

×