invention

Arduino: Getting Started

by syedBits

Published on June 19, 2015

So you've just unboxed your shiny new littleBits Arduino module and would like to get into the fabulous world of Computer Programming. Or you're already an experienced programmer and want dip your toe into coding an Arduino, we'll be covering how you can get from 0 - 100 in no time.

You can also follow the slightly more in depth version here:
http://discuss.littlebits.cc/t/introduction-to-arduino-programming-1-the-basics/22237

Credits: pubnub instructables keywild

How To Make It

1

What does the Arduino module do anyway? In short the littleBits Arduino at ❤ module enables you to learn programming, code physical games, and connect your littleBits modules to pretty much any software running on your computer. How does it work? Think of the Arduino as a little kid. If we need it teach it something, like riding a bike ( or move a servo motor ) we'll have to give it commands. It'll use it's sense of touch and feel through theinputs and outputs of our littleBits circuits The other important thing to remember is that the Arduino can store memory and make decisions . So if you're playing a game, it can decide if you won a game or not and keep track of the game's score.

2

To program the Arduino we need special software that will let us connect to the Arduino so we can code it. IDE stands for Integrated Development Environment. Let's break down that down: http://www.arduino.cc/en/Main/Software Development stands for software development or coding. We use code to create programs. Environment is exactly what it means, humans exist in a environment that's made up of oxygen and water + lots of other stuff we need to live. In computer programming an environment includes all the things we need to code our Arduino in it's little Arduino world. Integrated It just means that everything you need to code is all one place. If you'd like to learn more I highly recommend reading the documentation for the Arduino Development Environment

3

Before we get coding we need to setup our circuit. Let's take a look at the Arduino:

We can see that our module has a set of inputs one side and a set of outputs on the other. And the USB port let's us program the Arduino from our computer.

Picture 3

4

All we have to do now is grab our p1 power bit (blue), our Arduino (orange) and a USB cable. Make sure you've turned on your power bit and plugged in your USB cable.

5

Ok now our Arduino won't do much because just like our friend frankenstein we'll need to give it some commands so it can do some work, BUT before we can do that there's one more step. We need to tell the IDE what Arduino we're using and how we're communicating with it. So that means selecting our board which is based off of the Arduino Leonardo. Then we select port (our communication method) we'll be send our code through. Which is “tty.usbmodem…” for Mac, “cu.usbmodem…” for Windows.

6

Flipping the programming switch Ok now we need to check everything is order we press the upload button and hopefully you'll see some lights blink on your Arduino and we'll have our very first program flashed! The Arduino is equipped with a tiny bit of memory that allows it to save our program so when we unplug the device and turn it back on it will run program that was last uploaded. If things go wrong don't fear, let's do a little troubleshooting: - Make sure that your Arduino is powered on before you open your IDE. - Try restarting the Arduino software. - Try restarting your computer. - Unplug your Arduino and plug it back in. - Make sure the right port and board are selected. - If all else fails check out our troubleshooting guide

7

Flipping the programming switch Ok now we need to check everything is order we press the upload button (second to the right) and hopefully you'll see some lights blink on your Arduino and we'll have our very first program flashed!

 The Arduino is equipped with a tiny bit of memory that allows it to save our program so when we unplug the device and turn it back on it will run program that was last uploaded.

 If things go wrong don't fear, let's do a little troubleshooting: - Make sure that your Arduino is powered on before you open your IDE. - Try restarting the Arduino software. - Try restarting your computer. - Unplug your Arduino and plug it back in. - Make sure the right port and board are selected. - If all else fails check out our troubleshooting guide

8

Now just like our friend frankenstein we need to load software on to our Arduino's baby brain and teach it to do things. So let's get down to some coding! You'll see a copy of the code in the project page please type it in carefully and hit the checkmark (furthest right button) to check for errors.

9

Wat? Ok so we're learning how to code now. We need to teach our Arduino to do things but only way we can do that is to speak it's language. And just like learning any new language we need to learn it's rules. In computer programming those rules are called syntax.

 The rules of the road Firstly you'll notice that the words void and ** setup** void setup() as well as void and loop. void loop() Are both highlighted. This is called syntax highlighting, it means those words are special keywords that give the Arduino a specific command. void setup() is a function. a function is a lot like a blender it takes in some ingredients and gives us something delicious like so:

10

In addition to the name of the function we need to tell the Arduino what kind or type of function we want, in this case we'll be using void.
We won't dive deeply into types of functions (yet!) but just know that they come before setup() and loop() right now.

The section after the parentheses () and in between the curly braces { } is where we will write our first line of code that will enable the Arduino to talk to us.

It's called Serial.begin() In this case we're using Serial no not the stuff you eat but a form of communication that let's us upload to the Arduino. .begin(9600) tells the Arduino to start the communication. You'll notice that there is a dot that separate's Serial and begin that is yet another syntax rule.

Don't worry you'll remember all of this as you keep coding!

 The 9600 tells the Arduino how fast it should talk to us. For most of the most part 9600 for what we're going to be doing.

 NOTE: Right after our function name we have two parentheses every function has them just like you have a type and a name.

Think of it as a punctuation mark. Our second command is the loop() just like it implies it runs code over and over again. Just like like our circulatory system is a loop, the code inside of the loop is pumped through our program. In this case we're pumping code through the Arduino's veins. 

11

Serial.println("hello littleWorld!"); is the command that we us to tell the Arduino to speak. Inside of the double quotes is where we put our message!



Picture 2

12

Congrats! If you have any problems please check our troubleshooting guide: http://littlebits.cc/projects/troubleshooting-arduino

Related Projects