chochain / nanoFORTH

Forth for Arduino Nano - Interactive, Multi-tasking, EEPROM turnkey.
MIT License
27 stars 4 forks source link
arduino bluetooth forth multitasking

The emerging micro-controller communities are no more focusing on specific hardware or form factor but around tool-chain provided typically with higher-level languages. The once popular Arduino platform gradually lose out the market share to ESP, Raspberry, and whatever new kids on the block. Being chip agnostic, the Arduino IDE does serve as an excellent learning tool for future systems to come. No matter how the hardware environment evolved, especially on the edge of IoT universe, I felt a minimalist system similar to the Arduino UNO/Nano will always have its value especially in learning even when the size of chips shrunk down to micro or even nano-scale one-day.

On the language end, check out NASA and contemplate why FORTH is still running on a number of space probes today. It's known that projects developed in interactive/incremental style can be more productive compared to typical static tool-chain such as the C/C++ provided by Arduino.

I touched FORTH briefly years ago back in school days. After seeing Nakagawa's TinyForth, I got this idea!

nanoFORTH - FORTH for Arduino Nano

Observations

+ many Arduino makers are still using UNO or Nano,
+ most do not need the full-blown FORTH vocabularies,
  50+ words or so, anything more might need ESP or RPi.
+ most are not familiar with standard FORTH words, abbreviation would be OK,
+ meta-compiler not needed, i.e. no trying to build a new Forth

Features

+ no bootloader burning needed, so no extra cost or bricking,
+ a downloadable library from Arduino IDE,
+ easy to follow .ino Sketch examples, (bluetooth, 7-seg, robot)
+ 1K RAM dictionary, and EEPROM to persist user defined words,
+ call Arduino functions, (i.g. pinMode, digitalRead/Write, analogRead/Write, millis, delay),
+ C API, for user defined functions (ig. Bluetooth, Servo, ...),
+ timer ISR, support multi-tasking,
+ pin change ISR, support hardware trigger,
+ memory dump and execution trace, to understand FORTH internal,
+ autorun after reboot, can become a turnkey system

Use Cases - Interaction Examples

Behold! This is nanoFORTH in its entirety. It's a short list of 'words' which should be rather easy to master. Note that the steps illustrated above has been the way Forth programmers building their applications. One small word at a time. Debug each well interactively then combine them into a "bigger" word. If a bug found, FGT the word, redefine it. Next word!


OK! If the process shown above has captured the essence, we should have an idea of what nanoFORTH is trying to do. Let's just stop and contemplate for a while. We did all of the above without any recompilation. Instead, we "talked" directly with the nanoFORTH uploaded only once via the USB cable. Should you code these in C, how do you go about doing it?

The interactive nature is different from the way we are so used to on Arduino platform. Just consider how many times you have to compile your C code to go through the functions shown above. So, move forward, let's envision how we can control robots or what we can do using Bluetooth with our Nano...


Ready to give nanoFORTH a trial? or view References and all the details...