Arduino : A beginners story/guide

Using and Programming Arduino and other microcontrollers
Almurray42
Competent
PostsCOLON 293
JoinedCOLON Wed Jun 30, 2010 11:42 pm
LocationCOLON Bridgwater, Somerset, England
CONTACTCOLON

Arduino : A beginners story/guide

Postby Almurray42 » Thu Mar 29, 2012 8:08 pm

Hi guys, arduino is both simple and complex, but as a beginner I started off cold without any knowledge, so I thought id would be a good idea to post here my first steps into arduino; my ffindings, the problems I have and how I do things, hopefully as I go on it will turn more into a guide but for now it will be rusty and with a few questions...
Feel free to post any corrections, advice or problems that you have!
Below is a basic collection of the things you will need to do when starting with arduino, follow the posts for more in depth tuts.

1:Setting up your arduino http://www.arduino.cc/en/Main/Howto

2: Sending your first sketch (Program) http://arduino.cc/en/Tutorial/Blink

3: Coding? Huh? What? - Arduino Sketches EXPLAINED! - http://arduino.cc/en/Guide/Environment

3: Digital & Analog Inputs + Outputs + the HARDWARE of the arduino board! (Based on UNO R3) [b]- COMING SOON!

Happy modding!
Al
Last edited by 5 on Almurray42, edited 0 times in total.
Image
[MOD IT] [OR BIN IT]

Almurray42
Competent
PostsCOLON 293
JoinedCOLON Wed Jun 30, 2010 11:42 pm
LocationCOLON Bridgwater, Somerset, England
CONTACTCOLON

Re: Arduino : A beginners story

Postby Almurray42 » Thu Mar 29, 2012 9:59 pm

1: Unboxing and Setting up

OKay, So first steps obviously is unboxing, so this is what it looks like if you haven't seen a kit before!
Image
Image
The Actual Arduino board is in here -->
Image

Anyway, so first you will need the Arduino Software found here: http://arduino.cc/en/Main/Software
Install, and thats the first step!
This is what the program should look like when you first open it up (Fullscreened)
Image

You will also want to download AVRdude, look at the post on programming ATTiny chips to see a link, or google it! :P

Connect your arduino via USB to your computer as shown below and you're ready to start! :D
Image

A FULL OFFICIAL GUIDE TO SETTING UP YOUR ARDUINO CAN BE FOUND HERE: http://www.arduino.cc/en/Main/Howto
Last edited by 1 on Almurray42, edited 0 times in total.
Image
[MOD IT] [OR BIN IT]

phenoptix
Competent
PostsCOLON 744
JoinedCOLON Sat Apr 17, 2010 11:25 am

Re: Arduino : A beginners story

Postby phenoptix » Thu Mar 29, 2012 10:53 pm

A promising start! I look forward to the next installment!

Almurray42
Competent
PostsCOLON 293
JoinedCOLON Wed Jun 30, 2010 11:42 pm
LocationCOLON Bridgwater, Somerset, England
CONTACTCOLON

Re: Arduino : A beginners story/guide

Postby Almurray42 » Fri Mar 30, 2012 4:05 pm

2: Send your first sketch/program

Okay so obviously you will be eager to upload your first program to your arduino, so open up the arduino software. First you must ensure you have the correct device selected by going into Tools>Board and select the board you have. Next you must select the correct COM port so go to Tools>serial port>(Would be named something like COM1 or COM3). If your serial port menu is greyed out or no com ports show up, then read on and I will show you how to fix it.

Now you are all set up! Head into File>Examples>Basics>Blink and your screen should pop up with code! Plug in your arduino and hit the Upload sketch button! This program will make an LED plugged into GND and pin 13 go on and off at the rate of one second. Have a play around changing the time and get used to seeing the code, identify what you can!
--------
ERROR 1: (+FIX)

HERE is where i encountered my first error, it took me a lot of working out but it was relatively simple now i know how. Look at the bottom red line of code. This error message means that your PC is not communicationg properly with your compute, so something is going wrong.
Image

This could be a variety of things but for me it was the most obvious. - DRIVERS.

