Schedule 8:00-11:00 Workshop: Arduino Fundamentals

Slides:



Advertisements
Similar presentations
Why won’t my Arduino work???? living with the lab © 2012 David Hall.
Advertisements

temperature system wiring
Using the servo library living with the lab Libraries are computer programs written to add functionality to Arduino programs. A library to control hobby.
Analog and Digital Measurements living with the lab 14 digital input / output pins 6 analog input pins © 2012 David Hall.
Waterproofing a thermistor ENGR 121 living with the lab © 2013 David Hall.
Using the Arduino to Make an LED Flash Work in teams of two! living with the lab digital I/O pins (I/O = input / output) USB cable plug power pins.
User-defined functions in Arduino sketches living with the lab © 2012 David Hall.
Calibration of conductivity sensors living with the lab.
Using Your Arduino, Breadboard and Multimeter Work in teams of two! living with the lab 1 © 2012 David Hall.
Parallax 4x20 LCD (part number 27979) with Arduino Duemilanove
Living with the lab Attaching Arduino to Boe-Bot Chassis © 2012 David Hall.
Thermistor calibration living with the lab © 2013 David Hall.
Cascaded switching of a solenoid valve living with the lab transistor relay solenoid valve © 2012 David Hall.
Assembly of conductivity flow loop living with the lab (in preparation for calibrating conductivity sensor)
Switches & whiskers on the Arduino living with the lab lever arm switches mounted to Arduino © 2012 David Hall.
Using fixed-cell references and built-in functions in Excel living with the lab © 2012 David Hall.
220  470  Gnd5V Currents Through Parallel Resistors 1 living with the lab © 2012 David Hall.
Using Hobby Servos with the Arduino living with the lab © 2012 David Hall.
Introduction to Microsoft Excel living with the lab © 2012 David Hall.
Voltage Drops Around Closed Loops 470  220  5V   220  living with the lab © 2012 David Hall.
Navigating the engineering disciplines robot challenge living with the lab © 2012 David Hall.
Kirchoff’s Current Law (KCL) living with the lab University of Pennsylvania Library and Wikipedia Gustav Kirchoff (left) and Robert Bunsen (right) Bunsen.
Adding a Barrel Jack to a Battery Pack living with the lab © 2012 David Hall.
Using for loops to control LEDs living with the lab 1 1 arduino.cc the for statement allows us to repeat a block of commands a limited number of times.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
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.
Building Circuits.
Using a SparkFun™ serial LCD with an Arduino
Controlling Servos with the Arduino
Series and Parallel Resistors
Introduction to the Arduino
Why Won’t My Arduino Work?
Using servos.
Arduino Programming Part II
calibration of conductivity sensors
Servo Library and Functions
Line Following Tips photoresistor circuits
Arduino Part 1 Topics: Microcontrollers Programming Basics
INC 161 , CPE 100 Computer Programming
Robot Assembly.
Controlling a Motor with Cascading Switches
Introduction to Transistors
RGB LEDs.
Maxbotix Ultrasonic Distance Sensor
Conductivity Sensor.
Introduction to Transistors
Servo Library and Functions
a few of my favorite sensors
using for loops to control LEDs
using the Arduino to make LEDs flash
Acquiring Data from an ADXL335 Accelerometer
Using Photoresistors with an Arduino
Introduction to Mathcad
Line Following Tips photoresistor circuit
Data Types.
analog and digital measurements
Using “if” statements.
Digital Input from Switches
Implementing Switches Using Interrupts
Arduino: For Loops.
Non-Concurrent Force Systems
IR Object Detection IR detector IR LED IR light reflected off object
Radio Frequency Transmitter and Receiver
Interfacing a Rotary Encoder with an Arduino
Evaluating Design Alternatives
Counting Servo Gear Teeth (FS90R Servos)
Static Equilibrium Problem
Reservoir Loop.
Arduino Uno circuit basics
Gearmotor Efficiency W table top gearmotor pulley string.
Presentation transcript:

