Joining Raspberry Pi and Arduino applications with SIMPL

Arduino Sketch In Brief

The first thing the Arduino sketch does is assign the SIMPL name ARDUINO to the tclSurrogate child process running on the Rasp Pi. Any SIMPL sender now sees a local SIMPL receiver process called ARDUINO on the Rasp Pi. Recall from the tclSurrogate protocol discussion above that the generic tclSurrogate child process assumes this SIMPL name, ARDUINO. SIMPL messages arriving at this child process are then routed to the Arduino via the tclSurrogate socket. Being a receiver, the sketch waits to receive a message.

This message contains a single byte representing the states of the eight LEDs, each as a bit (0=Off; 1=On). The Arduino simply replies with a null response and illuminates the LEDs accordingly. Recall that all SIMPL messages are acknowledged to release the sender to carry on with other business. A null response is a valid SIMPL acknowledgement.

In our demo design, the Arduino is not returning any information to the sender. This could be otherwise depending on the application. For example, the Arduino could be asked for sensory data of some sort and would reply with that information.

Arduino Checklist

  • 1. The port number on the Rasp Pi that the tclSurrogate daemon is babysitting is set correctly. Default = 8000. Line 19 in eightLeds.ino.
  • 2. The IP address assigned to the Rasp Pi is set correctly. Line 20 in eightLeds.ino. Note the URL in line 21; we can use this instead if the tclSurrogate daemon is living somewhere in the cloud.
  • 3. The MAC address of the Ethernet chip is the one found on the shield. Line 22 in eightLeds.ino.

We assume that the reader is familiar with the Arduino IDE and has it available on a development host. This will be necessary to compile the eightLeds.ino code and upload the binary image to the Arduino.

When the SIMPL archive [4] is installed on your development host, look at the subdirectory simpl/docs. There you will find readme.arduino, which will explain a few simple steps to import the Arduino Simpl library into the Arduino IDE.

When running eightLeds.ino, it's highly recommended that the Arduino IDE's serial monitor be open for business. The sketch writes messages back via the serial monitor, which are very helpful in narrowing down problems.

In our configuration, both the Rasp Pi and the Arduino are connected to the same network router. However, the SIMPL toolkit only requires a TCP/IP route between the Rasp Pi and the Arduino. If the Rasp Pi is configured to have a static IP address (and/or hostname), then the physical connection could be directly via an Ethernet cable.

When an Arduino TCP/IP connect request is received by the tclSurrogate daemon at port 8000 on the Rasp Pi, a child process is spawned to handle the resulting TCP/IP socket communications. As such, the Arduino business logic and the child process illustrated in Figure 2 together will present themselves to other SIMPL applications as a SIMPL receiver module. When the Arduino is started, the sketch will run.

To check that the Arduino sketch is running correctly, you can look for the ARDUINO SIMPL name in the namespace sandbox by typing:

fcshow

The SIMPL process named ARDUINO should be there.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content