Here is how you can get the correct drivers installed for your arduino:
First ensure your arduino is plugged in and windows is no longer trying to find drivers on its own for your arduino.
Go into Control Panel>System and security>System>Device Manager
A window should pop up as shown below.
Image

Click on the COM ports tab and the unknown device tab. Your arduino will either show up as ARDUINO or as an unknown device. If you have multiple unknown devices showing up then uplug and plug back in your arduino and you will see which one it is as it will disappear and reapper as you do so.
Image

When you have identified it right click on it and click "Update driver software". Then click Browse my computer for a driver, And find your Arduino 1.1 (Or latest version) folder. Open Arduino>Drivers, and windows should automatically find and install the drivers when you click ok.
Image

Bingo! Restart your arduino software and you should be able to send your first program!
Image
[MOD IT] [OR BIN IT]

phenoptix
Competent
PostsCOLON 744
JoinedCOLON Sat Apr 17, 2010 11:25 am

Re: Arduino : A beginners story/guide

Postby phenoptix » Fri Mar 30, 2012 8:05 pm

Superb quality post!

Almurray42
Competent
PostsCOLON 293
JoinedCOLON Wed Jun 30, 2010 11:42 pm
LocationCOLON Bridgwater, Somerset, England
CONTACTCOLON

Re: Arduino : A beginners story/guide

Postby Almurray42 » Fri Mar 30, 2012 8:52 pm

phenoptix wroteColonSuperb quality post!

Thanks haha! Have been playing around with some led's and switches so will put up another installment soon, the arduino book is actually quite informative! Coding is still fuzzy for me but I'm getting there with it!
Image
[MOD IT] [OR BIN IT]

Almurray42
Competent
PostsCOLON 293
JoinedCOLON Wed Jun 30, 2010 11:42 pm
LocationCOLON Bridgwater, Somerset, England
CONTACTCOLON

Re: Arduino : A beginners story/guide

Postby Almurray42 » Thu Apr 12, 2012 10:56 pm

3: Coding? Huh? What? - Arduino Programs Explained! -

Right, Sorry that it's been a while since the last installment, i actually have 2 or 3 of these planned out as I have got stuck into my arduino a bit more, but as promised i'm carrying on from a beginners perspective, becuase It was frustrating trying to overcome hurdles by myself... Once again if you have any questions please do not hesitate to ask!
---------

If you started an absolute coding noob like I did, arduino programs may seem a bit of a shock at first sight. But really, DONT PANIC! They really are very simple.

The 5 Main Structures to an arduino program are as follows:

ELEMENT 1 - Introducing your program and explaining what it does, and adding comments; to help YOURSELF! (OPTIONAL)
ELEMENT 2 - Setting up YOUR parameters/integers etc. This really can help you and in some cases it is optional but in more complex programs you NEED this stage to set up certain constants.
ELEMENT 3 - Setting up the necessary pins for the program. (This Is very necessary, without it your program will not work!)
ELEMENT 4 - Writing the Main program known as the loop, because surprise surprise, it loops around and keeps on going until you power off the arduino!
ELEMENT 5 - Subroutines/Functions/Voids. These are known by many different names but they basically help to simplify your main loop, and make the program easier to change. (OPTIONAL)

Okay, so load up the very first sketch you sent to your arduino which is likely to be the Blinking LED program.

See if you can pick out the different parts of the program, but remember they might not ALL be included as this is a very simple program.
Lets use this example and go into some detail, this may seem boring but when you come to doing more complex programs you will be greatful!

CodeColon Select all

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */

void setup() {               
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}


Now, You may have noticed that this program only contains 3 of the 5 core elements of a good sketch. These are elements: 1, 3 and 4.

Element 1 is the introducing of the program and the OOP text (Out of Program). You will notice in the arduino environment that this text is greyed out, showing you that the arduino will ignore it when running the sketch.
To write Multi line text, you put the writing like this. /* INSERT MULTILINE TEXT HERE */ to write simple one line explanations you just use two slashes like this. //INSERT COMMENT HERE

Element 3 starts where you see the line "void setup()" This is pretty self explanitory and it is setting up the pins for the arduino board to run from. The command line "pinMode(13,OUTPUT)" tells the arduino that you are setting the MODE of the pin (Obviously) As some pins can be both INPUTS or OUTPUTS. "13" Shows the pin number you want to set, and OUTPUT states the connectivity mode. If you wanted to add another LED that blinks, in the setup you would write another command line below (ENDING EACH LINE WITH A SEMICOLON ";") Say you want the second led on pin 12, the next line would be pinMode(12,OUTPUT); becasue you are setting the pin as a DIGITAl OUTPUT. If there is anything that you need the arduino to run only once upon startup, these commands can also be added to the setup, after setting the pins.

In the next Post I will explain about Digital and Analog inputs and outputs, but dont worry about those yet, the key is to understand what you are writing!

Element 4 is known as the loop, which is the main section of code that the program runs through repeatedly until the arduino does not have power. This will not be run until the setups have been run when initially reset or powered up. As the programming languae is C/C++, (Tweaked) the sketch runs as WE read, from left to right, and top to bottom. In some programming everything is read at once and different things can happen simultaneously.
The command "digitalWrite" is telling the arduino to SEND something to a DIGITAL pin, think of this as a precautionary order to what you are telling it.
Next, you will need to state which pin you want it to communicate with, and what you want it to "SAY" - in this case It's communicating with Pin 13, and telling the arduino to give power to the pin.
digitalWrite commands can set the pin as HIGH, or LOW, High meaning full voltage (5v) LOW meaning no voltage (0v). Note that LOW is not disconnecting the pin, only removing its supply voltage.

The "delay(1000);" command is very simple, and literally means: Delay the arduino from continuing reading the program for 1000. The 1000 being MilliSeconds, so 1 second.

Reading this through, and looking at some of the other example programs should help you to understand the logic of arduino programming, and if you need to know any more information please do not hesitate to ask, OR check out the official arduino website, where you can find pretty much everything you need to know in terms of understanding the meaning of certain terms and how to use certain functions.This Installment is a fairly boring all text one, which I do apologise about, But I had to learn this from various different places trawling around and I think it will really help beginners to understand it by reading through this. Thanks!

Al.

P.s The next installment will be about using Both Digital Pins And Analog Pins, As both inputs and outputs!
Good Luck!

MORE HELP CAN BE FOUND AT THE OFFICIAL ARDUINO WEBSITE www.arduino.cc - Specific to this guide http://arduino.cc/en/Guide/Environment should help you!
Image
[MOD IT] [OR BIN IT]

phenoptix
Competent
PostsCOLON 744
JoinedCOLON Sat Apr 17, 2010 11:25 am

Re: Arduino : A beginners story/guide

Postby phenoptix » Wed Jun 13, 2012 8:58 pm

Great update. I'd say that although commenting is optional and part of a good sketch, its something you should really force yourself to do until it becomes second nature. Even if your comment is that something is a bodge to do x it will really help you out when you look at the code the next time, as an aid memoir.

Thanks again for writing these, they're a really fantastic account of someone starting out. Which to be fair is most of us!

bigal344
Competent
PostsCOLON 426
JoinedCOLON Thu Jun 09, 2011 11:21 pm
LocationCOLON Crewkerne,Somerset

Re: Arduino : A beginners story/guide

Postby bigal344 » Fri Jun 15, 2012 3:22 pm

Just been reading through this and I've got to say that its a great, well laid out guide, or more of a commentary.
As a beginner with Arduino, I've not long started trying to get to grips with the programming side of things, its been a similar series of trial and error experiments for me.
I've found myself using bits from one program and bits from another to achieve what I want, then spending some time figuring out what each bit does and why!! ;)
Image

Today I have been mostly Nyaning.

Almurray42
Competent
PostsCOLON 293
JoinedCOLON Wed Jun 30, 2010 11:42 pm
LocationCOLON Bridgwater, Somerset, England
CONTACTCOLON

Re: Arduino : A beginners story/guide

Postby Almurray42 » Fri Jun 15, 2012 3:50 pm

Thanks for the feedback guys, ! :D I might put up another couple of installments sometime soon! :)
Image
[MOD IT] [OR BIN IT]


Return to

Who is online

Users browsing this forum: 1 and 0 guests