SmallBASIC on Teensy MCU

SmallBASIC was ported to the Teensy 4.0 and 4.1. Have fun using SB on this fast and easy to use microcontroller. For details see our Teensy guide.

What is the size of the Tx and Rx buffers for serial Comms? Is there a road-map for this development (features, capabilities, etc)? I’m gonna have to get one :+1::grin:

I don’t have a real roadmap, but I would like to implement the following features (in this order, somehow)

  1. LittleFS for storing the SmallBASIC program and data in flash memory. Run the stored SB program at Teensy startup
  2. Accessing SD card from your SB program
  3. SPI → many displays
  4. OneWire → i.e. Dallas temperature sensor DS18B20
  5. Examples for more I2C devices

Here are some information about Rx and Tx buffer:

If you have other ideas what to implement, let us know.

1 Like

64 bytes/port is good for me.

Presumably, changing the PWM resolution is already planned?

There is a library; HardwareQuadratureDecoder which handles multiple high speed encoders without CPU overhead. I don’t suppose it would be a simple matter of creating a wrapper?

I see that the 4.1 can handle ethernet. Any plans for this?

Will there be a hardware (deterministic) timer interrupt?

This is gonna be awesome :+1: :smiling_face_with_sunglasses:

  1. PWM and changing PWM resolution is already implemented: SmallBASIC | teensy
  2. I can implement: Encoder Library, for Measuring Quadarature Encoded Position or Rotation Signals
  3. No plans for Ethernet yet.
1 Like

Oh fantastic, can we also include:

We will have the basis of a full blown CNC that uses servo motors as opposed to steppers :+1::smiling_face_with_sunglasses::+1:

The 1ms minimum loop time is OK but if we could get shorter than that, we will be with the big boys :grin:

Oh wait. That isn’t the high speed library, it uses interrupts.

This is the one that I was referring to:

#include <HardwareQuadratureDecoder.h>

HardwareQuadratureDecoder encoder1;
HardwareQuadratureDecoder encoder2;

void setup() {
Serial.begin(115200);

// Initialize two encoders on different pins
encoder1.begin(2, 3);  // Encoder 1 A and B pins
encoder2.begin(4, 5);  // Encoder 2 A and B pins

}

void loop() {
int32_t count1 = encoder1.getCount();
int32_t count2 = encoder2.getCount();

Serial.print("Encoder 1 Count: ");
Serial.println(count1);

Serial.print("Encoder 2 Count: ");
Serial.println(count2);

// Additional logic...

}

It even supports Index and trigger signals…. Perfect :grin:

:+1::smiling_face_with_sunglasses:

Interactive mode: Meaning that it’s possible to do things like interrogate and/or change the value of a variable during program execution? :man_dancing::partying_face:

oh, maybe the name is misleading. Interactive modes means, that you can upload a new program via serial whenever you want. SmallBASIC will detect the upload, stop the current program and start the newly uploaded one.

Any updates to come, maybe SPI support?

no updates so far. Currently I’m working on the improved console version of SmallBASIC. Linux is running quite nice now. I started to get also Windows working. After finishing this I will get back to Teensy. Most probably I will start with SPI and storing several programs in Flash memory.

1 Like

Sounds great. I haven’t pulled the trigger on buying a Teensy until I am sure that I can make use of it but I wonder if you could give me a couple of benchmarks?

Floating point

dim x as single
x=1000000
while x>1
  x=x/1.0001
  i=i+1  ' -- count iterations -- about 138K
loop

Integer

i=1000000
while i
  i=i-1
loop

Don’t go out of your way, only if it is convenient :+1: :smiling_face_with_sunglasses:

Here are the benchmarks you asked for. I additionally added a pin toggle benchmark.
What kind of MCU/BASIC you are using? Do you have benchmark results for comparison?

x = 1000000
a = ticks()

while x > 1
  x=x / 1.0001
  i=i+1  ' -- count iterations -- about 138K
wend

b = ticks()
print "Time: "; b - a; "ms Loops: "; i

Time: 443ms Loops: 138163

x = 1000000
a = ticks()

while x
  x = x - 1
wend

b = ticks()
print "Time: "; b - a; "ms"

Time: 1628ms

OUT = teensy.OPENDIGITALOUTPUT(13)
state = 0

a = ticks()

for x = 1 to 1000000
  OUT.WRITE(state)
  state = !state
next

b = ticks()
print "Time: "; b - a; "-> "; round(1000000/(b-a)); "kHz"

Time: 3294ms → 303kHz

1 Like

I am currently evaluating the very new ARMbasic on the Pico 2 (RP2350 @150MHz150MHz)

Time for float BM: 45ms

Time for integer BM: 80ms

I/O toggle:

main:

  Output(PICO2_LED)  ' sets pin direction

  a=timer
  while X<1000000
    x=x+1
	Out(PICO2_LED) = x and 1    'sets pin state
  loop
  b=timer
  ms_time = (b-a)/1000          'timer is microseconds
  print "Time: "; ms_time; "-> "; 1000000/ms_time; "kHz"

end

Time: 270-> 3703kHz

Coridium ARMbasic (BUT THIS IS A COMPILER :grin: )

However, I was more interested in a comparison with what I actually use which is MMBasic on the “PicoMite” (RP2350). I am overclocked to 378MHz:

Float BM: 805ms (your Teensy: 443ms)

Integer BM: 3191ms (your Teensy: 1628ms)

Output toggle BM: 6203ms (your Teensy: 3294ms)

Many thanks. Teensy is exciting :+1: :smiling_face_with_sunglasses: