-
Notifications
You must be signed in to change notification settings - Fork 32
Hardware Platforms
The BASIC code is in basic.c with basic.h being the header file for most of the interpreter variables. It was intended from the start to be multi platform. Hardware dependent functions are mostly (but not completely) in hardware-arduino.h. As the different target platforms have different cores and different libraries, precautions are needed. An SD file system library on Arduino 8bit and ESP8266 is different in some aspects. The hardware layer of the interpreter deals with these differences. This part of the code is complex with a lot of heuristics in it. Currently 16 different cores are supported.
Main platforms are
- Mac
- Arduino AVR
- Arduino 32 bit SAM(D) and Mbed
- Arduino R4 with NRENESA chipset
- ESP8266
- ESP32
Platforms I occasionally use and test against are
- Mighty core AVR
- Mega core AVR
- ESP32 VGA Fablib systems
Platforms that work but that I test only in major release
- Linux
- Windows
- DOS
- Seeed Studio Mbed
- Raspberry PI Pico
- XMC1100
- STM32F4
Most genuine Arduino board and their clones are supported. I admire the solid work the Arduino engineers have done to build and integrate these boards with the software.
Diecimila 168 (EEPROM): 512 byte of BASIC memory. Runs a real tiny BASIC.
The first Arduino board I owned. It has only 1kB of RAM and 512 bytes of EEPROM. It is my test board for real frugal code. Picoserial is used to safe buffer space. This code in integrated in BASIC right now and no addition library is needed.
Uno with 328P (EEPROM and LCD Shield), Nano
Systems with roughly 1KB of BASIC memory and EEPROM as program storage. Floating point support fits into the flash.
For the LCD shield the standard Arduino Liquidcrystal library is used. (https://www.arduino.cc/en/Reference/LiquidCrystal). See the projects page (https://github.com/slviajero/tinybasic/wiki/Peripherals:-Display-LCDs,-TFTs,-and-VGA) for more. The Pretzel board libraries for networking are not supported and never will be. There is much better stuff on the market for networking now.
Larduino with a LTG8F328P Chip aka WEMOS XI aka other names: These boards have no real EEPROM. They use a flash EEPROM emulation. Supported now as well, PICOSERIAL does not work on them. They have a slightly smaller flash which limits the use with peripherals. Very fast. Please use the newest cores from https://github.com/LGTMCU/Larduino_HSP for this. The boards are really fast!
All the UNO and Nano based board work really well and are fun to use with BASIC.
Nano Every
Has 4 kB of BASIC memory free and can drive a lot of peripherals.
The Every (https://docs.arduino.cc/hardware/nano-every) has received little love in the community but for running BASIC it is a great system. With its 6 kB of memory and 48 kB of flash, a lot of features can be added to the BASIC interpreter and you still have a computer with 4kB RAM. It is the ideal system for small wearables and applications.
Mega 2560 (EEPROM):
For a system with 6-7 kB BASIC memory, ideal for a standalone 8bit system.
The MEGA256 is ideal for standalone systems with a small display. It has enough program memory for the PS2 keyboard library (https://github.com/slviajero/PS2Keyboard) and the I2C Liquidcrystal libraries (https://github.com/slviajero/LiquidCrystal_I2C). Look at the project page https://github.com/slviajero/tinybasic/wiki/Projects:-How-to-use-BASIC-on-Arduinos for more.
MKR 1010 Wifi
28 kB BASIC memory, Wifi and MQTT supported. Built-in real time clock is also supported.
This board required the Arduino SAMD board extension in the board manager menu. Wifi and MQTT is fully supported just as well as sleep modes. This board is the basis of an IoT display board I build. Built-in RTC is supported for time keeping but not for alarms. This is in preparation.
For SAMD boards, the RTCZero and LowPower library has to be installed from the Arduino library manager before compiling BASIC.
Arduino DUE, 64 kb BASIC memory
The 32 bit workhorse of the Arduinos. Ideal for TFT based standalone systems. See https://github.com/slviajero/tinybasic/wiki/Projects:-How-to-use-BASIC-on-Arduinos for an example of a TFT screen. This board requires the Arduino SAM board extension from board manager.
Arduino RP2040 aka Raspberry PI Pico, generic Arduino model with 64 kb BASIC memory.
This board is ideal for a small standalone computer.
Supports LittleFS now for an internal filesystem with BASIC. Wifi and MQTT supported. No EEPROM emulation support yet but external I2C EEPROM of course fully supported.
Arduino R4 MINIMA and Wifi
The best platform for BASIC from Arduino. Fully compatible with the UNO boards and shields. There is approximately 26 kB of BASIC memory available with the full floating point BASIC installed. Great for all kind of applications.
The real time clock is supported by BASIC by default. MCUFRIED type parallel display shields are tested successfully (with my patched MCUFRIEND library). Will test more shields and applications for it in the future.
Wifi is work in progress right now.
The Chinese competition to the Arduino boards. Fast, low cost. Sometimes tricky to use but with a lot of possibilities. Endless hardware variants available. On all ESP boards SPIFFs and Wifi are fully supported. SLEEP works as well. They are ideal to build sensor devices or small standalone computers.
ESP8266 NodeMCU
These boards are very popular and only cost a few Euros. They can be mounted on breadboards or other prototype boards.
Wemos D1 R1
These boards with a UNO form factor are also really cheap and very useful. They are not really compatible with UNOs and can't be used with many shields.
Read this tutorial to see what can be done with BASIC and one of these boards: https://create.arduino.cc/projecthub/sl001/the-10-euro-iot-computer-with-esp-8266-e93681
More info on the board, in particular, the pinout https://cyaninfinite.com/getting-started-with-the-wemos-d1-esp8266-wifi-board/
ESP32 Wroom and C3
both variants of ESP32 modules are supported. In addition to this, the interpreter also runs on Espduino modules which are similar to UNOs again.
ESP01
Depending on the memory of the board and the features activated up to 64 kB of memory is possible. I tested on ESP01 in the 8266 and ESP32 variant as sensor boards.
TTGO ESP32 with VGA and PS/2
Here is the hardware spec http://www.lilygo.cn/prod_view.aspx?TypeId=50033&Id=1083 and this is the software https://github.com/slviajero/FabGL. Plain 16 color VGA including graphics with PS2 keyboard and SD card running supported. Wifi also supported.
Please use the new FABLib version with the newest ESP32 core, version 2.0.2 and above.
64kB of BASIC memory without Wifi.
With Wifi the system cannot be stably powered any more from a standard USB port. It will crash periodically through the brownout detection mechanism. Use a sufficiently powerful external power source instead. Memory management is broken. Only small BASIC memories of 8kB are currently supported with the full VGA resolution.
Seeeduino Xiao 24 kB of BASIC memory
A super cheap, super small but powerful board. Fully supported with BASIC. Projects in preparation.
https://wiki.seeedstudio.com/Seeeduino-XIAO/
The genuine Raspberry PI Pico is a great and powerful board for standalone computers.
It has a lot of memory, is fast and many I/O pins. Fully supported with BASIC with the genuine Raspberry PI Pico core.
A few of the very useful AVR controllers never made it into Arduino board. One has to build ones own board for them. A 644 is a great chip as it has 64kB flash and 4kB of RAM. Ideal for BASIC.
Low energy board can be build with it:
BASIC supports AVR644 and AVR1284 with these boards.
Bare bone board with AVR128 are ideal for BASIC. Many pins and enough memory.
Use the Mighty core (https://github.com/MCUdude/MightyCore) and Mega core (https://github.com/MCUdude/MegaCore) with these systems
A support for the XMC1100 has been added to the code. These microcontrollers are SAMD based, have 32kB or 64KB of flash. Wiring and I2C tested so far and working.
Special features of the system like the built-in RTC are not yet supported.
I build an EEPROM emulation and integrated it to BASIC. See https://github.com/slviajero/XMCEEPROMLib. (Thanks to Florian for inspiring this work and giving me the right hints.
The STM32F4VE boards with the SD card slot are ideal as a basis for BASIC computer. They are probably the fastest BASIC home computer that you can get. Speed on BASIC command execution is close to 1 Mips.
Powerful boards, see docs here https://www.st.com/en/microcontrollers-microprocessors/stm32f407ve.html#overview or here https://os.mbed.com/users/hudakz/code/STM32F407VET6_Hello/shortlog/ or here https://stm32-base.org/boards/STM32F407VET6-STM32-F4VE-V2.0
OS information in this repo https://github.com/stm32duino/Arduino_Core_STM32
BASIC supports the board now, including the EEPROM feature. It has 16 kB of buffered EEPROM emulation. Memory size 64KB by default. Bigger is possible. The SD card slot with SDIO interface is supported with the STM32SD library. Built-in real time clock is supported. The STM32RTC and STM32LowPower libraries are both needed.
A small board with Wifi and an Epaper display. Great device for digital signage. First version of code prepared but very raw. Not meant for production. Necessary font file not yet checked in. Do not activate or use at this time. Major change coming here.
Framebuffer graphics now supported and Wiring.
The hardware abstraction file hardware-arduino.h
has become as big as the BASIC interpreter itself in the meantime. It contains a number of predefined drivers for hardware components. There is (almost) no Arduino library code any more in the basic interpreter basic.c
. The hardware code includes displays, keyboards and keypads, sensors, networking, filesystems, and other peripherals.
Small text based LCD displays with and without I2C interface can be connected.
The LCD shield is supported including the keypad. The standard Arduino parallel LCD library is used for this.
LCD I2C is also supported for any display size.
SSD1306 based OLEDS are very common. The are supported using the u8g2 drivers. Almost all common monochrome displays can be connected with this and accessed through BASIC by changing the constructor lines in the code.
Larger TFT displays based on the SSD1963 are supported with full graphics.
SPI based displays like the Nokia 5110 and small ILI9488 can be used. They are really low cost and offer graphics.
For the Nokia display there is a page mode in the graphics code. It allows drawing and printing into a page buffer and then transfer the data to the display.
The SPI based ILI948x displays are very common. A project with a display like this was published in arduino.cc.
Parallel ILI9886 displays are also supported in the meantime. They are ideal with Arduino Mega256 controllers are they need a lot of pins.
Arduino I2C Real Time clocks with a DC3231, DC3232 or DC1307 are supported. If the clocks have an EEPROM they can be integrated as a small file system using the EFS library.
PS2 keyboards and the keypad of the LCD shield are supported. ZX81 keyboards can be used with my ZX81Keyboard library. USB Keyboards are supported on a DUE with a German keymap. This is experimental.
ESP Wifi, WifiNINA and Arduino Ethernet are supported as network protocols with MQTT messages.
RF2401 Radio modules are implemented, they can be used are slaves and masters.
A generic WIRE access library exists for all kind of I2C devices. Slave mode wire is implemented in BASIC 1.4.
A small number of sensors are integrated, this is active work. Currently DHT11, DHT22, AHT10, SHT3, BMP280, BME280 are supported. In addition to this the LSM6D sensor of the MKR and the MQ2 air quality sensor is integrated into the BASIC code.
EEPROMS with 4k and 32k size are autodetected on I2C. EEPROMS can be used as direct program storage and programs can run from them. SPI RAM chips are also supported as primary program storage.
MacOS X with gcc and Xcode
Raspberry PI / raspbian with gcc - Wiring implemented to support I/O pins.
Download MINGW (https://sourceforge.net/projects/mingw/) and set the MINGW macro.
Borland's Turbo C Compiler 2.01 is freely available for MSDOS (see here https://vetusware.com/download/Borland%20Turbo%20C%202.01/?id=168 or here - megapack - https://archive.org/details/msdos_borland_turbo_c_2.01). Use the program dosify in my repo to remove C++ style comments and add the obligatory CR characters at the end of each line. basic.c compiles nicely in DOSBOX including the file IO code. Catalog doesn't work as I didn't take the time to dive into MSDOS header files.
A LCD shield / UNO based standalone computer.
Further infos on this project: https://create.arduino.cc/projecthub/sl001/basic-on-arduinos-5b4e24
A standalone computer with a 4x20 display and a thermo printer based on a MEGA 265.
Further infos on this project: https://create.arduino.cc/projecthub/sl001/aim65-lookalike-computer-from-scratch-8d94d6
A standalone computer with a TFT screen based on an Arduino DUE.
Further infos on this project: https://create.arduino.cc/projecthub/sl001/homecomputer-from-scratch-a04fb9
The FabGL library makes it possible to build real VGA system based on an ESP32 CPU.
Further infos on this project: https://create.arduino.cc/projecthub/sl001/a-vga-computer-based-on-esp32-and-fabgl-with-sound-graphics-976894
A system build on the old Wemos D1 UNO lookalike boards integrated with a low cost SD and clock shield.
Further infos on this project: https://create.arduino.cc/projecthub/sl001/the-10-euro-iot-computer-with-esp-8266-e93681
In one of the old Dr. Dobbs journals the tiny program
10 FOR I=1 TO 10000 : A=5 : NEXT
is called the canonical benchmark. These were simpler times. Here are a few results for Stefan's BASIC. The first number is running as a program, the second interactively. Results differ so much because, like in Apple Integer BASIC, all program lines are tokenised before execution. Any interactive code with a FOR loop has to tokenise the loop over and over again while a program does it only once.
ESP32/VGA: 214 ms / 763 ms
Arduino DUE: 274 ms / 1945 ms
Arduino RP2040 connect: 284 ms / 1223 ms
ESP8266: 374 ms / 1129 ms
Arduino MKR1010 Wifi: 545 ms / 3395 ms
Arduino UNO/MEGA/Diecimila/Nano: 1268 ms / 7316 ms
DOSBox (3000 cycles = 286@12MHz): 4.1 s / 28 s
These figures are a little unfair as some of the systems have to drive Wifi during the benchmark, like the ESP8266 and the RP2040 while others have to handle a display, like the ESP32/VGA.
All this is timed with millis(). Timing also depends on the language features added and other factors.
Run times quotes in the old Dr. Dobbs were between 2.5 minutes and 10 seconds for old 8080 based BASIC interpreters under CP/M with floating point arithmetic. My Apple I clone with a 1 MHz 6502 and Applesoft (floating point) BASIC needs 26 seconds. It doesn't matter if it runs as a program or interactively. An ATMega 644 clocked down to 1 MHz by using the internal oscillator and floating point runs the benchmark in 31 seconds which is roughly comparable with the Apple 1 clone. The main difference is the memory access code. Applesoft BASIC is written in Assembler and optimised for the 8bit memory access of the 6502 CPU. The BASIC interpreter here has a generic memory access method which works for all kind of architectures. Rewriting the memread() and memwrite() code in assembler would probably speed up the code quite a bit.
My Mac runs the program in 2 ms. This cannot be explained with clock frequency. The bottleneck of the Arduino's is memory access and flash read performance of the interpreter code. My Raspberry Pi 2 needs 35 ms. Both, the Raspberry and the Mac load the interpreter completely into memory or even cache and run it there while the microcontrollers have slow program memories.
I now use the program
10 T=MILLIS(1): FOR I=1 TO 10000: A=5: NEXT: T=MILLIS(1)-T
20 S=MILLIS(1): FOR I=1 TO 10000: A=5*6: NEXT: S=MILLIS(1)-S
30 U=MILLIS(1): FOR I=1 TO 10000: : NEXT: U=MILLIS(1)-U
40 V=MILLIS(1): FOR I=1 TO 10000: NEXT: V=MILLIS(1)-V
50 PRINT "Loop time", V/10
60 PRINT "Token time", (U-V)/10
70 PRINT "Assignment time", (T-U)/10
80 PRINT "Multiplication time", (S-T)/10
for time testing. It yields for distinct times in microseconds. Loop time is the time a full FOR loop needs. Token time is the time the interpreter needs to interpret one token. Assingment time the the time to parse and execute a full assignment operation. Multiplication time is the time a multiplication and parsing of the expression needs.
Differences of the various platforms are striking. All times here are in microseconds.
Uno Integer - Simple
Loop time 43
Token time 18
Assignment time 68
Multiplication time 34
LGT8 Integer - Simple
Loop time 15
Token time 6
Assignment time 19
Multiplication time 10
Uno Float - Simple with float
Loop time 69.9
Token time 21.1
Assignment time 83.5
Multiplication time 52.2
STM32V4VE
Loop time 5.3
Token time 1.7
Assignment time 10.3
Multiplication time 3.7
XMC
Loop time 43
Token time 10.3
Assignment time 56
Multiplication time 34.2
ESP8266
Loop time 29.89999
Token time 21.5
Assignment time 36.9
Multiplication time 9.6
ESP32
Loop time 11.3
Token time 9.89999
Assignment time 14
Multiplication time 2.59999
ESP32-C3
Loop time 12.3
Token time 9.39999
Assignment time 14
Multiplication time 3.59999
RP2040 (Pi Pico)
Loop time 12.6
Token time 12.89999
Assignment time 18.5
Multiplication time 5.59999
The token time measures the memory bandwidth of a system. It is determined by the combined speed of the memory and the CPU. The LGT8 boards is very fast and then of course the STM32 with its large data cache memory and high clock frequency. Multiplication time of the ESP32 is surprising as well as on the LGT8. This is a combination of good memory bandwidth and hardware multiplication.
Please have a look at the example section of the repo. In chapter 11 there is a number of classical BASIC benchmark and the respective results.
- LCD shield uses LiquidCrystal.h (https://www.arduino.cc/en/Reference/LiquidCrystal).
- PS2 Keyboards on Arduino (https://github.com/slviajero/PS2Keyboard and https://www.pjrc.com/teensy/td_libs_PS2Keyboard.html)
- Wire.h and Lyquidcrystal_IC2.h for the connection of serial displays (https://github.com/slviajero/LiquidCrystal_I2C)
- UTFT for the TFT (http://rinkydinkelectronics.com/library.php?id=51)
- FabGL for VGA (http://www.fabglib.org/)
- EepromFS for file systems on I2C EEPROMS (https://github.com/slviajero/EepromFS)
- RF2401 for radio (https://nrf24.github.io/RF24/)
- http://arduino.esp8266.com/stable/package_esp8266com_index.json
- https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
- http://digistump.com/package_digistump_index.json
- https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
- https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
- https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
- https://mcudude.github.io/MegaCore/package_MCUdude_MegaCore_index.json
- https://mcudude.github.io/MightyCore/package_MCUdude_MightyCore_index.json
- https://github.com/Infineon/XMC-for-Arduino/releases/latest/download/package_infineon_index.json