ArduinoSoftwareIntro

From ArduinoInfo
Jump to navigation Jump to search

INTRO TO ARDUINO SOFTWARE

Arduino calls software written for the Arduino type boards SKETCHES

What Arduino Sketches look like and how you can write them

All Arduino sketches have the same basic structure:

  • First there is SETUP Where you put things to be done once at the beginning.
  • Thenhere is LOOP where you put the things that will be done over and over again.

Soon you will use the "Arduino IDE" to edit your sketches. Here's a quick look at what you'd do when you start a totally New sketch.

You would click FILE and NEW SKETCH. A new page would pop up and look like this:

1 void setup() {
2   // put your setup code here, to run once:
3 
4 }
5 
6 void loop() {
7   // put your main code here, to run repeatedly:
8 
9 }

A Better Template to start with

The first example above is very simple but as soon as you do more complicated things you will have to define variables, import libraries, and write your own subroutimes that are pieces of code that is outside of Setup or Loop. WHERE should you put them?? This "Starter Template" (you can cut and paste it later) shows a way to explain and organize things: (You can scroll it up and down here).

 1 /* YourDuinoStarter Example: Sketch Template
 2  - WHAT IT DOES
 3  - SEE the comments after "//" on each line below
 4  - CONNECTIONS:
 5    - 
 6    - 
 7  - V1.00 09/11/12
 8    Questions: terry@yourduino.com */
 9 
10 /*-----( Import needed libraries )-----*/
11 /*-----( Declare Constants and Pin Numbers )-----*/
12 /*-----( Declare objects )-----*/
13 /*-----( Declare Variables )-----*/
14 
15 
16 void setup()   /****** SETUP: RUNS ONCE ******/
17 {
18 
19 
20 }//--(end setup )---
21 
22 
23 void loop()   /****** LOOP: RUNS CONSTANTLY ******/
24 {
25 
26 
27 }//--(end main loop )---
28 
29 /*-----( Declare User-written Functions )-----*/
30 
31 
32 //*********( THE END )***********

Look at some EXAMPLES

There are thousands of examples in MANY sites and places. It is hood to carefully read code written by other people. It is a very good way to learn. Do it slowly .

Here is one that is the usual BLINK program but using the template above:

 1 /* YourDuinoStarter Example: BLINK
 2  - WHAT IT DOES: Blinks the built-in LED ON and OFF
 3  - SEE the comments after "//" on each line below
 4  - CONNECTIONS:
 5  - Built-In LED and resistor connected to pin 13
 6  -
 7  - V1.01 02/11/13
 8  Questions: terry@yourduino.com */
 9 
10 /*-----( Import needed libraries )-----*/
11 //none yet
12 /*-----( Declare Constants and Pin Numbers )-----*/
13 #define led 13  // define name of pin number  NOTE: NO ";" on #define !
14 /*-----( Declare objects )-----*/
15 //none yet
16 /*-----( Declare Variables )-----*/
17 //none yet
18 
19 
20 void setup()   /****** SETUP: RUNS ONCE ******/
21 {
22   pinMode(led, OUTPUT);  // initialize the digital pin as an output. 
23 }//--(end setup )---
24 
25 
26 void loop()   /****** LOOP: RUNS CONSTANTLY ******/
27 {
28   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
29   delay(1000);               // wait for a second, watching the bright LED
30   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
31   delay(1000);               // wait for a second, watch the Dark
32 
33 }//--(end main loop )---
34 
35 /*-----( Declare User-written Functions )-----*/
36 //None yet
37 //*********( THE END )***********

LINKS to Many More Examples

After you get the Arduino IDE installed you will start to make your own sketches.

Below are links to many other examples you may want to read thru or copy.

The Arduino IDE (Integrated Development Environment)

This is the free software you will download to use to create the Behavior of your project. Here's what it includes:

  • An EDITOR to create and edit the text of your software Sketch. It actively highlights Keywords in the language so typing errors are more obvious.
  • A VERIFY system that runs through your Sketch, verifies that there are no errors, and then compiles it into the machine language program that can be Uploaded to your Arduino board over the USB cable. (This is often called MAKE in other systems, and actually is quite complex, running system preprocessor, compiler, linker etc. "Under the covers").
  • An UPLOAD system that communicates with your Arduino Board over USB, loads your program into Arduino memory, and starts your program running.
  • A SERIAL MONITOR window that allows you to receive and send messages from programs running on your Arduino board. This is often used for testing and "debugging" programs.
  • Many EXAMPLE software Sketches that show how to use many different devices and techniques.
  • A LIBRARY system containing many prewritten sections of software.
  • A FILE system to save and retrieve Sketches.
  • A HELP system that includes the entire Arduino Reference document.


Click on [THIS PAGE] to learn about the Arduino IDE.

To download and install the Arduino IDE:

Go our pages that show how to go the official Arduino site to download and install the software for your operating system:

Arduino Libraries:

Here we will talk about Software for Arduino, LIBRARIES of Arduino code, PHYSICAL COMPUTING and other subjects.

When you start writing Arduino software Sketches, you are not in a room alone. You are in a Library, with many pre-written examples that make it easy to use more complex functions like connecting to the Internet. Here are the Standard Libraries that come with the free IDE software install:

  • EEPROM - reading and writing to "permanent" storage
  • Ethernet - for connecting to the internet using the Arduino Ethernet Shield
  • Firmata - for communicating with applications on the computer using a standard serial protocol.
  • LiquidCrystal - for controlling liquid crystal displays (LCDs)
  • SD - for reading and writing SD cards
  • Servo - for controlling servo motors
  • SPI - for communicating with devices using the Serial Peripheral Interface (SPI) Bus
  • SoftwareSerial - for serial communication on any digital pins. Version 1.0 and later of Arduino incorporate Mikal Hart's NewSoftSerial library as SoftwareSerial.
  • Stepper - for controlling stepper motors
  • WiFi - for connecting to the internet using the Arduino WiFi shield
  • Wire - Two Wire Interface (TWI/I2C) for sending and receiving data over a net of devices or sensors

One of the greatest advantages of Arduino is the worldwide community of thousands of people who are using it. Arduino enthusiasts who have figured out how to do more complex things have shared their work by creating Contributed Libraries. Some of the categories of libraries are:

  • Communication (networking and protocols):
  • Sensing:
  • Displays and LEDs:
  • Audio and Waveforms:
  • Motors and PWM:
  • Timing:
  • Utilities:


See the details of available libraries on the Arduino site here: And when you figure out something cool that other people could use, see the Tutorial on that page about writing your own libraries.


PHYSICAL COMPUTING

Physical Computing is quite different than writing software for personal computers where the only physical inputs are the Mouse and Keyboard. With Arduino you can connect and control literally hundreds of different devices, and write software that creates new Intelligent Devices.

Click on [THIS PAGE] to start on this important subject.

COMBINING ARDUINO SKETCHES

Go [(HERE!)]

READY TO START WITH HANDS-ON LEARNING?

Go [(HERE!)]