Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 SAMI MAKERSPACE MAKE: AN ELECTRONICS WORKSHOP

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

3 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

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

5 GETTING AROUND AN ARDUINO THE “UNO” MODEL

6

7 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

8 LET’S GET CONNECTED!

9 PLUG IN YOUR ARDUINO

10 BREADBOARDS RAPID AND SOLDER-FREE PROTOTYPING!

11 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

12 WHAT’S A BREADBOARD?

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

14 A SIMPLE CIRCUIT LIGHT UP AN LED USING THE ARDUINO

15 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

16

17

18 PART TWO: THE SOFTWARE INTEGRATED DEVELOPMENT ENVIRONMENT

19 THE INTEGRATED DEVELOPMENT ENVIRONMENT

20 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)

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

22 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.

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

24 PART 3: PROGRAMMING! CODE FOR THE MASSES

25 CONCEPT: INPUTS VS. OUTPUTS

26 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?

27 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

28 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:

29 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?

30 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

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

32 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.

33 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!

34 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.

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

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

37 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!

38 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).

39 3. TURN ON THE LED FOR ONE SECOND

40 4. TURN OFF THE LED FOR ONE SECOND

41 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….

42 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).

43 CONCEPT: VARIABLES

44 Declaring variables Types of variables Variable scope Initializing variables Variable rollover

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

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

47 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?

48 CONCEPT: DIGITAL VERSUS ANALOG

49 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

50 CONCEPT: PWM PULSE WAVE MODULATION

51 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)

52 SECOND PROGRAM: FADE LET’S DIM THAT LED!

53 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…

54 THIRD PROGRAM: BUTTON CONTROL THAT LED WITH DIGITAL INPUT!

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

56 DIGITAL INPUT: BUTTON to Digital Pin 2

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

58 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)

59 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

60

61 USING CONDITIONAL STATEMENTS IF THIS, THEN THAT!

62 CONDITIONAL STATEMENTS: IF()

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

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

65 SERIAL COMMUNICATION KEEPING AN EYE ON YOUR PROGRAM…

66 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’).

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

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

69 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).

70

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


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

Similar presentations


Ads by Google