E5Shield User's Guide

The E5Shield is a hardware/software combination that enables a real-world interface to MATLAB.  This document assumes you have an E5Shield board (it has "E5 Shield" written on the top) connected to an Arduino processor (the bottom of the board has "Arduino" printed on it) connected via a USB cable to your computer.  This document assumes the hardware and software are configured properly.  If not, please consult the hardware/software guide.

The E5Shield let's you use MATLAB to control real world devices (including LED's, servo motors, and low voltage relays and motors, and anything that responds to a logic level (0 to 5 volt low power) output, and to sense voltages from the real world (0 to 5 volts).  It also allows for communication with a Wii Nunchuck.  A diagram of the shield is shown to the right (click on image get higher resolution).  The connections you are likely to use in E5 are labeled in red, other connections are blue.

The E5Shield software functions fall into three general categories, 1) Initialization, 2) Sensing, and 3) Control. 

  1. Initialization
  2. Sensing
  3. Control

1) Initialization

Before using the E5Shield for real world sensing and control an E5Shield "object" must be created within MATLAB (this uses a MATLAB command
"E5Shield").  This object is used to let MATLAB interact with the real world.  Second, any pins that are to be used for input or output must be specified using the "pinMode" function.  Third, it is possible to change the voltage reference used for analog inputs using "analogReference."  The second and third commands are generally not of interest for E5.


The Arduion/E5Shield are connected to your computer through a USB port (see diagram above).  The computer sees this connection as a serial port, or COM (short for communications) port, with a number.  The serial port is "COMx" where "x" is a one or two digit number.  To determine this number

  1. Click on the Start button (a Windows icon in a circle at the lower left of the screen).
  2.  Click on "Control Panel" (this may take a few seconds to open).
  3. Select "Device Manager" by clicking on it.

This sequence is illustrated in the image below.

 In the Device Manager, click the triangle to the left of “Ports” to see the available COM (or serial) ports.  If there is one that is called Arduino UNO R3, or something similar (shown below), the COM port listed in parentheses is the one you should use (COM19 in this case).


Otherwise, the one whose Manufacturer is Arduino LLC or www.arduino.cc is the COM port that should be used. 

If the Arduino does not appear among the available ports, or if MATLAB still cannot connect, then unplug the Arduino board from the USB port for at least ten seconds then reconnect it and enter the command into MATLAB again.

Once the serial port is determined, an E5Shield object can be created.  In the example below, the name of the object is "a."  Note: In this document MATLAB commands that you enter will be shown in green and with a Courier font, output from MATLAB will have a gray background.

>> a=E5Shield('COM19')
Attempting connection: 3,2,1,0
E5Shield Script detected!
E5Shield successfully connected!
a = 
E5Shield object connected to COM19 port
E5Shield Server running on the E5Shield board
Digital Pin 02 is currently UNASSIGNED
Digital Pin 03 is currently UNASSIGNED
       ⋮ Pins 04 through 11 omitted for brevity
Digital Pin 12 is currently UNASSIGNED
Digital Pin 13 is currently UNASSIGNED

At this point the I/O pins (Pin 02 through 13) are unassigned.  Leave them this way unless you need them for some purpose.  If you prefer not to have the long printout, simply but a semicolon at the end of the MATLAB command.


this is this


Normally the analog inputs

2) Sensing


this is this


this is this

3) Control


this is this


this is this


This command sets the angle of a servo connected to one of the sets of three pins labeled J0 through J9.  Note that to control a servo an external voltage source is needed on the lines labeled "Motor Power" at the top of this document (the red wire goes to the positive voltage, black goes to ground (or negative) voltage.  Note also that servo connectors have three wires, one black, one red and one yellow; make sure these are attached to the pins labeled "B," "R," and "Y," respectively. 

Servo motors have approximately 180° of rotation controlled by the width of a pulse sent on the yellow wire.  The width of the pulse varies between 1 mS and 2 mS as the angle varies from 0 to 180° in the clockwise (?? Nicole, can you make sure the direction is correct ??).  The syntax of a call to this function is as follows (where it is assumed that "a" is an initialized "E5Shield" object (see Initialization for directions on how to create an "E5Shield" object).

>> a.servoWrite(n,val)

The motor is determined by "n" which must be 0 through 7, and the number "val" determines the pulse width via the formula

pulse width = 1 mS + val*4μSec

In other words each increment of "val" by 1 unit corresponds to an increase in pulse width of 4 μS. So if val=0, then the pulse width is 1 mS.  If val=250, the pulse width is 2 mS.  If val=100, the pulse width is 1.4 mS...  (Note: this value is ±5% if you compare one E5Shield board against another - but should be almost constant for any given board; in other words it is very precise, but not completely accurate).  The command

>> a.servoWrite(3,112);

will set the pulse width for motor 3 to 1.448 mS (=1 + 0.004*112);. 

The variables "n" and "val" may be vectors if you want to set several motors all at the same time.   For example,

>> a.servoWrite([1 3 7],[112 0 250]);

will set the pulse widths for motor 1 to 1.448 mS, motor 3 to 1 mS and motor 7 to 2 mS.  

To set the first several motors all to the same value, you can let "val" be a scalar. So,

>> a.servoWrite(0:3,125);

sets the first 4 motors to a pulse width of 1.5 mS.


this is this


Calling this function determines the state of the status LED on the E5Shield board.  If the argument is zero, the LED is turned off.  Any non-zero value will turn the LED on. 

>> a.statLED(0);       % Turn LED off
>> a.statLED(100);     % Turn LED on


this is this