SAMI MAKERSPACE MAKE: AN ELECTRONICS WORKSHOP. ARDUINO BASICS Credit to: Sparkfun and Linz Craig, Nick Poole, Prashanta Aryal, Theo Simpson, Tai Johnson,

Slides:



Advertisements
Similar presentations
Lab7: Introduction to Arduino
Advertisements

Mini-SumoBot Construction and Programming
Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
How to use Arduino By: Andrew Hoffmaster.
Embedded Sumo 1T4 – 1T5 UTRA.
Re-programming the Simon Says with Arduino Linz Craig, Brian Huang.
Introduction to Arduino Programming January MER-421:Mechatronic System Design.
Intro to Arduino with LilyPad Make a MakerSpace, Artisan’s Asylum Linz Craig, Chris Taylor, Mike Hord & Joel Bartlett.
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Introduction.
Embedded Programming and Robotics Lesson 1 Basic Electricity and Electronics Transistor Basics Lesson 1 -- Basic Electricity1.
 Main Components:  Sensors  Micro controller  Motor drivers  Chasis.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
Intro to Arduino Zero to Prototyping in a Flash! Material designed by Linz Craig, Nick Poole, Prashanta Aryal, Theo Simpson, Tai Johnson, and Eli Santistevan.
Intro to Arduino Zero to Prototyping in a Flash! Material designed by Linz Craig, Nick Poole, Prashanta Aryal, Theo Simpson, Tai Johnson, and Eli Santistevan.
Embedded Programming and Robotics
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Arduino Part 1 Topics: Microcontrollers Programming Basics: structure and variables Digital Output Analog to Digital Conversion.
Colorado Space Grant Consortium Gateway To Space ASEN 1400 / ASTR 2500 Class #12 Gateway To Space ASEN 1400 / ASTR 2500 Class #12 T-58.
Dean Brock, Rebecca Bruce and Susan Reiser, CCSC SE 2009 Using Arduino Material taken from Todbot blog Bionic Arduino Todbot blog Bionic ArduinoTodbot.
Intro to Arduino Zero to Virtual Prototyping in Seven Hours
ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra.
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Introduction to the Arduino
Intro to Arduino Programming. Draw your circuits before you build them From Arduino 330 Ohm From Arduino 330 Ohm From Arduino 330 Ohm.
Tweaking Your Simon Adding a photoresistor and changing code Instruction by Pete Lewis and Linz Craig.
Overview What is Arduino? What is it used for? How to get started Demonstration Questions are welcome at any time.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Microprocessors Tutorial 1: Arduino Basics
ARDUINO 1. Basics  Comments  /* * Blink * * The basic Arduino example. Turns on an LED on for one second, * then off for one second, and so on... We.
Microcontroller Hands-on Workshop #2 Ahmad Manshad New Mexico State University Institute of Electrical and Electronics Engineers October 31, 2009.
Microcontrollers, Microcomputers, and Microprocessors
Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Getting Started.
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
Embedded systems and sensors 1 Part 2 Interaction technology Lennart Herlaar.
1 Introduction to Haptics Introduction to the Hapkit board Allison M. Okamura Stanford University.
Introduction to Arduino A very basic intro to Arduino, the IDE and the Servos class.
Introduction to Programming the Arduino Dr Gaw 3/21/14.
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
Pulse-Width Modulation: Simulating variable DC output
1 Microcontrollers. 2 Programmers work in the virtual world Machinery works in the physical world Microcontrollers connect the virtual and physical world.
Having fun with code, using Arduino in a middle school CS classroom
Arduino.
Getting Started: Building & Programming
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Microcontroller basics
Val Manes Department of Math & Computer Science
Microprocessors Tutorial 1: Arduino Basics
Arduino & its hardware interfacing
UTA010 : Engineering Design – II
An Arduino Workshop A Microcontroller.
Welcome to Arduino A Microcontroller.
UCD ElecSoc Robotics Club 2017/2018
Arduino Part 1 Topics: Microcontrollers Programming Basics
Introduction to Arduino Microcontrollers
Introduction to Arduinos
What is an Arduino ? Open Source electronic prototyping platform based on flexible easy to use hardware and software.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Welcome to Digital Electronics using the Arduino Board
Arduino : Introduction & Programming
Programming 2: The Arduino IDE & First Sketches
Aeroponic Engineering and Vertical Farming
Lab #1: Getting Started.
Arduino Uno circuit basics
Setting up a basic program with Arduino
Introduction to Arduinos
Introduction to arduino
Introduction to Arduino IDE and Software
Presentation transcript:

SAMI MAKERSPACE MAKE: AN ELECTRONICS WORKSHOP

ARDUINO BASICS Credit to: Sparkfun and Linz Craig, Nick Poole, Prashanta Aryal, Theo Simpson, Tai Johnson, and Eli Santistevan

THIS PRESENTATION: Part One: Hardware Getting around and Arduino Getting connected The breadboard A simple circuit Part Two: Software The integrated development environment Part Three: Programming Inputs and outputs Some conventions First Program: Blink Variables Analog versus digital Pulse wave modulation Second Program: Fade Third Program: Button Conditional statements Serial communication

PART ONE: THE HARDWARE ARDUINO, USB CABLE, LAPTOP, BREADBOARD

GETTING AROUND AN ARDUINO THE “UNO” MODEL

Analog INPUTS Digital I\O PWM(3, 5, 6, 9, 10, 11) PWR INUSB (to Computer) SCL\SDA (I2C Bus) POWER 5V / 3.3V / GND RESET

LET’S GET CONNECTED!

PLUG IN YOUR ARDUINO

BREADBOARDS RAPID AND SOLDER-FREE PROTOTYPING!

PROTOTYPING CIRCUITS SOLDERLESS BREADBOARD One of the most useful tools in an engineer or Maker’s toolkit. The three most important things: A breadboard is easier than soldering A lot of those little holes are connected, which ones? Sometimes breadboards break

WHAT’S A BREADBOARD?

SOLDERLESS BREADBOARD Each row (horiz.) of 5 holes are connected. Vertical columns – called power bus are connected vertically

A SIMPLE CIRCUIT LIGHT UP AN LED USING THE ARDUINO

USE THE BREADBOARD AND ARDUINO TO BUILT A SIMPLE CIRCUIT Use the breadboard to wire up a single LED with a 330 Ohm Resistor (Orange- Orange-Brown). Note: the longer leg on the LED is the positive leg and the shorter leg is the negative

PART TWO: THE SOFTWARE INTEGRATED DEVELOPMENT ENVIRONMENT

THE INTEGRATED DEVELOPMENT ENVIRONMENT

OPEN UP “ARDUINO” APPLICATION Look for the icon on the desktop of the white clam-shell computers. You can also download the application for free to your own computers (you may need to also install the proper drivers)

ARDUINO: INTEGRATED DEVELOPMENT ENVIRONMENT (IDE) Two required functions / methods / routines: void setup() { // runs once } void loop() { // repeats } error & status messages

SETTINGS: TOOLS  SERIAL PORT Your computer communicates to the Arduino microcontroller via a serial port  through a USB-Serial adapter. Check to make sure that the drivers are properly installed.

SETTINGS: TOOLS  BOARD Next, double-check that the proper board is selected under the Tools  Board menu.

PART 3: PROGRAMMING! CODE FOR THE MASSES

CONCEPT: INPUTS VS. OUTPUTS

CONCEPTS: INPUT VS. OUTPUT Referenced from the perspective of the microcontroller (electrical board). Inputs is a signal / information going into the board. Output is any signal exiting the board. Almost all systems that use physical computing will have some form of output. What are some examples of Outputs?

CONCEPTS: INPUT VS. OUTPUT Inputs is a signal / information going into the board. Output is any signal exiting the board. Examples: Buttons Switches, Light Sensors, Flex Sensors, Humidity Sensors, Temperature Sensors… Examples: LEDs, DC motor, servo motor, a piezo buzzer, relay, an RGB LED

YOU DON’T NEED TO SPEAK BINARY! The Arduino IDE allows you to work in a “high-level programming language.” The code you write is readable to humans (with a little training) The IDE does the hard work of making your code something that the chip on the Arduino understands:

SUB-ROUTINES/FUNCTIONS/COMMANDS Arduino uses pre-made sub-routines (small programs) to make your life easier. Programs like: delay() if() loop() Most programs need an input (what they are acting on) and give an output (usually a numerical value) The names of these programs (like most things in Arduino) are case sensitive, so type carefully! digitalWrite() is not the same as digitalwrite() Can you guess what these do?

pinMode(pin, INPUT/OUTPUT); ex: pinMode(13, OUTPUT); digitalWrite(pin, HIGH/LOW); ex: digitalWrite(13, HIGH); delay(time_ms); ex: delay(2500); // delay of 2.5 sec. // NOTE: -> commands are CASE-sensitive

digitalWrite() analogWrite() digitalRead() if() statements / Boolean analogRead() Serial communication BIG 6 CONCEPTS

SOME CONVENTIONS: CURLY BRACKETS When you call a sub-routine every thing that happens in the program should be contained in curly brackets: Everything between the curly brackets {..} is part of the loop function.

SOME CONVENTIONS: SEMICOLONS Any line of code that isn’t calling a sub- routine, or is a sub-routine that is only one line long should always end with a semicolon (;) If you forget these, you will get errors when you try to “compile” the code!

SOME CONVENTIONS: COMMENTS It’s easier to get lost in your own code than you may think. Leave comments to yourself, especially before you do something “tricky.” They are not needed to make the program work, but can save you a lot of trouble in the long run.

FIRST PROGRAM: BLINK LET’S MAKE AN LED BLINK!

PLAN YOUR ATTACK WITH A FLOWCHART Initialize Turn LED ON Wait Turn LED OFF Wait

1. PUT IN THE “BARE MINIMUM” The “setup” function runs once and will lock in any settings you want. The “loop” function will run for as long as the Arduino has power!

2. INITIALIZE THE LED PIN AS A “OUTPUT” Use the “pinMode” command. This requires two inputs (or arguments). You must tell it what pin to act on (13 in this case) and whether that pin is an OUTPUT or INPUT (this is case sensitive).

3. TURN ON THE LED FOR ONE SECOND

4. TURN OFF THE LED FOR ONE SECOND

5. REPEAT! Once the end of the program is reached, it will go to the beginning of loop() and run it again. And again. And again….

SOME EXTRA CHALLENGES… Make the light blink with a 200 ms interval. Change the blink to mimic a heart beat. What’s the fastest blink your eye can detect? Add two, three, or four LED’s. (each LED will need its own 330 Ohm resistor).

CONCEPT: VARIABLES

Declaring variables Types of variables Variable scope Initializing variables Variable rollover

TYPES OF VARIABLES 8 bits16 bits32 bits byte char int unsigned int long unsigned long float

DECLARING VARIABLES AND SCOPE OF VARIABLES Variable Scope Global Vs. Function-level

INITIALIZING A VARIABLE: EXAMPLE Compare this code our early “blink” program. There is an “int” type variable declared. An integer (no decimal) The variable is named “ledPin” ledPin is initialized to the value “5” This is a “global” variable since it was declared outside of a function. All other functions are able to “call” ledPin and they can change its value Notice how easy it would be to change the pin on your circuit that has the LED connected to it?

CONCEPT: DIGITAL VERSUS ANALOG

CONCEPTS: ANALOG VS. DIGITAL Microcontrollers are digital devices – ON or OFF. Also called – discrete. Analog signals are anything that can be a full range of values. What are some examples? How can we get 3V from a microcontroller that can only be on (5V) or off (0V)? 5 V 0 V 5 V 0 V

CONCEPT: PWM PULSE WAVE MODULATION

CONCEPT: PULSE WAVE MODULATION To create an analog signal, the digital microcontroller uses a technique called PWM. By varying the duty cycle, we can mimic an “average” analog voltage. Pulse Width Modulation (PWM)

SECOND PROGRAM: FADE LET’S DIM THAT LED!

analogWrite(pin, val); pin – refers to the OUTPUT pin (limited to pins 3, 5, 6, 9, 10, 11.) – denoted by a ~ symbol val – 8 bit value (0 – 255). 0 => 0V | 255 => 5V PROJECT #2 – FADING INTRODUCING A NEW COMMAND…

THIRD PROGRAM: BUTTON CONTROL THAT LED WITH DIGITAL INPUT!

USE AN EXAMPLE PROGRAM In Arduino, open up: File  Examples  02.Digital  Button

DIGITAL INPUT: BUTTON to Digital Pin 2

DIGITAL INPUT: BUTTON This is just like our 1 st circuit!

DIGITAL INPUT Connect digital input to your Arduino using Pins # 0 – 13 (Although pins # 0 & 1 are also used for programming) Digital Input needs a pinMode command: pinMode (pinNumber, INPUT); Make sure to use ALL CAPS for INPUT To get a digital reading: int buttonState = digitalRead (pinNumber); Digital Input values are only HIGH (On) or LOW (Off)

DIGITAL SENSORS Digital sensors are more straight forward than Analog No matter what the sensor there are only two settings: On and Off Signal is always either HIGH (On) or LOW (Off) Voltage signal for HIGH will be a little less than 5V on your Uno Voltage signal for LOW will be 0V on most systems

USING CONDITIONAL STATEMENTS IF THIS, THEN THAT!

CONDITIONAL STATEMENTS: IF()

void loop() { int buttonState = digitalRead(5); if(buttonState == LOW) {// do something } else { // do something else } CONDITIONAL STATEMENTS: IF() DIG INPUT

BOOLEAN OPERATORS Description ( ) == ( ) is equal? ( ) != ( ) is not equal? ( ) > ( ) greater than ( ) >= ( ) greater than or equal ( ) < ( ) less than ( ) <= ( ) less than or equal

SERIAL COMMUNICATION KEEPING AN EYE ON YOUR PROGRAM…

USING SERIAL COMMUNICATION Method used to transfer data between two devices. Arduino dedicates Digital I/O pin # 0 to receiving and Digital I/O pin #1 to transmit. Data passes between the computer and Arduino through the USB cable. Data is transmitted as a string of zeros (‘0’) and ones (‘1’).

SERIAL MONITOR & ANALOGREAD() Initializes the Serial Communication 9600 baud data rate prints data to serial bus

SERIAL MONITOR & ANALOGREAD() Opens up a Serial Terminal Window

EXAMPLE void loop ( ) { Serial.print(“Hands on “) ; Serial.print(“Learning ”) ; Serial.println(“is Fun!!!”) ; } Serial.print adds to the same line. Serial.println adds to the line, then “returns” (starts a new line).

USING SERIAL COMMUNICATION TO DEBUG AND TROUBLESHOOT Let’s use serial communication to watch what is happening in our “button” program.