-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab01.html
327 lines (296 loc) · 14.7 KB
/
lab01.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!DOCTYPE HTML>
<!--
Linear by TEMPLATED
templated.co @templatedco
Released for free under the Creative Commons Attribution 3.0 license (templated.co/license)
-->
<html>
<head>
<title>Lab01</title>
<link href="shrimp.ico" rel="icon">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link href="https://fonts.googleapis.com/css?family=Roboto:100" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/skel.min.js"></script>
<script src="js/skel-panels.min.js"></script>
<script src="js/init.js"></script>
<noscript>
<link rel="stylesheet" href="css/skel-noscript.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/style-desktop.css" />
</noscript>
</head>
<body>
<!-- Header -->
<div id="header">
<div id="nav-wrapper">
<!-- Nav -->
<nav id="nav">
<ul>
<li><a href="index.html">Homepage</a></li>
<li><a href="about.html">About</a></li>
<li><a href="team-contract.html">Team Contract</a></li>
<li><a href="meeting-minutes.html">Meeting Minutes</a></li>
<li><a href="ethics.html">Ethics Case Study</a></li>
</ul>
</nav>
</div>
<div class="container">
<!-- Logo -->
<div id="logo" style="font-family: Ubuntu; font-weight: normal">
<h1><a href="index.html">team-shrimp-cracker</a></h1>
<span class="tag">A robotics team dedicated to jamming the most flavor in a little robot.</span>
</div>
</div>
</div>
<!-- Header -->
<!-- Main -->
<div id="main">
<div class="container">
<div class="row">
<!-- Sidebar -->
<div id="sidebar" style="width: 18%;" class="4u">
<section>
<header>
<h2>LABWORK</h2>
</header>
<div class="row">
<section class="6u">
<ul class="default">
<li><a href="lab01.html">Lab01</a></li>
<li><a href="lab02.html">Lab02</a></li>
<li><a href="lab03.html">Lab03</a></li>
<li><a href="lab04.html">Lab04</a></li>
<li><a href="m01.html">Milestone01</a></li>
<li><a href="m02.html">Milestone02</a></li>
<li><a href="m03.html">Milestone03</a></li>
<li><a href="m04.html">Milestone04</a></li>
<li><a href="competition.html">Competition</a></li>
</ul>
</section>
</div>
</section>
</div>
<!-- Content -->
<div id="content" class="8u skel-cell-important" style="width:77%;">
<section>
<header style="margin-bottom:5%; ">
<h2>LAB01: MICROCONTROLLERS</h2>
</header>
<div class="grey" >
<h2 style="font-size:200%; margin-bottom: 2%;">Objective</h2>
<p>In this lab we learned how to use the Arduino Uno and IDE, taking digital and analog inputs and outputting digital and PWM signals.</p>
<p style="font-size:120%; margin-bottom:0;">Equipment</p>
<ul style="margin-left:5%;">
<li>* 1 Arduino Uno</li>
<li>* 1 USB A/B cable</li>
<li>* 1 Continuous rotation servos</li>
<li>* 1 Pushbutton</li>
<li>* 1 LED (any color except IR!)</li>
<li>* 1 Potentiometer</li>
<li>* Several resistors (kΩ range)</li>
<li>* 1 Solderless breadboard</li>
</ul>
</div>
<div class="white">
<h2 style="font-size:200%; margin-bottom: 2%;">Communicating between the UNO and IDE
<a href="/code/lab01_1.ino" download>
<i class="fa fa-download" aria-hidden="true"></i>
</a>
</h2>
<div style="width:50%; display: inline; float:right;">
<div style='position:relative;padding-bottom:54%'><iframe src='https://gfycat.com/ifr/DistantBraveBoa' frameborder='0' scrolling='no' width='106%' height='120%' style='position:absolute;top:8px;left:0' allowfullscreen></iframe></div>
</div>
<div style="width:45%;">
<p>To test out the capabilities of the Arduino IDE, we first used the example Blink.ino in the IDE to have the Uno's built-in LED flash.</p>
<pre>
<code>
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
</code>
</pre>
</div>
<p style="margin-top:-50px;">After the code was verified and uploaded to the Uno, the built-in LED on the UNO started to blink, as shown above.</p>
</div>
<div class="grey">
<h2 style="font-size:200%; margin-bottom: 2%;">Modifying the Blink Sketch
<a href="/code/lab01_2.ino" download>
<i class="fa fa-download" aria-hidden="true"></i>
</a>
</h2>
<div style="width:50%; display: inline; float:right;">
<img src="http://i.imgur.com/Rn8bvos.jpg" width=435 style="margin-left:-25px; margin-top:8px;">
</div>
<div style="width:45%;">
<p>Next, we modified the sketch to blink an external LED connected to digital pin 9 on the UNO. <br>The code was as follows:</p>
<pre>
<code>
void setup() {
pinMode(9, OUTPUT);
}
void loop() {
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(1000);
}
</code>
</pre>
</div>
<p>We added a resistor to lower the current to the LED, as shown in the above image.<br>
The LED blinked on and off, just as the built in LED did in the previous exercise.</p>
</div>
<div class="white">
<h2 style="font-size:200%; margin-bottom: 2%;">Using the Serial Monitor and Analog Pins
<a href="/code/lab01_3.ino" download>
<i class="fa fa-download" aria-hidden="true"></i>
</a>
</h2>
<p>For this section we hooked up a potentiometer to one of the Arduino’s analog pins. The pot is a variable resistor, and is used in a voltage divider circuit to provide an output to the pin of between 0V and 5V, depending on its position.</p>
<p>To output the measured values, we used the Serial library and the Arduino IDE’s serial monitor tool.</p>
<div style="width:50%; display: inline; float:right;">
<p>When run, here’s what happens:</p>
<img src="https://thumbs.gfycat.com/NegligibleTerrificGreatdane-size_restricted.gif" width=455>
</div>
<div style="width:45%">
<p>Here is the code that we used:</p>
<pre>
<code>
int value;
void setup() {
// open the serial port at 9600 bps
Serial.begin(115200);
}
void loop() {
int value = 0;
value = analogRead(A0);
Serial.println("value = " + value);
}
</code>
</pre>
</div>
</div>
<div class="grey">
<h2 style="font-size:200%; margin-bottom: 2%;">Using the Arduino for Analog Output</h2>
<p>To output an analog signal from the Arduino, we chose a digital pin with pulse-width modulation capability. We connected this pin to the LED in series with a resistor. <br>The circuits below show the LED and potentiometer connected to the arduino, as well as the different levels of brightness of the LED.</p>
<img src="http://i.imgur.com/zr5EUwi.jpg" width=420 style=margin-right:14px;>
<img src="http://i.imgur.com/QGjNzXP.jpg" width=420>
<p>We added to our code from the previous section in order to use the potentiometer to adjust the LED brightness. We added a map function that would map the input range (0-1023 for the analog pin) to the correct output range (0-255 for the digital pin). We then used the analogWrite function to write the output value to the digital pin we had chosen. The following oscilloscope graph shows the frequency of the signal and its response to changing analog values.</p>
<img src="http://i.imgur.com/QthYOI4.jpg" width=100%>
</div>
<div class="white">
<h2 style="font-size:200%; margin-top: 2%;">Applying the Parallax Servos
<a href="/code/lab01_4.ino" download>
<i class="fa fa-download" aria-hidden="true"></i>
</a>
</h2>
<p style="margin-top:1%;">One of the most important functions for a robot to discover the maze is the ability to “walk”. Here, we used Parallax Continuous Rotation Servos. The white wire was connected to the digital pin “~11” with PWM capability. The red wire was connected to 5V output pin and the black wire was connected to ground “GND”. The oscilloscope was attached to check the frequency and maximum/minimum duty cycle. </p>
<div style="width:50%; display: inline; float:right;">
<p>When ran, the oscilloscope looked like:</p>
<img src="https://i.imgur.com/B9Udwd5.jpg" width=456>
</div>
<div style="width:45%">
<p>The code is listed below.</p>
<pre>
<code>
#include <Servo.h>
Servo yep;
void setup() {
}
void loop() {
yep.attach(11);
yep.write(0);
// yep.write(X),
// the integer X here can be 0 to 180.
// If X is 90, the servo will stop.
// If X is 0 or 180, it will rotate
// at full speed but in different directions
// for 0 and 180.
}
</code>
</pre>
</div>
<p>When the servo ran at full speed as X for yep.write(X) was 0, the duty cycle was 0.5/20=0.025. When the servo stopped as X was 180, the duty cycle was 1.5/20=0.075.</p>
<p>The potentiometer was then connected to the servo running with the same code above.</p>
</div>
<div class="grey">
<h2 style="font-size:200%; margin-bottom: 2%;">Let the Robot Run!
<a href="/code/lab01_5.ino" download>
<i class="fa fa-download" aria-hidden="true"></i>
</a>
</h2>
<p>Finally, we assembled the robot as shown below:</p>
<img src="https://i.imgur.com/vlPUDgf.jpg" height=402 style="margin-right:14px; margin-bottom:2%;">
<img src="http://i.imgur.com/z1QnSDW.jpg" height=402 style="margin-bottom: 2%;">
<div style="width:50%; display: inline; float:right;">
<p>The robot ran as shown below:</p>
<img src="https://thumbs.gfycat.com/BlandRashElk-size_restricted.gif" width=400>
</div>
<div style="width:45%">
<p>To let the robot drive in a square, a framework of the code is listed below:</p>
<pre>
<code>
Servo servoLeft;
Servo servoRight;
// Loop through motion tests
void loop() {
moveForward();
delay(1000);
turnRight();
}
// Motion routines for forward,
// reverse, turns, and stop
void moveForward() {
/* omitted */
}
void moveBackwards() {
/* omitted */
}
void turnLeft() {
/* omitted */
}
void turnRight() {
/* omitted */
}
void brake() {
/* omitted */
}
</code>
</pre>
<!-- <img src="images/lab01_c5.PNG" class="code" width=500>-->
</div>
</div>
</section>
</div>
</div>
</div>
</div>
<!-- /Main -->
<!-- Tweet -->
<div id="tweet">
<div class="container">
<section>
<blockquote style="font-family:Ubuntu; letter-spacing: 2px;">no bad robots</blockquote>
</section>
</div>
</div>
<!-- Copyright -->
<div id="copyright">
<div class="container">
website design from <a href="http://templated.co">TEMPLATED</a>
<br>
</div>
</div>
</body>
</html>