ESP32 PC With Tiny Basic on Steroids
by Rob Cai in Circuits > Arduino
12331 Views, 40 Favorites, 0 Comments
ESP32 PC With Tiny Basic on Steroids
In this Instructable I am going to show how to build the second version of a simple retro style PC based on an ESP32 and few other components.
This PC runs a modified version of Tiny Basic, a simplified dialect of BASIC, and generates the output for a VGA monitor.
The resolution is 640x200 pixels, allowing 80x25 ascii characters in 16 colors. It uses a PS2 keyboards, and the code can be saved on a micro SD. I have created a breadboard that included a VGA and PS2 port, as well as a piezo and an adaptor for the micro SD reader.
Some of the ESP32 I/O free pins can be directly driven by dedicated BASIC commands. Those pins are available through an extra connector and a RS232 port. This means that this PC can be also considered a stand-alone microcontroller that you can program directly in BASIC to control other devices (sensors, actuators, etc.), without the need of an external PC and IDE. When your code is ready, you can save it on the micro SD with the name autorun.bas and, at the reset, it is executed automatically.
The customized Tiny Basic has many extra features, such as the possibility to use floating point numbers and arrays, many graphical and mathematical functions, timing functions and so on, as shown in details in the next step.
Tiny Basic Features for This Project
The standard Tiny Basic Plus features can be found here.
But for this project many other commands have been added, and some application are shown in the pictures in this step. Here it is a list:
Graphic commands:
- CLS
- COLOR x,y forecolor, backcolor
- GET(x, y) get color from pixel x, y. Return "16" if the pixel is outside the screen
- POINT c, x, y color of pixel x, y
- LINE c, xIni, yIni, xEnd, yEnd, pw color, x ini, y ini, x end, yend, pen width
- RECTANGLE c, cf, xIni, yIni, xEnd, yEnd, pw color, color fill (-1 = no fill), x ini, y ini, x end, y end, pen width
- ELIPSE c, x, y, w, h, cf color, center x, center y, width, height, color fill (-1 = no fill)
- CURSOR 0/1 enable/disable cursor
- AT x, y -> puts cursor on x,y
Color definitions:
- standard colors: 0 Red; 1 Green; 2 Yellow; 3 Blue; 4 Pink; 5 Cyan; 6 Grey; 7 Dark Grey;
- bright colors: 8 Red; 9 Green; 10 Yellow; 11 Blue; 12 Pink; 13 Cyan; 14 White; 15 Black
Sound commands:
- TONE(freq, duration)
mathematic commands:
- RND(a, b) random number from a to b - 1
- ABS(x, y) returns abs(x), y is not kept in account
- POW(x, y) returs x^y
- EXP(x) returns the exponential of x
- LOG(x, n) returns the logarithm of x in base n
- LN(x) returns the natural logarithm of x
- ROOT(x, n) returns n-th root of x (returns 0 if x is negative and b is even).
- SIN(x) returns sin(x) where x is in degrees.
- COS(x) returns cos(x) where x is in degrees.
- TAN(x) returns tan(x) where x is in degrees.
- MOD(a, b) return the remaining of a/b
- INT(x) return integer part of x
Timing commands:
- TIME(a): a = 0 returns milliseconds from the start (up to 32.767);
- a = 1 returns seconds from the start
- a = 2 returns minutes
- a = 3 returns hours
- a = 4 returns days
Array introduction:
- VECTIN a,n,m assign the value a to the vector[n][m]
- a = VECTOUT(n,m) returns the value of the vector[n][m] and assign it to the variable "a"in this example
Other useful commands:
- INKEY program suspended until a button is pressed
- INPUTN(n) suspend the program until a key is pressed,
- LS n list 16 program lines starting from the n-th line
ESP32 Board Version and Software Installation
The version I am using here is the ESP32 NodeMCU WiFi with CP2102, with 38 pins.
Once you purchase this board, begin installing the ESP32 Tiny Basic PC code. In this step you can find four compressed .bin files that you can upload directly on the ESP32. NB you have to download the file binfiles.rar.txt, rename it such as binfiles.rar and uncompress it to get the four .bin files. Once you have them, you must upload on the microcontroller. There are many software that allow that but, if you are a newcomer, there is an easy way by using the Arduino IDE.
Starting from the scratch, first install the Arduino IDE. You can download it from the Arduino Home Page, here, and you have to install also the ESP32 drivers. Since there are a tons of tutorial, I am skipping this step here. But you can find more info in the first version of this PC here. The configuration in my PC is:
ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFF), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32MB), 921600, None su COM14
Now, just try to upload an example code, for instance, upload LEDCsoftwarefade as shown in the upper 1st picture.
If this succeed, please watch the last line before the orange code, as shown the 3rd picture (see the line in the yellow ellipse).
The Arduino IDE has compiled the code and created four .bin files, in the example
- boot_app0.bin
- bootloader_qio_80m.bin
- LEDCSoftwareFade.ino.bin
- LEDCSoftwareFade.ino.partitions.bin
Please try to Copy&Paste this line in a Windows command prompt and press Enter, you will see that the .bin files are immediately uploaded (via esptool.exe) in the ESP32, i.e. without the need of the Arduino IDE.
This means that you can copy the four .bin files at the bottom of this page in your PC, for instance in the folder C:\binfiles, modify the prompt command of the previous example accordingly (i.e. you replace the path and files name with the Tiny Basic PC ones), and you should be able to upload the code!
For instance, for me, this is the working line.
C:\Users\Casa\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\3.0.0/esptool.exe --chip esp32 --port COM14 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 C:\binfiles/boot_app0.bin 0x1000 C:\binfiles/bootloader_qio_80m.bin 0x10000 C:\binfiles/ESP32_Tiny_Basic_Plus_PC_20ago21_v28.ino.bin 0x8000 C:\binfiles/ESP32_Tiny_Basic_Plus_PC_20ago21_v28.ino.partitions.bin
Downloads
Schematic
I have built the breadboard using EasyEDA. At the bottom of this step I put the schematic in pdf.
You can find the Gerber files in .zip format (download the file and replace the extension from .zip.txt in .zip).
In the second picture you can find the final result. So far I have ordered 10 PCB and assembled four little PCs.
BAS Programs Examples
Here you can downoad some example of ESP32 Tiny Basic Plus codes, where I try to use all the new features of this customized BASIC for the ESP32. You can see some of them in action in the introduction video and in the one in this step.
I plan to add more code in the future and to keep this section up-to-date.
Acknoledgments
I wish to express my tanks to Fabrizio Di Vittorio for his awesome ESP32 VGA library. For more details, visit his site here.
many thanks also to the authors of Tiny Basic:
- Mike Field
- Scott Lawrence
- Brian O'Dell
my acknoledgments also to Fernando Garcia Fb1998 that began to introduce the ghraphics functions to Tiny Basic Plus.