Intro to Arduino Basic Arduino John Wolf (WolfDenElectronics.com)
There are 10 types of people. Those that understand binary, and those that do not understand binary. Make that 11 types. Those that understand binary, those that don't, and those who didn't grasp this joke even if they did understand binary.
Objectives – We’ll Learn Arduino pedigree Arduino Integrated Development Environment (IDE) Serial Monitor interface and other IDE features-works well with Processing Start writing code Add concepts describing physical computing as we go – Why explosions occur
More Objectives… Pulse Width Modulation (PWM) Analog signals -> Digital Driving motors – H-Bridges How servos work – feedback loops Pulling it together with Ohm’s Law Voltage regulators Power limitation of the USB port MOST IMPORTANT – Glossary of terms (learn to use a pencil again)
There are shields for everything you can think of. If not, build one and get rich. This is why Arduino is so popular… or.org How to keep up on Arduinos
Match Arduino to Application (8-bit computing – yeah!)
Texas Instruments LaunchPad MSP430 Texas Instruments BeagleBone Black Raspberry Pi Alternatives
Arduino Board of Direction “Teach the Youth” Ivrea, Italy in 2005, Massimo Banzi & David Cuartielles Open Source Hardware Atmel Processor (8-bit power) Coding is accessible (C++, Processing, ModKit and MiniBloq)
What’s an Arduino? Microcontroller board with all the support electronics built-in on the board. Has 14 digital I/O and 6 analog I/O connections. USB port, power jack, and voltages for support electronics attached to the board via the headers. Atmel AVR Computer USB Power in (7~12V) Digital I/O header Analog I/O header USB processor
Arduino IDE – resides on laptop Where you write your source code Compile, link your code and upload to the board Code checker Code layout feature Organize code and libraries available Provides a serial interface via the USB port to the Arduino board (IDE => Integrated Development Environment)
console area Serial Monitor App to interface to the Arduino via USB
How to get the Arduino S/W Go to Click the “Download” tab Now you have a choice: If you have a new computer with the latest OS… go to the turquoise box and click the appropriate download. I suggest zip files. Or… click on “Previous Releases” and download arduino This is the classic Arduino IDE that matches the basic set of Arduino boards. The new software adds-in compatibility with the new specialty boards and later OS’s.
Where to place the Arduino folder Two logical places (although – anyplace will work, because the IDE is self contained – not installed into the OS) Just put it in your My Documents folder. Better: Put it in your Program Files (86) folder at C:\Program Files(86)\ This way, it’s part of your other programs Easy to find
How to use the IDE Let’s walk through this… When you write your first sketch and go to “save as” to store it, browse to a new folder you set up in your regular My Documents directory. The IDE will remember this path an store all your sketches there, plus give you a library folder to place Third Party libraries you will want to use.
Integrated Development Environment What you do see: Area for variables The “setup()” function – void setup(); The “loop()” function – void loop(); int main(void); and Arduino.h are active, but hidden(C++)
More Arduino.h “methods” pinMode – used to tell the compiler whether a pin is an input or an output digitalWrite – whether to write-out a HIGH or LOW voltage digitalRead – read-in the pin voltage for a HIGH or LOW value analogRead – use the A/D converter to read an analog value (0-5V) analogWrite – triggers the PWM feature
Analog to Digital Convertion +5V 0V Arduino uses 10bits or 1024 individual levels from 0 to 1023 Time(or analogReads) Pins A0 to A5
Pulse Width Modulation Outputs are always digital, even when representing analog. For PWM the Arduino pin turns on then off very fast (Arduino PWM base frequency is approx 490 Hz, 980Hz on pins 5, 6) 2 ms 0 Volts 5 Volts
Let’s Get Our Hands Dirty…
USB power called USBVCC. VIN cuts off USBVCC and applies power directly to +5V regulator, which also supplies 3.3V regulator. Barrel connection basically at the VIN point. Note: VIN polarity not protected like barrel connector. Regulator can accept 7 to 12V in, 5V out at ~500ma Must be aware of Uno Power Limitations VIN Barrel Connector GND Atmel328
Breadboard has two sets of +5V rails and Gnds. Each middle row is connected across, but not down. Center gutter is there for and IC to straddle. 9V battery can supply about double the current the USB port can 9V Wall-wart usually supply about 1.5A to 2A so are good. Basic gear to start fiddling around
Beef up the +5 Volts for more elaborate projects. Many projects require current loads or other voltages only and external supply can adequately handle. GND Can use Vin to power the Arduino
Addition Power Supply Built from old ATX supply from a discarded computer Old ATX
Pwr Box 2.0 Done the same way with better construction technique.
+5V GND 0 to 5V input LED Pot 220 +5V GND 220 I = 3.8/220 I = 17mA 1.2v E = I x R So… you have to learn about electronics as we go. Next level is learning how to solder your projects together – then make PCBs. All supported by Open Source developers. Fritzing CAD layout Ohm’s Law 3.8v here (190 20ma)
Example Sketch (C++) void loop() { val = analogRead(potPin); // read the input pin with ADC 10-bits analogWrite(ledPin, val / 4); // analogRead values go from 0 to 1023, //analogWrite values from 0 to 255 } int ledPin = 9; // LED connected to digital pin 9 (PWM pin) int potPin = A3; // potentiometer connected to analog pin 3 int val = 0; // variable to store the value read void setup() { pinMode(ledPin, OUTPUT); // sets the pin as output pinMode(potPin, INPUT); // sets the pin as input } type end Last statement scales the input-read to the output capability of the PWM
Pulse Width Modulation Outputs are always digital, even when representing analog. For PWM the Arduino pin turns on then off very fast (Arduino PWM base frequency is approx 490 Hz, 980Hz on pins 5, 6) 2 ms 0 Volts 5 Volts
Initially HIGH until button is pushed, then LOW Initially LOW until button is pushed, then HIGH Either circuit only draws 0.5 ma Logic set by path of least resistance
What defines a 1 or 0 ? Logic circuits will register a “0” for voltages from 0 to about 0.8 volts. Logic circuits will register a “1” for voltages from 2 to 5 volts. (some sources quote 3v) Notice there is a dead-band where the logic level is questionable. Stay out of there in your designs. Supplies that can’t hold up the current will cause voltage sag that can reach a point where logic gets faulty
Switch bounce caught in the act 0.1ms
Debounce can also be handled in hardware. The 74HLS279 was specifically designed to do this task. Debounce is handled here in software.
Use button to select different LED colors.
int
Pot values from the serial interface