Running Tiny Basic on the Micro: Bit

I was looking for some things to use in teaching my kids some programming with the BBC Micro: Bit and came across Tiny Basic on the Micro: Bit.  The implementation of Tiny Basic is a cross between Arduino Tiny Basic and Palo Alto Tiny Basic.  It’s very comprehensive and includes things like LED control, sensor reading, and serial communication via USB.  This is a great way to introduce kids and adults alike to the wonderful world of programming, hardware and the Micro: Bit. 

Full source is available, unfortunately, the GITHUB is in Japanese.  HOWEVER, you can use Google or Bing translate to translate the page for you. 

I have taken the liberty of bringing some of the information to you.  I had a bit of an issue making it work, so, here’s what I found so you don’t have to worry about it.

WHERE TO DOWNLOAD

You can, of course, download the full source and associated libraries and compile it yourself and then import into the Micro: Bit.

BUT….

All you really need is the compiled HEX file.  To get that…

  1. Download
    https://github.com/Tamakichi/ttbasic_microbit/archive/master.zip

  2. Connect the  micro:bit.
    You should see the Micro:bit drive “MicroBIT”
    Unzip the download file ttbasic_microbit-master.zip.
    From the bin folder, copy the file  ttbasic_microbit.ino.hex to the micro:bit (you can drag and drop it into the Micro: Bit folder.

  3. When the program write is finished, connect the serial with terminal software (TeraTerm, for example) etc.

  4. Set up your terminal software as follows:

    Terminal communication conditions Communication speed 115200bbs, parity none, stop bit 1, flow control: No; set the transmission delay to 1 ms/character.

Once you have downloaded the hex file to the micro: bit and setting up and connecting to your favorite terminal app, you should reset the micro: bit and see something like:

tinybasicformicrobitThe dialect of Tiny Basic is similar to Half-Byte Tiny Basic, but, it has far more capability.  With more memory to work with, no graphics and Micro: Bit hardware, there are a bunch of things you can do.

The following is copied directly from the web site.

Available keys

  • Cursor Move Cursor Key
  • Delete, CTRL-X: Delete characters at cursor position
  • BackSpace: Delete characters before cursor and move forward
  • PageUP, PageDown, ctrl-r: Refresh the screen
  • HOME, END: Move cursor to left or right edge in row
  • INS: Toggle toggle switching for insert sand
  • Enter: Line entry confirmed
  • Press ESC twice, ctrl-c: suspend execution program
  • CTRL-L, F1: Clear Screen
  • CTRL-R, F5: Screen Refresh

Pin-assigning and pin-specifying

  • Pin: Specified by PN0 through PN32, or 0 through 32
  • Pin mode specification command :GPIO pin , OUTPUT | INPUT_PU INPUT_PD INPUT_FL”
  • Digital Output:OUT Pin, HIGH| LOW|0|1
  • Digital input: variable =IN(pin)
  • Analog input: variable =ANA(pin)

Sample Program

Colored text on the screen

10 FOR I=0 TO 10
20 FOR J=0 TO 10
30 COLOR RND(8): ? "*";
35 WAIT 100
40 NEXT J
50 ?
60 NEXT I

Flashing LEDs on board


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"

Analog value display

10 CLS
20 A=ANA(PN0)
30 LOCATE 5,5:?A;"    "
40 GOTO 20
Button input determination
10 CLS
20 IF !IN(BTNA) ?"Button A"
30 IF !IN(BTNB) ?"Button B"
40 WAIT 200
50 GOTO 20
LED Matrix Dot Display
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"
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
Assign ed.m. character A to display
10 POKE FNT+ASC("A")*5+0,`00000000
20 POKE FNT+ASC("A")*5+1,`01010000
30 POKE FNT+ASC("A")*5+2,`00000000
40 POKE FNT+ASC("A")*5+3,`10001000
50 POKE FNT+ASC("A")*5+4,`01110000
60 MSG TOP,0,"A"
ASSIGN A FONT TO LED MATRIX CHARACTER A AND DISPLAY (2)
10 SETFONT ASC("A"),$00,$50,$00,$88,$70
MSG TOP,0,"A"
Neopixel Blue Trajectory Rotation
10 'Neopixel(1)
20 NPBEGIN 0,16
30 NPCLS
40 FOR I=0 TO 7
50 NPRGB I,0,0,(2<<I)-1
60 NEXT I
70 NPSHIFT 1
80 WAIT 50
90 GOTO 70
4x4Keypad input key determination (simple chattering measures available)
10 'Keypad 4x4
20 G0=-1
30 @(10)=1013,920,840,780,670,630,590,560,502,477,455,435,400,320,267,228
40 G0=G
50 G=GRADE(ANA(1),10,16)
60 IF G<>G0 WAIT 1 GOTO 40
70 IF G>=0 ?"KEY=[";G+1;"]"
80 GOTO 40
Time display (display the time when you press A button)
1 'トケイ
10 MATRIX ON
20 SETDATE 2018,1,16,12,0,0
30 IF !IN(BTNA) GOSUB "@ShowTime"
40 WAIT 200
50 GOTO 30
60 "@ShowTime"
70 GETTIME T1,T2,T3
80 MSG LEFT,80,#-2,T1;":";T2;":";T3;" "
90 RETURN
(new!) Browsing Misaki Font Data
1 '美咲フォントの利用
10 S="あ"
20 A=WADR(WASC(S))
30 FOR Y=0 TO 7
40 D=PEEK(A+Y)
50 FOR X=0 TO 7
60 IF D&($80>>X) ?"■"; ELSE ?"  ";
70 NEXT X
80 ?
90 NEXT Y
(new!) Character display with NeoPixcel (8×8 matrix type)
10 'NeoPixelで文字表示
20 SETFONT 0,$50,$A8,$88,$88,$70
30 MSG TOP,0,CHR$(0)
40 NPBEGIN 12,64
50 NPCLS
60 S="こんにちは☆さい玉":C0=RGB8(0,2,3)
70 FOR I=1 TO WLEN(S)
80 A=WADR(WASC(S,I))
90 FOR Y=0 TO 7
100 D=PEEK(A+Y)
110 FOR X=0 TO 7
120 IF D&($80>>X) C=C0 ELSE C=0
130 IF Y&1 POKE MEM+Y*8+X,C ELSE POKE MEM+Y*8+7-X,C
140 NEXT X
150 NEXT Y
160 NPPUT 0,MEM,64,1
170 WAIT 400
180 NEXT I
190 GOTO 70
(new!) LED Matrix Font Creation Tool (Created by Mr. Goeda)
1 'PCG EDIT
5 ATTR 0:COLOR 7
10 CLS:CLS 1:CLV:LET @(20)=79,42
20 FOR I=0 TO 4:FOR J=0 TO 4
30 LOCATE I,J:?CHR$(@(20));:NEXT J:NEXT I:GOSUB 500
40 K=INKEY()
50 X=X+(K=KRIGHT)*(X<4)-(K=KLEFT)*(X>0)
60 Y=Y+(K=KDOWN)*(Y<4)-(K=KUP)*(Y>0)
70 LOCATE X,Y:C=VPEEK(X,Y)
75 ATTR 2:?CHR$(C):LOCATE X,Y:WAIT 100:ATTR 0:?CHR$(C):LOCATE X,Y
80 IF K=32:IF C=@(20) P=@(21) ELSE IF C=@(21) P=@(20)
90 IF K<>32 GOTO 40
100 ?CHR$(P);
110 FOR I=0 TO 4:D=0
120 FOR J=0 TO 4:C=VPEEK(J,I)
130 IF C=@(21) D=D+(1<<(7-J))
140 NEXT J:@(I)=D
150 NEXT I
160 GOSUB 500:GOTO 40
500 LOCATE 0,10:?"SETFONT ASC(";CHR$(34,90,34,41);
510 FOR I=0 TO 4:?",$";HEX$(@(I),2);:NEXT I
520 SETFONT ASC("Z"),@(0),@(1),@(2),@(3),@(4)
530 MSG TOP,0,"Z"
540 RETURN

From then on is the original document

TOYOSHIKI Tiny BASIC for Arduino

The code tested in Arduino Uno R3. Use UART terminal, or temporarily use Arduino IDE serial monitor.

Operation example

> list 10 FOR I=2 TO -2 STEP -1; GOSUB 100; NEXT I 20 STOP 100 REM Subroutine 110 PRINT ABS(I); RETURN

OK >run 2 1 0 1 2

OK >

The grammar is the same as PALO ALTO TinyBASIC by Li-Chen Wang Except 3 point to show below.

(1) The contracted form of the description is invalid.

(2) Force abort key PALO ALTO TinyBASIC -> [Ctrl]+[C] TOYOSHIKI TinyBASIC -> [ESC] NOTE: Probably, there is no input means in serial monitor.

(3) Other some beyond my expectations.

(C)2012 Tetsuya Suzuki GNU General Public License

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s