Schedule 8:00-11:00 Workshop: Arduino Fundamentals 11:00-12:00 Workshop: Build a follower robot 1:30-3:00 Symposium: Group 1 Sanford Bernhardt, Sangster, Kumfer, Michalaka 3:10-5:00 Workshop: Build a speedometer 5:15-7:30 Dinner and Symposium: Group 2 Strevett, Walewski, Villiers, Siegnethaler

Arduino Workshop for Transportation Engineering Educators

DISCLAIMER & USAGE The content of this presentation is for informational purposes only and is intended only for students attending Louisiana Tech University. The author of this information does not make any claims as to the validity or accuracy of the information or methods presented. Any procedures demonstrated here are potentially dangerous and could result in injury or damage. Louisiana Tech University and the State of Louisiana, their officers, employees, agents or volunteers, are not liable or responsible for any injuries, illness, damage or losses which may result from your using the materials or ideas, or from your performing the experiments or procedures depicted in this presentation. If you do not agree, then do not view this content. The copyright label, the Louisiana Tech logo, and the “living with the lab” identifier should not be removed from this presentation. You may modify this work for your own purposes as long as attribution is clearly provided.

Building a speedometer Dr. Marisa Orr Monday 3:10-5:00

Calculating speed Need 2 distances and the time between them New command: millis() – outputs the time (in milliseconds) since the program was reset Take a distance measurement, wait a moment, take another

Distance

Sonar The sensors have a limited range, so we need to filter out bad readings Using the serial monitor decide what range of values you want to use for calculating speed pick a high and a low

Speed

Speed (cont.)

Add an LCD (Liquid Crystal Display)

using a parallax serial LCD with an Arduino Parallax 4x20 LCD (part number 27979) with Arduino Duemilanove

a servo extension is handy for wiring the LCD to the Arduino LCD wiring RX = wire to receive serial data from Arduino 5V = power wire GND = ground wire a servo extension is handy for wiring the LCD to the Arduino

Arduino wiring TX = wire to transmit serial data from digital I/O pin to LCD ground 5V power

LCD and Arduino together

Programming Text: “Louisiana Tech University” is displayed, with character locations chosen to center the text on the first two lines of the LCD Integers: The text “i=“ is printed followed by an integer that varies from 1 to 10 Floating Point Numbers: The text “x=“ is printed followed by a number with four numerals printed to the right of the decimal; the value here ranges from 0.0010 to 0.0100

Cursor Position & Printing to the 4x20 LCD row 0, position 3 2x16 Cursor Position & Printing to the 4x20 LCD Serial.write(131); // move cursor to row 0 position 3 Serial.write("Louisiana Tech"); // print “Louisiana Tech” at (0,3) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 1 2 3

Setting the Communication Rate The dip switches on the back of the LCD are set to SW1=off and SW2=on. This causes the LCD to look for data arriving at a rate of 9600 bits per second. The sketch must include . . . . . . so that the Arduino will know to send data to the LCD at a rate of 9600 bits per second. Serial.begin(9600);

