Mar 242019
 

 

 

How to Install amForth on the Arduino Uno

This is a detailed technical article that describes how to set up an Arduino Uno microcontroller board with a version of the Forth programming language called amForth. My regular readers should ignore this post. Stay tuned though loyal readers, I will be posting more on this topic latter for a general audience.

I recently went through the process of installing amForth on my Arduino Uno. I wasn’t able to find a simple, easy to follow explanation of how to do it. I had to piece together information from a variety of sources and make a number of mistakes before I could make it work. I decided to write this article to make it easier for someone else who wants to avoid the headaches.

The method I am going to describe uses two Arduino Unos: one as the target board that you will install amForth on, and the other as the programmer. There are many other devices that can be used to program the Arduino’s microcontroller, but this is the only one I will describe. Also, the process I will follow uses a Mac. There will obviously be some differences if you are using Windows. I assume you have no knowledge of microcontroller programming, which was the case with me.

Here are the detailed steps:

Install CrossPack on your Mac

CrossPack is a developer environment that works on the Mac for programming Atmel’s AVR line of microcontrollers. The Arduino Uno uses Atmel’s m328p chip. Download CrossPack here. (See Figure 1 below.)

CrossPack

Figure 1: You should see this when you follow the link. Click the Download button.

Download amForth

Next, download the latest version of amForth here. You will see a list of folders with version names on them. (See Figure 2 below.) Above the list of folders are the words “Looking for the latest version?” followed by a highlighted link to a file ending with .tar.gz. Click on that link. The file will download to your Mac and be placed in your Downloads folder. Create a folder on your desktop called Forthduino and drag the .tag.gz file into that folder.

amForth download

Figure 2: Download amForth files.

Open the Forthduino folder you created on your desktop and click on the .tag.gz file to open it. You should see a new folder appear with the name “amforth” followed by the version number. Now you need to look inside the amforth folder to find the files uno.hex and uno.eep.hex. They can be found in amforth/appl/arduino/ (See Figure 3 below.) Copy the two files into the Forthduino folder.

find hex files

Figure 3: Find uno.hex and uno.eep.hex.

Set up the Arduino Programmer

As I said at the start of this article, you are going to program one Arduino Uno with another. Connect the Arduino Uno that will serve as the programmer to your Mac’s USB port now. Then start up the Arduino software on your Mac. Under the File menu look in Examples and find the sketch called ArduinoISP. Click on this sketch and upload it to your Arduino. Make sure that you have selected Arduino Uno as the Board under the Tools menu and you have your USB port selected under the Port heading of the Tools menu. The programmer is now ready. Keep your Arduino software open.

The next task is to connect the target Arduino Uno to the Arduino Uno serving as the programmer. Figure 4 below shows how this should be done. You can power the target Arduino Uno by running two wires from the +5V and Ground pins of the programmer Arduino as shown in Figure 4. Or you can power it separately with a battery pack. Pick one. Don’t do both!

Wire up the two Arduino Uno's as shown in the picture above.

Figure 4: Wire up the two Arduino Unos as shown in the picture above. Source: arduino.cc

Now you are ready to flash amForth to the Arduino…

Flash amForth to the target Arduino Uno

Before you perform the actually flashing process, go back to your Arduino software and look under the Tools menus. The Programmer selected should be Arduino as ISP. If not, change it. Also open up the Arduino Serial Monitor and select a BAUD rate of 19200.

Next, open up the Terminal program on your Mac. First thing you need to do is change Terminal’s directory to the Forthduino folder that has all your amForth files. The easiest way to do this is to type “cd” in the Terminal program follow by a space and then using the mouse pointer drag the Forthduino folder into the Terminal window. You should see the path typed out after the “cd” as in the second line of figure 5 below. If you’ve got that, press the RETURN key now.

Now the fun part. Type the following line in your Terminal window:

avrdude -P /dev/tty.usb* -c avrisp -b 19200 -p m328p -e -U flash:w:uno.hex:i -U eeprom:w:uno.eep.hex:i -U efuse:w:0x05:m -U hfuse:w:0xD9:m -U lfuse:w:0xFF:m

Terminal avrdude

Figure 5: Avrdude command entered into Terminal.

Type the above in one continuous line. Figure 5, above, shows what it should look like. Now press the RETURN key. You should see a readout of the flashing process. If everything worked it will look like the screen pictured below in Figure 6:

Figure 7: This is what you should see if everything has worked correctly.

Figure 6: This is what you should see if the avrdude command has worked correctly.

If you want to understand what this avrdude command with all its obscure add-ons does, I recommend reading this explanation from Limor Fried of Adafruit.

Connect to your Forthduino

Now that amForth is installed on your Arduino Uno, you can disconnect all the jumper wires between the two Arduinos and put the Arduino programmer aside. Plug your new Forthduino directly into your Mac’s USB port. Then, open the Mac’s Terminal program once more. Type this line and hit RETURN:

screen /dev/tty.usb* 38400

You should now see the amForth welcome screen as pictured here:

And that’s all there is to it. If you have any questions or comments add them below this article and I will be sure to respond to you.

 Posted by at 8:41 pm

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)