48
Getting Started with Arduino James Michener K9JM These slides are available at k9jm.com

Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

  • Upload
    buidien

  • View
    221

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Getting Started with Arduino

James Michener K9JM

These slides are available at

k9jm.com

Page 2: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Why Arduino?

It was designed as a teaching tool in Europe. The goal was to get the student up and running after the first day of class. Where one can start running real programs.

This is your first day of class….

And your second day of class….

Page 3: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

What we will do: Getting started with

● Arduino IDE● Arduino Driver Install● Visual Studio + Visual Micro Arduino Extension● "Hello World" to a serial port / LCD● Example on-line of an Arduino RF voltmeter

Page 4: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Arduino Pros

● Up and running fast● Wide variety of hardware choices with a

common libraries and development platform● Built in / Intergrated: USB, Serial, EEPROM,

RAM, Flash, I2C, SDI, A/D, PWM● Full gcc g++ language support● Hundreds of prebuilt add on hardware

● LCD displays, touch screens, DDS, motor controllers, clocks, ethernet, WiFi, GSM

Page 5: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Arduino Con

Not good for big data / high speed applications.

Support only for C and C++ programming language. (no Java, Ruby, Lisp, Fortran, Python...etc)

Consider the Raspberry Pi, Beaglebone Black.... but you need to good at Unix

Page 6: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Step One:

Get a cup of coffee... especially if you're on DSL

Estimated time to download and install everything is two hours.

Page 7: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Download Arduino Software

● https://www.arduino.cc/en/Main/Software● Gets everything....

● Atmel gcc compilers● Libraries● Board Descriptions● Arduino IDE● Arduino Windows Drivers

Page 8: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Download Arduino Software

Page 9: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Hint:

I always go for the "Windows ZIP file for non admin install". The reason is, I can control where on my machine to install it AND (most important) you can have multiple versions of Arduino installed at one time. This is important when they come out with a new release (about every month).

Page 10: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Do you wish to donate?

Page 11: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Expand the zip file

The browser will save the zip file in it's 'download' directory.

Unzip the folder into your 'home' directory

(eg C:\Users\James )

This can be done by drag and dropping the folder

Short coffee break

Page 12: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Drag and Drop Folder from Zip

Page 13: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Make a desktop shortcutIn the new arduino directory, right click on arduino.exe and and click on 'create short cut'

Page 14: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Move short cut to desktop

● Drag and drop the short cut to the desktop● Rename the shortcut to Arduino-version#

● Hint: use F2 key for renaming a fime● Hint: you can delete the downloaded zip file

Page 15: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Double click on desktop icon

Uncheck 'Always ask before opening this file' and hit Run

Page 16: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Arduino IDE (Integrated Development Environment)

Page 17: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Driver Install

Note: Because you did not do an administrative install… Windows does not know where the Arduino drivers are located….

Plug in the USB cable connected to the Arduino and Windows will be unable to find the driver for this device.

Page 18: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Windows Fails to find driver. Hit Close

Page 19: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Open 'Computer Management' and look for an 'Unknown Device'

Page 20: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Right click on unknown device and select "Update driver software"

Then select Browse my computer for driver software

Page 21: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Browse to the Arduino driver directory

Page 22: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Say okay... and the driver is installed! Note the COM port

number

Page 23: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

A better IDE

Earlier this year, Microsoft released FOR FREE, a version of their Visual Studio development suite call Visual Studio Community. They also opened up how to create

Page 24: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Visual Studio Community Download

https://www.visualstudio.com/downloads/download-visual-studio-vs

Page 25: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Install Visual Studio Community

● Either take a typical install, or custom, but make sure that C and C++ elements are installed!

● Installation can take up to an hour, so you might consider going for a walk.

Page 26: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Take either Typical or Custom

Page 27: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Minimum C++ and Extensibility Tools

Page 28: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Click Install

Page 29: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

One hour later....Microsoft sign in

Page 30: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Sign in or create a new account

Page 31: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Just about there...

Page 32: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Visual Micro Install Extension

Open Visual Studio Community and in the menu select Tools, and Extensions and Updates.

Page 33: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

On the left click on 'Online'

Page 34: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

There are hundreds of extensions and pages of extensions!

Note: the '1 2 3 4 5 >' at the bottom, this selects the pages.Find the “Arduino IDE for Visual Studio”

Page 35: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Search for and select Arduino IDE Select and hit download

Page 36: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

VSIX runs

Page 37: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Click okay... then click Restart Now

Page 38: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Enter location of Arduino IDE then hit OK

Page 39: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Added tool bars and menu items

Page 40: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Congratulations!

You are ready to go... more readinghttp://www.visualmicro.com/page/User-Guide.aspx

https://www.arduino.cc/en/Guide/HomePage

Page 41: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Hello World Example

● I used an I2C (TWI) LCD panel..less wires● Wiring – Clock = Uno pin A5 Data = Uno pin A4● Using I2C LCD ... what is the I2C Address??

● Warning I2C address is 7 bits and it may or may not be shifted left by one bit

● When in doubt 'sniff' it...

Page 42: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Important to understand about AVR Arduinos (eg Uno, Mega)

● Processors have very limited RAM● Uno has 2 kilobytes● Mega has 8 kilobytes

● Not much space for a 'heap'● Avoid using 'new' or 'malloc'● Avoid using STL● Avoid using RAM except as needed!

Page 43: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

C / C++ notes

● Atmel compilier supports C++11● Not all Arduino libraries support C++11● Compilier supports C++11 STL changes● For AVR (Uno / Mega) avoid STL elements that

use malloc and new● Bottom line: Stick with C/C++ 98

Page 44: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Important to understand about AVR Arduinos (eg Uno, Mega)

● Processors use a 'Harvard Architecture'● Different instructions to address data or

SRAM● Data in Program Memory must be moved to

RAM

Page 45: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Important to understand about AVR Arduinos (eg Uno, Mega)

const char foo[] = "K9JM";

Serial.print("Hello World");

--- strings are in RAM!

const char foo[] PROGMEM = "K9JM";

Serial.print(F("Hello World"));

--- strings are in Program Memory

Page 46: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

Arduino SAM processors(eg Due)

32 bit flat address space

96K of RAM

512K of Flash program memory

any 'const' is stored in Flash

Due compilier will properly handel (F(" ")) and PROGMEM functions, but are not required.

Page 47: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

FYI

● Visual micro stores all objects and 'hex' files in a directory. Note: AppData is a hidden directory

/Users/James/AppData/Local/V.Micro/Arduino/Build

Page 48: Getting Started with Arduino - K9JM.COMk9jm.com/ArduinoGettingStarted.pdf · Getting Started with Arduino ... Full gcc g++ language support ... Arduino installed at one time. This

In case Visual Studio Express does not generate a desk top icon...

Go to this directory and right click on devenv.exe and click on 'Create shortcut'