Autres articles / Other articles

Communicate with Flash Forth

published: 22 May 2019 / updated 11 June 2019

Lire cette page en français

 


The development of FORTH applications on ARDUINO requires a type of software terminal. We have chosen, for the first steps, a very simple terminal: PuTTY. But you are free to operate any terminal of your choice.

Installing PuTTY for Windows

The PuTTY program is available here: putty.org.

In this page, follow the link: "You can download PuTTY here".

In the following page, you will have the choice between different versions:

choice of PuTTY version

Being Windows 10, we downloaded the 64-bit version (putty-64bit-0.71-installer.msi).

Once downloaded, launch this application with confidence.

démarrage installtion de PuTTY

Complete the installation.

Set PuTTY

Once installed, launch PuTTY. You must see this:

set puTTY

We will create a custom session to communicate with the map ARDUINO MEGA 2560 which now uses the FORTH language.

We select the COM7 port for our case. This value may be different on your PC. You will find the communication port used by the ARDUINO board by opening devices under Windows:

search COM port used by ARDUINO board

The communication speed is selected at 38400 bps.

Finally, we select Default Settings and we click on Save. This backup will allow you to find the settings of PuTTY at the next terminal session.

Using the PuTTY terminal

We now launch the terminal by clicking Open at the bottom of PuTTY.

If all goes well, you must see this:

Flash Forth starting screen

FORTH is operational!

We will check that everything works well by executing our first word: words.

This displays the contents of the FORTH dictionary:

p2+ pc@ @p hi d. ud. d> d< d= d0< d0= dinvert d2* d2/ d- d+ dabs ?dnegate dnegate  
s>d rdrop endit next for in, inline repeat while again until begin then else if  
zfl pfl xa> >xa x>r dump .s words >pr .id ms ticks r0 s0 latest state bl 2- [']  
-@ ; :noname : ] [ does> postpone create cr [char] ihere  char ' lit abort"  
?abort ?abort? abort prompt quit true false .st inlined immediate shb interpret  
'source >in tiu tib ti# number? >number ud/mod ud* sign? digit? find immed? (f)  
c>n n>c @+ c@+ place cmove word parse /string source user base pad hp task  
ulink rsave bin hex decimal . u.r u. sign #> #s # digit <# hold up min max ?negate  
tuck nip / u*/mod u/ * u/mod um/mod um* 'key? 'key 'emit p++ p+ pc! p! p@ r>p  
!p>r !p u> u< > < = 0< 0= <> within +! 2/ 2* >body 2+ 1- 1+ negate invert xor or  
and - m+ + abs dup r@ r> >r rot over swap drop allot ." ," s" type accept 1 umax  
umin spaces space 2swap 2dup 2drop 2! 2@ cf, chars char+ cells cell+ aligned align  
cell c, , here dp ram eeprom flash >< rp@ sp@ 2constant constant 2variable variable  
@ex execute key? key emit Fcy mtst scan skip n= rshift lshift mclr mset ic,  
i, operator iflush cwd wd- wd+ pause turnkey to is defer value fl+ fl- c! c@ @ x!  
x@ a> ! >a literal int! ;i di ei ver warm empty rx1? rx1 tx1 rx0? rx0 tx0 load-  
load+ busy idle exit 

Our first définition

If the PuTTY terminal (or any terminal of your choice) communicates perfectly with your ARDUINO card, you can now create new words. In FORTH, a word is the C language equivalent of a function. Our first word bonjour:

: bonjour ( --) 
    ." Bonjour tout le monde" cr 
    ." Bienvenue dans mon application" cr ; 

You can type this example from the keyboard, or copy / paste into the terminal. On Windows, it is the right mouse button that will paste the text into the terminal.

attention to the case of the characters

The FORTH Flash Forth version for ARDUINO is case-sensitive. Clearly, if a word is available or compiled in lowercase characters, it should be used with these same tiny characters.

Then press Enter on the keyboard once or twice and type bonjour to run the compiled code. display:

compilation and execution of bonjour

Here! You have just compiled your first word in FORTH, then run it!

The same program in C language would have required a compilation on PC, then upload to the Arduino. Here, certainly, our first word bonjour is very simple.

But as soon as the programs become more complex, it will be incessant compilations and uploads required for the development phase.

While FORTH ships the interpreter and compiler into the ARDUINO board. This interactivity and flexibility will be an asset majour to develop words complex.

Let's go back to our new word bonjour. It is now part of FORTH dictionary like all the other words already defined. With FORTH, there is no language and application. Your FORTH application becomes an extension of the language FORTH. To understand this, let's type the word words that show the contents of the dictionary. Here the last 3 lines that appear after the execution of words:

 x! x@ a> ! >a literal int! ;i di ei ver warm empty rx1? rx1 tx1 rx0? rx0 tx0  
 load- load+ busy idle exit 
bonjour marker  ok<#,ram> 

We see our word bonjour.

Unplug the ARDUINO board and close the PuTTY terminal.

Let's reconnect the ARDUINO board and restart the PuTTY terminal. Let's tap again words. The word bonjour previously compiled is always in the dictionary!

And to run it, just type again bonjour.

Yes. But we want to move to more serious applications and not clutter with this word bonjour. It's very simple, you type empty warm and the word bonjour will be missing from the dictionary and the memory space taken by this word recovered and therefore available for other new words.