Home

Awesome

UBASIC PLUS

uBasicPlus is an extension of the uBasic by Adam Dunkels (2006), https://github.com/adamdunkels/ubasic, which includes the strings and their functions from 'uBasic with strings' by David Mitchell (2008), http://www.zenoshrdlu.com/kapstuff/zsubasic.html, and some constructs and interpreter logic from 'CHDK', http://chdk.wikia.com/wiki/CHDK_Scripting_Cross_Reference_Page.

uBasic-Plus Interpreter Features

Software and Flow Control

Hardware Control

uBasic-Plus Command Line Interface

The Command Line Interface (CLI) supports the following commands:

The uBasic-Plus comprise of six files config.h, fixedptc.h, tokenizer.c, tokenizer.h, ubasic.c and ubasic.h. As an example implementation of the hardware related functions (random number generation, gpio, hardware events, sleep and tic/toc) the development boards STM32F030-Nucleo64 and STM32F051-Discovery are used in combination with CubeMX created system libraries.

UBASIC PLUS SCRIPT DEMOS

Demo 1 - warm up

println 'Demo 1 - Warm-up'
gosub l1
for i = 1 to 2
  for j = 1 to 2
    println 'i,j=',i,j
  next j
next i
println 'Demo 1 Completed'
end
  :l1
println 'subroutine'
return

Demo 2 - 'uBasic with strings' by David Mitchell

println 'Demo 2'
a$= 'abcdefghi'
b$='123456789'
println 'Length of a$=', len(a$)
println 'Length of b$=', len(b$)
if len(a$) = len(b$) then println 'same length'
if a$ = b$ then println 'same string'
c$=left$(a$+ b$,12)
println c$
c$=right$(a$+b$, 12)
println c$
c$=mid$(a$+b$, 8,8)
println c$
c$=str$(13+42)
println c$
println len(c$)
println len('this' + 'that')
c$ = chr$(34)
println 'c$=' c$
j = asc(c$)
println 'j=' j
println val('12345')
i=instr(3, '123456789', '67')
println 'position of 67 in 123456789 is', i
println mid$(a$,2,2)+'xyx'
println 'Demo 2 Completed'
end

Demo 3 - uBasic-Plus is here

println 'Demo 3 - Plus'
tic(1)
for i = 1 to 2
  j = i + 0.25 + 1/2
  println 'j=' j
  k = sqrt(2*j) + ln(4*i) + cos(i+j) + sin(j)
  println 'k=' k
next i
:repeat
  if toc(1)<=300 then goto repeat
for i = 1 to 2
println 'ran(' i ')=' ran
next i
for i = 1 to 2
println 'uniform(' i ')=' uniform
next i
for i = 1 to 2
x = 10 * uniform
println 'x=' x
println 'floor(x)=' floor(x)
println 'ceil(x)=' ceil(x)
println 'round(x)=' round(x)
println 'x^3=' pow(x,3)
next i
println 'Digital Write Test'
pinmode(0xc0,-1,0)
pinmode(0xc1,-1,0)
pinmode(0xc2,-1,0)
pinmode(0xc3,-1,0)
for j = 0 to 2
  dwrite(0xc0,(j % 2))
  dwrite(0xc1,(j % 2))
  dwrite(0xc2,(j % 2))
  dwrite(0xc3,(j % 2))
  sleep(0.5)
next j
println 'Press the Blue Button or type kill!'
:presswait
  if flag(1)=0 then goto presswait
tic(1)
println 'Blue Button pressed!'
:deprwait
  if flag(2)=0 then goto deprwait
println 'duration =' toc(1)
println 'Blue Button de-pressed!'
println 'Demo 3 Completed'
end

Demo 4 - input array entries in 10 sec time (use Arduino IDE Serial Terminal not Minicom)

println 'Demo 4 - Input with timeouts'
dim a@(5)
for i = 1 to 5
  print '?'
  input a@(i),10000
next i
println 'end of input'
for i = 1 to 5
  println 'a(' i ') = ' a@(i)
next i
println 'Demo 4 Completed'
end

Demo 5 - analog read with arrays

println 'Demo 5 - analog inputs and arrays';
for i = 1 to 100;
  x = aread(16);
  y = aread(17);
  println 'VREF,TEMP=', x, y;
next i;
for i = 1 to 1;
  n = floor(10 * uniform) + 2 ;
  dim b@(n);
  for j = 1 to n;
    b@(j) = ran;
    println 'b@(' j ')=' b@(j);
  next j;
next i;
println 'Demo 5 Completed';
end;

Demo 6 - if/then/else/endif and while/endwhile

println 'Demo 6: Multiline if, while'
println 'Test If: 1'
for i=1 to 10 step 0.125
  x = uniform
  if (x>=0.5) then
    println x, 'is greater then 0.5'
  else
    println x, 'is smaller then 0.5'
  endif
  println 'i=' i
next i
println 'End of If-test 1'
println 'Test While: 1'
i=10
while ((i>=0)&&(uniform<=0.9))
  i = i - 0.125
  println 'i =', i
endwhile
println 'End of While-test 1'
println 'Demo 6 Completed'
end

Demo 7 - kill test

println 'Demo 7: Analog Read or Kill'
y=0
:startover
  x = aread(10)
  if (abs(x-y)>20) then
    y = x
    println 'x=',x
  endif
  sleep (0.2)
  goto startover
end

Demo 8 - PWM Test

println 'Demo 8: analog write (PWM) 4-Channel Test'
p = 65536
for k = 1 to 10
  p = p/2
  awrite_conf(p,4096)
  println 'prescaler = ' p
  for i = 1 to 10
    for j = 1 to 4
      awrite(j,4095*uniform)
    next j
    println '    analog write = ' awrite(1),awrite(2),awrite(3),awrite(4)
    sleep(5)
  next i
next k
awrite(1,0)
awrite(2,0)
awrite(3,0)
awrite(4,0)
end

Demo 9 - Store/recall in FLASH Test

clear
println 'Demo 9: store/recall with FLASH'
if (recall(x)==0) then
  println 'generating x'
  x = uniform
  store(x)
endif
println 'stored: x=' x
if (recall(y@)==0) then
  println 'generating y'
  dim y@(10)
  for i=1 to 10
    y@(i) = uniform
  next i
  store(y@)
endif
println 'stored: y@'
for i=1 to 10
  println '  y@('i')=' y@(i)
next i
if (recall(s$)==0) then
  println 'generating s'
  s$='what is going on?'
  store(s$)
endif
println 'stored: s$',s$
println 'Demo 9 Completed'
println 'Please run it once more'
end

UBASIC PLUS HARDWARE SUPPORT

STM32F030R8-Nucleo64

About the board:

STM32F051R8-Discovery

About the board:

Firmware footprint with all features enabled and 8 demo scripts (bytes): 37872 flash, 548 data and 3940 bss.