My Forth Experience / Experiments Page


Home                               Craigs Pages                               Heathers Pages

October 2021
PAGE STILL UNDER CONSTRUCTION

Introduction

After a year of retirement from high tech I had the urge to do some hardware and software again. I think it must be in my blood. It had been a long time since I programmed small  computers (micro controllers and/or micro processors) so I thought I would get back to it. Since starting again, I have been having great fun designing and building electronic gadgets. I also  think continuing to program will help keep my mind sharp in case I have to get a real job again in the future.

ESP32Forth

Later I will describe some of my many adventures with Forth but first I wanted to tell you about my latest Forth find that I think is just amazing. In looking around the web I came across a port of ueForth / ESP32Forth written by Bradley D. Nelson that is hosted in the Arduino environment. ESP32Forth is an Arduino program that is flashed to a ESP32 module using the Arduino IDE. Once flashed, the ESP32 becomes a full featured Forth programming environment for developing Forth applications that have access to WiFi, Bluetooth, SPIFFS, SD cards, networking, i2C, SPI and many other of the ESP32 APIs. The beauty of this system is that one can add or remove Forth words at will creating ones own custom Forth development environment.  With that said that is exactly what I did. I removed some of the functionality that I didn't think I would use like a block editor and added a lot of functionality that I knew my applications would require including: SPI, Neopixel support, advanced networking, floating point arithmetic and a lot more. The code is available here.



With this new Forth tool, I implemented some ESP32 embedded applications including a Neopixel based thermometer, a slideshow program, a world clock program and a real time Earthquake map showing all of the earthquakes happening around the world. I also wrote drivers for numerous SPI LCD displays, graphics libraries for displaying text and graphics, a library for OneWire devices, a JSON parser, a time and timezone library, NTP code and much more. ESP32Forth has shown itself to more than powerful enough for all the embedded ESP32 projects I have used it for and will be my go to environment for many of my future projects as well.

Complex Forth programs are generally built using numerous files of Forth code that need to be organized and maintained. This can be done of course storing the files on the ESP32 SPIFFS filesystem or by storing them on an SD card that ESP32 has access to but both of these techniques have their issues. I chose a different route. I developed what I call the ESP32forth loader (written in Java) which runs on a USB connected host computer. This allows me to save Forth files to and from my MacBook in an organized fashion and to pick and chose which Forth files should be compiled to build a Forth application. The loader program is shown below:


 
The loader has the concept of include files that determine which Forth files make up an application. Here is an example include file for the Slideshow program I wrote:
\ Slide Show App Load Page
\ for TTGO T4 hardware

#include Hardware/TTGO_T4.fth
#include Drivers/ILI9341.fth
#include Graphics/graphics.fth
#include Apps/SlideShow/slideshow.fth
Lines that begin with a backslash are comments. As this shows, include files can be nested.

You specify the high level application include file in the Input Area (bottom of the screen), hit return and each individual include file is loaded and compiled on the ESP32. The compilation progress of the ESP32Forth code is shown in the large output window. Any errors encountered during the compilation will be shown in this window. The Input Area also maintains a command history which can be scrolled through using the up and down cursor keys.

If one types #help in the Input Area a help screen is displayed:
ESP32 Forth Loader by Craig A. Lindley

ESP32 Forth Loader Directives:

#clear - Clears the Output Area
#bye - Terminates ESP32 Forth Loader
#help - Shows this message
#include filename - Loads Forth code from a file

NOTES:
1. Remember to have your ESP32 device connected before starting ESP32 Forth Loader
2. Remember to set the FORTH_HOME environment variable if using include files
3. #include files can be nested
4. Use the up/down cursor keys to access command history

Questions/Comments to calhjh@gmail.com
The ESP32Forth Loader requires configuration before it can be used. The following are the instructions for running on a MAC.

ESP32 Forth Loader Running Instructions
Craig A. Lindley
July 2021

Prerequisites
====================
1. ESP32ForthLoader.jar
2. jssc-2.8.0.jar (or newer)

Executing From Shell
====================
1. Change directory to where the Forth loader jar files are located
2. export FORTH_HOME=<“full path to directory with esp32Forth project files>”
3. export CLASSPATH=“./ESP32ForthLoader.jar:./jssc-2.8.0.jar”
4. java com.craigl.esp32ForthLoader.ESP32ForthLoader

Alternatively add the following to your .profile/.zshenv file in your home directory
====================
# Items for ESP32 Forth Loader
export FORTH_HOME=~/Documents/dev/ESP32ForthLoader/projects
export CLASSPATH=~/Documents/dev/ESP32ForthLoader/ESP32ForthLoader.jar:~/Documents/dev/ESP32ForthLoader/jssc-2.8.0.jar
alias pfl="java com.craigl.esp32ForthLoader.ESP32ForthLoader"

Operation
====================
1. Connect your ESP32 device to your computer
2. Execute ESP32pForthLoader as described above
3. Once loader is operational, select appropriate Serial Port from drop down list
4. Click Open button in the UI to open the selected Serial Port
5. Type #help into the Input Area to see the help info
6. Type Forth commands to interact with ESP32forth
7. Type #include <filename> to load Forth code from a file
8. Use up/down cursor keys to retrieve command history
9. Type #bye to terminate the loader


NOTES:
1. The loader's window can be resized as necessary
The combination of ESP32Forth and the ESP32ForthLoader makes a convenient and useful development environment for writing ESP32Forth applications.

Click here to view the various ESP32Forth code/applications I have written. NOTE: this is a snapshot of my work space so not all code is fully operational.



My Forth Writings

Over the years I have written numerous times on various Forth topics. Here are some of the items I have published in roughly chronological order:

I wrote "The Alternate FORTH", a complete FORTH language and operating system for the TRS-80 line of Radio Shack computers. Marketed by the Alternate Source, Lansing, MI. 1983.

I wrote an article for the, now defunct magazine, Forth Dimensions, about writing a full on spreadsheet program in Forth. The program was made up of 45 screens of source code so the article was spread out over 2 issues. The first issue of the magazine is available here.

An article, "Forth Windows for the IBM PC", Dr. Dobbs Journal, July 1986, pg. 46.

I wrote an article for Dr. Dobb's Journal in 2008 about using Forth to generate HTML for web pages. The article is available here and the supporting code is available here.

I wrote an another article for Dr. Dobb's Journal also in 2008 where I wrote a version of Forth I called JForth in Java. The article is available here and the supporting code is available here.

I wrote an article in 2014 for Servo magazine called "Programming the Arduino in AMForth". The article is available here.






Home                               Craigs Pages                               Heathers Pages