EPICS Arduino tutorial

Page History

NOTE: This page is now considered as deprecated, as the SparkFun ProtoSnap is no longer available. If you can assemble an Arduino with all the devices, then, the this tutorial should still be valid, however, with our students, I have basically given up, as I don't want them to be spending time learning breadboard and electronics. Please do not get me wrong; it is quite useful to have the basic electronics knowledge and knowing how to use a breadboard. I just don't want to spend my own time with that. In addition, if the students has to do this on their own, setting up a circuit on a breadboard introduces more errors because of that. I do not want the students to get discouraged because of that...

This tutorial is based upon the work done by Pete Jemian @ Advanced Photon Source/Argonne National Laboratory. It has been modifed to use SparkFun ProtoSnap as well as to make it easier for absolute beginner to follow the minimum concept.

The assumption is that you have already downloaded and installed STAR EPICS VM Environment or STAR EPICS VM 6 Environment on your computer. If you have not done so, please check the link above.

Assuming you already have STAR EPICS VM environment installed and running, download the package here.
If you are using STAR EPICS VM 6 environment, then, download the package for SL6 here.

Once you have it downloaded, enter the following commands in Terminal:

[sysuser@localhost ~]$ tar xvfz Downloads/epicsArduino.tgz
At this point, you should have a new directory called "epicsArduino" in your home directory.
[sysuser@localhost ~]$ ls -l epicsArduino
total 44
drwxrwxr-x 3 sysuser sysuser 4096 Jun 30 08:57 bin
drwxrwxr-x 4 sysuser sysuser 4096 Jul 6 12:38 configure
drwxrwxr-x 4 sysuser sysuser 4096 Jul 6 12:38 configureSup
drwxrwxr-x 2 sysuser sysuser 4096 Jul 6 12:38 db
drwxrwxr-x 2 sysuser sysuser 4096 Jul 6 12:38 dbd
drwxrwxr-x 2 sysuser sysuser 4096 Jun 29 16:49 documentation
-rw-rw-r-- 1 sysuser sysuser 1976 Jul 6 11:04 epicsArduino.adl
drwxrwxr-x 4 sysuser sysuser 4096 Jun 30 08:53 epicsArduinoApp
drwxrwxr-x 4 sysuser sysuser 4096 Jul 6 12:38 epicsArduinoSup
drwxrwxr-x 3 sysuser sysuser 4096 Jun 30 08:53 iocBoot
-rw-rw-r-- 1 sysuser sysuser 315 Jun 29 16:49 Makefile
Before you do anything, do the following command:
[sysuser@localhost ~]$ ls /dev/ttyUSB*
ls: /dev/ttyUSB*: No such file or directory
You should get the result shown above. This is normal. This means that the there is no USB device of this type is present.

Now, plugin the ProtoSnap board to a USB port on your computer. Once you do, go to the VirtualBox menu, select "Devices", then, select "USB Devices". You should see an entry for "FTDI FT232R USB UART [0600]". If not, unplug and plug the ProtoSnap board.

Notice that on the second image, "FTDI FT232R USB URT [0600]" is selected (the check mark on the left of the menu item).
This indicates that the device is recognized in the Linux guest OS.

At this point, your ProtoSnap board should be recognized by the Linux system. Do the command from above, again:
[sysuser@localhost ~]$ ls /dev/ttyUSB* /dev/ttyUSB0
This means that your ProtoSnap board is recognized by the Linux system. Make a note of the name of the port using. It should be /dev/ttyUSB0 as shown above, but it could be /dev/ttyUSB1 or any other numbers in some rare cases.

Assuming the port it is using is /dev/ttyUSB0, do the following command:
[sysuser@localhost ~]$ cd epicsArduino/iocBoot/iocepicsArduino
[sysuser@localhost iocepicsArduino]$ pwd
[sysuser@localhost iocepicsArduino]$ ls -al
total 24
drwxrwxr-x 2 sysuser sysuser 4096 Jul 6 12:38 .
drwxrwxr-x 3 sysuser sysuser 4096 Jun 30 08:53 ..
-rw-rw-r-- 1 sysuser sysuser 283 Jul 6 12:38 envPaths
-rw-rw-r-- 1 sysuser sysuser 115 Jun 30 08:53 Makefile
-rwxrwxr-x 1 sysuser sysuser 1576 Jul 6 12:06 st.cmd
-rw-rw-r-- 1 sysuser sysuser 1578 Jul 6 09:53 st.cmd~
In principle, you are ready to run the IOC. If your ProtoSnap board was attached anything other than /dev/ttyUSB0, then, you need to make small change in st.cmd file in your current directory. If that's the case, do the following command:
[sysuser@localhost iocepicsArduino]$ gedit st.cmd &
You should see a text editor window show up. Change all the entries of /dev/ttyUSB0 with whichever the correct port name there. There should be only one entry of this on Line 16. Do not make any other changes.

Now you are ready to run the IOC. Do the folloiwng:
[sysuser@localhost iocepicsArduino]$ ./st.cmd
You should see the screen shown below:

In comparison, here is a bad example (notice for all the red warnings during the startup of the IOC). The errors shown here is due to the fact that the ProtoSnap board was not found by the Linux system. Since there is no board to control, it couldn't initialize the board, therefore, errors were generated.

If you have the errors, or need to stop the IOC for any reasons, type "exit" (no quotes). That should stop the IOC process that is running in that window.

Once you have the IOC running properly, now it is time to work on the graphical front end of the IOC. Open another terminal, and do the following:

[sysuser@localhost ~]$ cd epicsArduino
[sysuser@localhost epicsArduino]$ medm epicsArduino.adl &
You should see two windows shown below come up on the screen.

The first screen is the MEDM main window. Here, you can toggle the created MEDM screen between Edit mode and Execute mode.
The second screen is the created MEDM screen for ProtoSnap. It is now in Edit mode.
Change the mode to Execute mode by clicking "Execute" button on the main MEDM window. At this point, you should see the second window something like this:

The Light Sensor value should change if you move your hand over the light sensor on the board. Push "Off" button for the LED Switch. You should see the Green LED light up. If you push the button (not to be confused with the reset button), the Button Status should change from Green to Red.

Above, with Green LED turned on. Below, with Green LED turned off.