Beruflich Dokumente
Kultur Dokumente
---------------------------------------------------------------------------
Note that the andalog and digital input and output functionality (that is
the adiosrv.pde file) work fine with the ChipKit32 boards as well:
http://www.digilentinc.com/Products/Catalog.cfm?NavPath=2,892&Cat=18
---------------------------------------------------------------------------
DOWNLOADING AND INSTALLING THE MOTOR SHIELD LIBRARY (to be done only once):
Download the motor shield library for the motor shield here:
https://github.com/adafruit/Adafruit-Motor-Shield-library/zipball/master
then uncompress it and stick the AFMotor directory into the
arduino-1.X/libraries folder.
NOTE that if you don't have the motor shield and you don't plan to use it,
you might also SKIP THIS STEP but you have to make sure to upload the
ADIOSRV.PDE file to the board instead of the srv.pde file (see step below).
Also, at the time this was written (Dec 2011), the Motor Shield library does
NOT work with the ChipKIT32 boards, so if you are using one of these boards,
you MUST skip this step and make sure to upload the ADIOSRV.PDE file instead.
---------------------------------------------------------------------------
UPLOAD SRV.PDE (OR ADIOSRV.PDE) TO THE ARDUINO BOARD (to be done only once):
The srv.pde (or adiosrv.pde) is the "server" program that will continuously
run on the microcontroller. It listens for MATLAB commands arriving from
the serial port, executes the commands, and, if needed, returns a result.
The following instructions are needed to upload the srv.pde file into the
controller's flash memory. Note that if you don't have the motor shield and
don't plan to use it, then you can UPLOAD THE ADIOSRV.PDE file instead
(the instructions are the same, except for the folder location).
As long as no other file is uploaded later, this step does not need to
be repeated anymore, and the package can be used as soon as the board is
connected to the computer.
From the Arduino IDE, go to File > Open, locate the file srv.pde,
(in the ArduinoIO/pde/srv folder) and open it. If a dialog appears asking
for the permission to create a sketck folder and move the file, press OK
(this will create a srv folder and move the srv.pde file inside it).
Connect the Arduino, make sure that the right board and serial port are
selected in the IDE, (Tools/Board and Tool/Serial Port) then select
File -> Upload to I/O Board and wait for the "Done Uploading" message.
At this point the srv.pde file is uploaded and you can close the IDE,
which is not needed anymore for the purpose of this package. Actually
closing the IDE is suggested, so you can be sure that the serial connection
to the arduino board is not taken by the IDE when matlab needs to use it.
Note that the older files adiosrv.pde (IO pins only) and motorsrv.pde
(motor shield only) are also still available as simplified versions for
you to play around and create your own sketch versions. For older boards,
should you have any connection problems, it is suggested that you try to
upload and use the adiosrv.pde file.
---------------------------------------------------------------------------
Make sure that the pathdef.m file is writable, e.g. on unix issue a command
like this: sudo chmod 777 usr/local/matlab/R2012a/toolbox/local/pathdef.m
(the above changes depending on where MATLAB is installed).
If you are using the Arduino Uno (or later) on Unix, then create a symbolic
link as follows: sudo ln -s /dev/ttyACM0 /dev/ttyS101
From MATLAB, launch the "install_arduino" command, this will simply add the
relevant ArduinoIO folders to the matlab path and save the path.
---------------------------------------------------------------------------
TYPICAL USAGE:
Make sure the board is connected to the computer via USB port, make sure
you know which serial port the Arduino is connected to (this is the same
port found at the end of the drivers installation step), and finally,
make sure that the port is not used by the IDE (in other words, the IDE must
be closed or disconnected), so that MATLAB can use the serial connection.
Then use the commands a.pinMode, (to change the mode of each pin
between input and output) a.digitalRead, a.digitalWrite,
a.analogRead, and a.analogWrite, to perform digital input,
digital output, analog input, and analog output.
Consult the help of the files to get more information about their usage.
Finally, use a.delete to delete the arduino object, (and free up the serial
port) when the session is over.
NOTE: Should the serial port not be relaesed after you clear the arduino
object, you can use the following commands to release serial connections:
---------------------------------------------------------------------------
DEMO MODE:
---------------------------------------------------------------------------
EXAMPLE:
% read analog input from analog pin 5 (physically != from digital pin 5)
av=a.analogRead(5);
% close session
delete(a)
---------------------------------------------------------------------------
BLINK CHALLENGE:
NOTE that running this applicaton only makes sense if the Arduino board is
connected to an appropriate circuit where digital pins 9 to 13 are configured
as outputs and connected to leds, digital pin #2 is configured as input and
connected to a button that pulls the voltage down when pressed, and analog
pin #2 is connected to a potentiometer. Have a look at the schematics in the
blink_challenge_sch.mdl file, in the examples folder.
---------------------------------------------------------------------------
The motor shield is a shield to control dc, stepper and servo motors, which
can also be controlled from the MATLAB command line using this package.
Details on the shield are here: http://www.ladyada.net/make/mshield/
and is a good idea to have a good look at the Manual:
http://www.ladyada.net/make/mshield/use.html
DO NOT HOT SWAP SHIELDS. Before plugging the motor shield delete the
arduino object from the workspace, disconnect, then plug the motor shield
on top of the arduino, reconnect and create a new arduino object.
Also, note that the motor shield uses a lot of the pins, (see the manual)
so if you use both analog and digital IO and motor instructions they
will likely interfere with each other, so the best approach is using
either the IO instructions OR the motor shield instructions and delete
and reinstantiate the arduino object everytime one needs to switch from
one set of instructions to the other.
If for any reason you were using the adiosrv.pde file then you need to
upload either the srv.pde or motorsrv.pde files on the board, in order
to use the motor shield.
% attach servo #1
a.servoAttach(1);
% release motor 1
a.motorRun(4,'release');
% releases stepper 1
a.stepperStep(1,'release');
% close session
delete(a)
---------------------------------------------------------------------------
SIMULINK LIBRARY
Since version 3.0 this package also comes with a Simulink library that
has block for Analog and Digital IO, as well as Servo Read and Write,
Motor, and Stepper control. Type "arduino_io_lib" to open the library.
Examples that illustrate how to use analog IO blocks are the files
"blink_challenge_sim.mdl" and "blink_challenge_sf.mdl", which are the
simulink and stateflow implementation of the blink challenge demo
described above in this readme file. The file "servo_sim.mdl" shows
how to use the Servo Read and Write blocks.
Note that these blocks, being based on MATLAB objects (and relying on the
OS serial communication stack), do not support code generation.
The Arduino Target (also available on MATLAB Central file excchange),
can be used to automatically generate, from Simulink, arduino executables
that are automatically uploaded on the board.
---------------------------------------------------------------------------
ARDUINO MEGA
The Arduino Mega board has several more I/O pins than the Duemilanove/UNO.
Stefan Neuh�user, [stefan . neuhaeuser at ilek . uni-stuttgart . de]
has suggested modifying the files 'arduino.m' and 'adiosrv.pde' as
following, to access all the available pins:
TROUBLESHOOTING
This software was developed mainly on R2011a, and was fully tested using
R2010a, so i suggest to get at least R2010a (or later) if you can.
The simulink library will not work on versions prior to R2010a, (because
the arduino object is shared among the blocks in the model using features
that belong to that version). In any case, this software uses the new
MATLAB object system, and it will not work on versions prior to R2008a.
I have come across in the past to cases (using the Duemilanove board) in
which MATLAB had problems in connecting to the arduino when creating an
object (specifically, this resulted in the error message: "Connection
unsuccessful, please make sure that the Arduino is powered on ... ").
I believe this is solved now, as it was likely due to the older servotimer
library, anyway if you have similar problems and don't need to use the
motor board, then i suggest that you simply compile and upload the
adiosrv.pde file on the arduino, instead of the general version srv.pde
or:
or:
then it likely means that something went wrong with your serial connection,
(this might happen sometimes for example if the board resets itself) and
your best chance is doing the following:
---------------------------------------------------------------------------
Note that while this package was designed to be used with MATLAB, it can
be used with any program that allows you to communicate via serial port.
For example the command "1c" reads digital pin #2, as "1" stands for
digitalRead and "c" stands for pin #2 (ascii(c)-ascii(a)=2)
---------------------------------------------------------------------------
---------------------------------------------------------------------------