NOTE: In the Mac OS finder, you may need to right-click
on the Arduino folder, and select “Show Package
Contents” in order to reach the destination folder.

Figure 4. Connecting the cable to
the I/O Module.

Installing the XIPMod code library creates a repository of
XIPMod code examples within the Arduino IDE. These are
available through the Arduino File menu (shown in Figure 6),
just like any other Arduino code examples.

Figure 5. Arduino code environment.

Writing XIPMod Code
for the Arduino

With the XIPMod code library installed, almost all of the

XIPMod control functions documented in the Machine

Science tutorials are available in the Arduino environment.

However, code for the Arduino must be written with a slightly
different structure than that presented in the tutorials. With
the exception of #include statements, #define statements,
and global variable declarations, all code must be contained in
two special functions: setup and loop. This structure will be
familiar to Arduino users.

As an example, consider a simple code for blinking an
LED on the Input/Output Module. The version on the left
shows how the code would be structured in the XIPMods
tutorial; the version on the right shows the structure required
for the Arduino.

Both examples contain identical headers: #include
machinescience.h, which includes code required for all XIPMod projects; and #include iomod.h, which
includes code required for controlling the I/O Module. The network_control(ENABLE) function — which
initializes network communication among the XIPMods — needs to be executed only once, so it appears
inside the Arduino setup function. The code for blinking the LED needs to be executed over and over. It is
placed inside an infinite while loop in the example on the left, and inside the loop function in the Arduino
example on the right. One other minor change is also required: all delay_ms functions in the original code
file must be changed to delay functions for the Arduino. In the example above, the two delay_ms(1000)
statements become delay(1000) statements. SV