A Complete Sketch This sketch does not require a special library (only the Serial commands commonly used in sketches) /*****************************************************************************/ /* David Hall September 2012 */ /* Example program using a Parallax 4x20 LCD to output text and numbers. */ /* The following screen is printed: */ /* */ /* --------------------- */ /* | Louisiana Tech | */ /* | University | */ /* | | */ /* | i=8 x=0.0080 | where 1<=i<=10 and 0.0000<=x<=0.0100 */ /* The program prints out both integers and floating point numbers. The */ /* floating point number is printed to four decimal places. */ /* A partial listing of commands recognized by the LCD is provided below. */ /* See the data sheet for the LCD on the Parallax web site for more details. */ /* Serial.write(8) - move cursor one space left */ /* Serial.write(9) - move cursor one space right */ /* Serial.write(10) - move cursor down one line */ /* Serial.write(12) - clear screen and move cursor to top left */ /* Serial.write(13) - carriage return (will wrap if on last line) */ /* Serial.write(17) - turn backlight on */ /* Serial.write(18) - turn backlight off */ /* Serial.write(21) - turn display off */ /* Serial.write(22) - turn display on, cursor off, no blink */ /* Serial.write(23) - turn display on, cursor off, character blink */ /* Serial.write(24) - turn display on, cursor on, no blink (default) */ /* Serial.write(25) - turn display on, cursor on, character blink */ /* Serial.write(128) moves the cursor to row 0 and position 0 */ /* row and position commands are shown below for all 80 character positions */ /* ROW 0: 128=(0,0) 129=(0,1) 130=(0,2) 131=(0,3) 132=(0,4) */ /* 133=(0,5) 134=(0,6) 135=(0,7) 136=(0,8) 137=(0,9) */ /* 138=(0,10) 139=(0,11) 140=(0,12) 141=(0,13) 142=(0,14) */ /* 143=(0,15) 144=(0,16) 145=(0,17) 146=(0,18) 147=(0,19) */ /* ROW 1: 148=(1,0) 149=(1,1) 150=(1,2) 151=(1,3) 152=(1,4) */ /* 153=(1,5) 154=(1,6) 155=(1,7) 156=(1,8) 157=(1,9) */ /* 158=(1,10) 159=(1,11) 160=(1,12) 161=(1,13) 162=(1,14) */ /* 163=(1,15) 164=(1,16) 165=(1,17) 166=(1,18) 167=(1,19) */ /* ROW 2: 168=(2,0) 169=(2,1) 170=(2,2) 171=(2,3) 172=(2,4) */ /* 173=(2,5) 174=(2,6) 175=(2,7) 176=(2,8) 177=(2,9) */ /* 178=(2,10) 179=(2,11) 180=(2,12) 181=(2,13) 182=(2,14) */ /* 183=(2,15) 184=(2,16) 185=(2,17) 186=(2,18) 187=(2,19) */ /* ROW 3: 188=(3,0) 189=(3,1) 190=(3,2) 191=(3,3) 192=(3,4) */ /* 193=(3,5) 194=(3,6) 195=(3,7) 196=(3,8) 197=(3,9) */ /* 198=(3,10) 199=(3,11) 200=(3,12) 201=(3,13) 202=(3,14) */ /* 203=(3,15) 204=(3,16) 205=(3,17) 206=(3,18) 207=(3,19) */ /* To print variables to the LCD, you need to use the Serial.print() */ /* command instead of the Serial.write() command. For example, the command */ /* Serial.print(x,4) will send variable "x" to the LCD with four digits */ /* beyond the decimal point. */ See the Parallax website (www.parallax.com) for more details. Custom characters and other features are available for this LCD. When developing your sketch, print things to the LCD screen only once if they do not change. For example, the text in this sketch is printed once in setup(), while the variables are printed repeatedly in loop(). void setup() { Serial.begin(9600); // use a baud rate of 9600 bps pinMode(1,OUTPUT); // set pin1 as an output (pin1=TX) Serial.write(12); // clear screen & move to top left position Serial.write(131); // move cursor to row 0, position 3 Serial.write("Louisiana Tech"); // print a text string starting at (0,3) Serial.write(153); // move cursor to row 1, position 5 Serial.write("University"); // print a text string starting at (1,5) Serial.write(190); // move cursor to row 3, position 2 Serial.write("i= x="); // print text string at (3,2) Serial.write(22); // turn cursor off to keep screen clean } void loop() { float x=0.0; for (int i=1;i<=10;i++) { x=x+0.0010; // add 0.001 to variable x Serial.write(192); // move cursor to row 3, position 4 Serial.print(i); // print i at the current cursor position Serial.write(" "); // print blanks to cover previous printing Serial.write(200); // move cursor to row 3, position 12 Serial.print(x,4); // print x to 4 decimal places delay(1000); // delay 1 second between printing numbers

Other LCD commands Serial.write(#) 8 = Backspace / Left - The cursor is moved one position to the left. The command doesn’t erase the character. 9 = Right - The cursor is moved one position to the right. The command doesn’t erase the character. 10 = Line Feed - The cursor is moved down one line. For the two line LCD model, if on line 0 it goes to line 1. If on line 1, it wraps around to line 0. The horizontal position remains the same. 12 = Form Feed - The cursor is moved to position 0 on line 0 and the entire display is cleared. Users must pause 5mS after this command. 13 = Carriage Return – For the two line LCD model, if on line 0 the cursor is moved to position 0 on line 1. If on line 1, it wraps around to position 0 on line 0. 17 = Turn backlight on (only on models 27977, 27979) 18 = Turn backlight off (Default) 21 = Turn the display off 22 = Turn the display on, with cursor off and no blink 23 = Turn the display on, with cursor off and character blink 24 = Turn the display on, with cursor on and no blink (Default) 25 = Turn the display on, with cursor on and character blink

LCD practice void setup() { Serial.begin(9600); // use a baud rate of 9600 bps pinMode(1,OUTPUT); // set pin1 as an output (pin1=TX) Serial.write(12); // clear screen & move to top left position Serial.write(129); // move cursor to row 0, position 1 Serial.write("Louisiana Tech"); // print a text string starting at (0,1) Serial.write(149); // move cursor to row 1, position 1 Serial.write("i= x="); // print text string at (1,1) (four spaces after “i=“ Serial.write(22); // turn cursor off to keep screen clean } void loop() { float x=0.0; for (int i=1;i<=10;i++) { x=x+0.0010; // add 0.001 to variable x Serial.write(150); // move cursor to row 1, position 2 Serial.print(i); // print i at the current cursor position Serial.write(" "); // print blanks to cover previous printing Serial.write(167); // move cursor to row 1, position 9 Serial.print(x,4); // print x to 4 decimal places delay(1000); // delay 1 second between printing numbers There are 2 mistakes in this code, try it and see if you can find them

living with the lab After downloading your sketch, you may need to press the Arduino reset button to remove “gibberish” that may be printed on the LCD. reset button

Now add a LCD display to your speedometer code

Dinner and Presentations at the Davison Complex

1. plug in Arduino 2. we will be using digital pin 2 as an output to make an LED go on and off 14 digital I/O pins (I/O = input / output) connect computer to USB plug

the circuit

enter and run the following sketch void setup() { // initialize the digital pin 2 as an output pinMode(2, OUTPUT); } void loop() { digitalWrite(2, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(2, LOW); // set the LED off delay(500); // wait for 500 ms

how the sketch works infinite loop HIGH = 5V and LOW = 0V (Always!!!!) void setup() { pinMode(2, OUTPUT); } void loop() { digitalWrite(2, HIGH); delay(1000); digitalWrite(2, LOW); delay(500); initialize pin 0 as an output infinite loop set pin 0 to LOW (0V) wait 500 ms set pin 0 to HIGH (5V) wait 1000 ms HIGH = 5V and LOW = 0V (Always!!!!) time (ms) voltage (V) 0V 5V 500 ms 1000 ms

now experiment on your own! Try changing the time to 1.5 seconds on and 1 second off Connect the resistor to digital pin 5 and change the program to match Blink out SOS in Morse code (dot-dot-dot-dash-dash-dash-dot-dot-dot) three short pulses (0.25 seconds each) followed by . . . three long pulses (0.75 second each) followed by . . . a brief pause (1 second) repeat a through d using an infinite loop

The End  Find each command in the reference section of arduino.cc (discuss each command with others at your table) void setup() { // initialize the digital pin as an output: pinMode(0, OUTPUT); } void loop() { digitalWrite(0, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(0, LOW); // set the LED off delay(500); // wait for 500 ms The End 