Arduino Basics

 

Download the Arduino IDE software or sign up to use the Arduino IDE web editor here.

 

 

The littleBits Arduino bit must be connected to a power source.  It does not draw power from the computer.

 

Once you plug the littleBits Arduino into your computer, go to the Tools pull down menu in the Arduino software, select “Board” and then choose “Arduino Leonardo” from the menu.

 

The Arduino is a microprocessor about as powerful as desktop computers were in the 1980s.  You can load a series of instructions called a sketch to the Arduino and it will execute in an endless loop until you load new instructions.

 

All Arduino sketches have the following structure:

 

void setup() {

  // put your setup code here, to run once:

 

}

 

void loop() {

  // put your main code here, to run repeatedly:

 

}

 

The void setup () command clears whatever values had previously been initialized.  Whatever values you define in the setup loop will be loaded when you send the sketch to the board.

 

The void loop () command clears whatever loop had been coded before.  When you send the sketch to the board, it will execute the new commands in a loop.

 

We will be working with the Blink sketch.  Go to the File pull down menu, then choose Examples> Basics > Blink.

 

 

 

Arduino sketches are based on the C coding language.  Here are some key elements of the syntax:

 

​//

Precedes comment lines.  Comments explain what the code is supposed to do in language humans can understand.

/**/

Encases blocks of text that are included as comments.  The computer does not execute comment text.  You can “comment out” blocks of code when you are testing and de-bugging your sketch.

 

​{}

Curly brackets open and close functions, loops, and conditional statements.  If you forget one of them, your code will not execute and you will get error messages.

 

​;

Statements end with a semicolon.  Check for missing semicolons if you get compiler errors.

 

 

 

You can look up all the terms in the Arduino language on the Arduino Language Reference page.

 

 

The Blink sketch uses two functions.  The first, pinMode() defines a specific pin on the Arduino board as an output.  The littleBits Arduino boards have 3 pins.  They are numbered 1, 5, and 9.  Connect your outputs to these pins.  In order to initialize a particular pin, you will use a statement like this in the set up loop:

 

pinMode(5, OUTPUT);

 

Blink also uses the digitalWrite () function.  This function sends a signal to one of the pins you have defined as an output:

 

digitalWrite(5, HIGH);  

 

In this statement the variable “HIGH” turns on the output connected to pin 5.   Replacing “HIGH” with “LOW” turns the power off:

 

digitalWrite(5, LOW);  

 

Resources

 

Arduino Tutorials

 

 

Arduino.org Tutorials

 

 

Debugging Arduino Code

Arduino Forum

 

Q: How to debug an Arduino? A: With the Arduino debugger

Arduino for Visual Studio Debugging Tutorial 

 

Code Project Debugger for Arduino

 

Arduino Serial Monitor

 

littleBits Arduino

*Getting Started with littleBits Arduino at Heart Module"

 

Getting Started with littleBits Arduino

 

littleBits Arduino

 

Animatronics with littleBits

littleBits Animatronics Challenge

 

Animatronics Workshop by Ginger Alford

 

littleBits Tips and Tricks

“10 Ways to Make Goofy Eyeballs”