Introduccion A La Programacion Con Ardiuno
Introduccion A La Programacion Con Ardiuno
This book and the kit will give you the necessary skills
The Arduino can also be extended with the use of
needed to get started in this exciting and creative
ʻShieldsʼ which are circuit boards containing other
hobby.
devices (e.g. GPS receivers, LCD Displays, Ethernet
connections, etc.) that you can simply slot into the top
So, now you know what an Arduino is and what you can
of your Arduino to get extra functionality. You donʼt
do with it, letʼs open up the starter kit and dive right in.
have to use a shield if you donʼt want to as you can
make the exact same circuitry using a breadboard,
some veroboard or even by making your own PCBʼs.
Download the Arduino IDE Now, connect the other end of the USB cable into the
USB socket on your PC or Mac. You will now see the
Download the Arduino IDE from the Arduino download small power LED (marked PWR above the RESET
page. As of the time of writing this book, the latest IDE switch) light up to show you have power to the board.
version is 0015. The file is a ZIP file so you will need to
uncompress it. Once the download has finished, unzip If you have a Mac, this stage of the process is complete
the file, making sure that you preserve the folder and you can move on to the next Chapter. If you are
structure as it is and do not make any changes. using Windows, there are a few more steps to complete
(Damn you Bill Gates!).
If you double-click the folder, you will see a few files
and sub-folders inside.
The wizard will now search for a suitable driver and then
tell you that a “USB Serial Convertor” has been found
On the next page select “Install from a list or specific and that the hardware wizard is now complete. Click
location (Advanced)” and click Next. Finish.
Make sure that “Search for the best driver in these You are now ready to upload your first Sketch.
locations” is checked.
Upload your first Sketch
you will see the Sketch inside the white code window.
Now that your Freeduino has been connected and the Now you need to tell the IDE the details of your USB
drivers for the USB chip have been installed, we are port, so now click on Tools again, scroll down to Serial
now ready to try out the Arduino for the first time and Port and a list of the available serial ports on your
upload your first Sketch. system will be displayed. You need to choose the one
that refers to your USB cable, which is usually listed as
Navigate to your newly unzipped Arduino folder and something like /dev/tty.usbserial-xxxx on a
look for the Arduino IDE icon, which looks something Mac or something like Com 4 on Windows so click on
like this.... that. If not sure, try each one till you find one that works.
When you open up the Arduino IDE it will look very The Toolbar consists of 7 buttons, underneath the
similar to the image above. If you are using Windows or Toolbar is a tab, or set of tabs, with the filename of the
Linux there will be some slight differences but the IDE code within the tab. There is also one further button on
is pretty much the same no matter what OS you are the far right hand side.
using.
Along the top is the file menu with drop down menus
The IDE is split up into the Toolbar across the top, the headed under File, Edit, Sketch, Tools and Help. The
code or Sketch Window in the centre and the Serial buttons in the Toolbar provide convenient access to the
Output window at the bottom. most commonly used functions within this file menu.
Verify/ Serial
Stop New Open Save Upload
Compile Monitor
The Toolbar buttons are listed above. The functions of each button are as follows :-
Serial Monitor Displays serial data being sent from the Arduino
The Verify/Compile button is used to check that your The Upload to I/O Board button will upload the code
code is correct, before you upload it to your Arduino. within the current sketch window to your Arduino. You
need to make sure that you have the correct board and
The Stop button will stop the Serial Monitor from port selected (in the Tools menu) before uploading. It
operating. It will also un-highlight other selected is essential that you Save your sketch before you
buttons. Whilst the Serial Monitor is operating you may upload it to your board in case a strange error causes
wish to press the Stop button to obtain a ʻsnapshotʼ of your system to hang or the IDE to crash. It is also
the serial data so far to examine it. This is particularly advisable to Verify/Compile the code before you upload
useful if you are sending data out to the Serial Monitor to ensure there are no errors that need to be debugged
quicker than you can read it. first.
The New button will create a completely new and blank The Serial Monitor is a very useful tool, especially for
Sketch read for you to enter code into. The IDE will ask debugging your code. The monitor displays serial data
you to enter a name and a location for your Sketch (try being sent out from your Arduino (USB or Serial board).
to use the default location if possible) and will then give You can also send serial data back to the Arduino using
you a blank Sketch ready to be coded. The tab at the the Serial Monitor. If you click the Serial Monitor button
top of the Sketch will now contain the name you have you will be presented with an image like the one above.
given to your new sketch.
On the left hand side you can select the Baud Rate that
The Open button will present you with a list of Sketches the serial data is to be sent to/from the Arduino. The
stored within your sketchbook as well as a list of Baud Rate is the rate, per second, that state changes
Example sketches you can try out with various or bits (data) are sent to/from the board. The default
peripherals once connected. setting is 9600 baud, which means that if you were to
send a text novel over the serial communications
The Save button will save the code within the sketch line (in this case your USB cable) then 9600 letters, or
window to your sketch file. Once complete you will get symbols, of the novel, would be sent per second.
a ʻDone Saving message at the bottom of the code
window.
To the right of this is a blank text box for you to enter Across the top of the IDE window (or across the top of
text to send back to the Arduino and a Send button to your screen if you are using a Mac) you will see the
send the text within that field. Note that no serial data various menus that you can click on to access more
can be received by the Serial Monitor unless you have menu items.
set up the code inside your sketch to do so. Similarly,
the Arduino will not receive any data sent unless you
have coded it to do so.
The menu bar across the top of the IDE looks like the
Finally, the black area is where your serial data will be image above (and slightly different in Windows and
displayed. In the image above, the Arduino is running Linux). I will explain the menus as they are on a Mac,
the ASCIITable sketch, that can be found in the the details will also apply to the Windows and Linux
Communications examples. This program outputs versions of the IDE.
ASCII characters, from the Arduino via serial (the USB
cable) to the PC where the Serial monitor then displays The first menu is the Arduino
them. menu. Within this is the About
Arduino option, which when
To start the Serial Monitor press the Serial Monitor pressed will show you the
button and to stop it press the Stop button. On a Mac current version number, a list
or in Linux, Arduino board will reset itself (rerun the of the people involved in
code from the beginning) when you click the Serial making this amazing device
Monitor button. and some further information.
Once you are proficient at communicating via serial to Underneath that is the
and from the Arduino you can use other programs such Preferences option. This will
as Processing, Flash, MaxMSP, etc. To bring up the Preferences
communicate between the Arduino and your PC. window where you can change various IDe options,
such as were you default Sketchbook is stored, etc.
We will make use of the Serial Monitor later on in our
projects when we read data from sensors and get the Also, is the Quit option, which will Quit the program.
Arduino to send that data to the Serial Monitor, in
human readable form, for us to see. The next menu is the
File menu. In here you
The Serial Monitor window is also were you will see get access to options to
error messages (in red text) that the IDE will display to create a New sketch,
you when trying to connect to your board, upload code take a look at Sketches s
or verify code. t o r e d i n y o u r
Sketchbook (as well as
Below the Serial Monitor at the bottom left you will see the Example Sketches),
a number. This is the current line that the cursor, within options to Save your
the code window, is at. If you have code in your window Sketch (or Save As if
and you move down the lines of code (using the ↓ key you want to give it a different name). You also have the
on your keyboard) you will see the number increase as option to upload your sketch to the I/O Board (Arduino)
you move down the lines of code. This is useful for as well as the Print options for printing out your code.
finding bugs highlighted by error messages.
Next is the Edit menu. In here you The next menu in the
get options to enable you to Cut, IDE is the Tools menu.
Copy and Paste sections of code. W ithin this are the
Select All of your code as well as options to select the
Find certain words or phrases within Board and Serial Port
the code. Also included are the we are using, as we did
useful Undo and Redo options when setting up the
which come in handy when you Arduino for the first time.
make a mistake. Also we have the Auto
Format function that
Our next menu is the Sketch menu which gives us formats your code to make it look nicer.
access to the Verify/Compile functions and some other
useful functions you The Copy for Forum option will copy the code within the
will use later on. Sketch window, but in a format that when pasted into
These include the the Arduino forum (or most other Forums for that
Import Library option, matter) will show up the same as it is in the IDE, along
which when clicked with syntax colouring, etc.
will bring up a list of
t h e a v a i l a b l e The Archive Sketch option will enable you to compress
libraries, stored your sketch into a ZIP file and asks you were you want
within you r to store it.
libraries folder.
Finally, the Burn Bootloader option can be used to burn
A Library, is a collection of code, that you can include the Arduino Bootloader (piece of code on the chip to
in your sketch, to enhance the functionality of your make it compatible with the Arduino IDE) to the chip.
project. It is a way of preventing you from ʻre-inventing This option can only be used if you have an AVR
the wheelʼ by reusing code already made by someone programmer and have replaced the chip in your Arduino
else for various pieces of common hardware you may or have bought blank chips to use in your own
encounter whilst using the Arduino. embedded project. Unless you plan on burning lots of
chips it is usually cheaper and easier to just buy an
For example, one of the libraries you will find is ATmega chip with the Arduino Bootloader already pre-
Stepper, which is a set of functions you can use within programmed. Many online stores stock pre-
your code to control a Stepper Motor. Somebody else programmed chips and obviously these can be found in
has kindly already created all of the necessary the Earthshine Design store.
functions necessary to control a stepper motor and by
including the Stepper library into our sketch we can use The final menu is the Help menu were you can find help
those functions to control the motor as we wish. By menus for finding out more information about the IDE
storing commonly used code in a library, you can re- or links to the reference pages of the Arduino website
use that code over and over in different projects and and other useful pages.
also hide the complicated parts of the code from the
user. Donʼt worry too much about using the IDE for now as
you will pick up the important concepts and how to use
We will go into greater detail concerning the use of it properly as we work our way through the projects. So,
libraries later on. Finally within the Sketch menu is the on that note, letʼs get on
Show Sketch Menu option, which will open up the folder
were your Sketch is stored. Also, there is the Add File
option which will enable you to add another source file
to your Sketch. This functionality allows you to split
larger sketches into smaller files and then Add them to
the main Sketch.