-
Notifications
You must be signed in to change notification settings - Fork 3
/
circ05.html
374 lines (356 loc) · 16.1 KB
/
circ05.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>ardx:circ-05[.:wcrs:.]</title>
<meta name="description" content="Arduino Experimenters Kit Shift Register circuit">
<!-- #include «head.html» -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--[if IE]><link rel="shortcut icon" href="favicon.ico"><![endif]-->
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="icon" href="favicon.png">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<script src="js/vendor/modernizr-2.8.3.min.js"></script>
</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- #include «topnav.html» -->
<nav id="topnav">
<a id="logo" href="https://wcrsyyc.github.io/"><img
src="img/wcrs_logo.png" alt="logo"></a>
<h2><a href="index.html">WCRS</a></h2>
<ul>
<li><a href="https://github.com/WCRSyyc/ardx">about</a> |</li>
<li><a href="https://github.com/WCRSyyc/ardx/issues">contact</a> |</li>
<li><a href="https://github.com/WCRSyyc/ardx/wiki">wiki</a></li>
</ul>
<hr>
<p><!-- current message text --></p>
</nav>
<!-- #include «sidebar.html» -->
<nav id="sidebar">
<section id="menu">
<ul>
<li><h2>PRODUCTS</h2>
<ul>
<li><a href="https://github.com/WCRSyyc/ardx/"><h3>(WCRS)</h3>ARDX additions</a>
<ul>
<li><a href="preface.html">
<h4>ABOUT</h4>A Few Words</a></li>
<!-- <li><a href="assembling.html">
<h4>ASSMB</h4>Putting It Together</a></li> -->
<li><a href="starthere.html">
<h4>START</h4>Startup Links</a></li>
<li><a href="programming.html">
<h4>PROG</h4>Programming Primer</a></li>
<li><a href="electronics.html">
<h4>ELEC</h4>Electronics Primer</a></li>
<li><a href="fritzing.html">
<h4>FRITZING</h4>Fritzing with ARDX</a></li>
<li><a href="circ01.html">
<h4>CIRC-01</h4>Blinking LED</a></li>
<li><a href="circ02.html">
<h4>CIRC-02</h4>Multiple LEDs</a></li>
<li><a href="circ03.html">
<h4>CIRC-03</h4>Transistors & Motors</a></li>
<li><a href="circ04.html">
<h4>CIRC-04</h4>Servos</a></li>
<li><a href="circ05.html">
<h4>CIRC-05</h4>74HC595 Shift Registers</a></li>
<li><a href="circ06.html">
<h4>CIRC-06</h4>Piezo Speaker</a></li>
<li><a href="circ07.html">
<h4>CIRC-07</h4>Pushbuttons</a></li>
<li><a href="circ08.html">
<h4>CIRC-08</h4>Potentiometers</a></li>
<li><a href="circ09.html">
<h4>CIRC-09</h4>Photo-Resistors</a></li>
<li><a href="circ10.html">
<h4>CIRC-10</h4>Temperature</a></li>
<li><a href="circ11.html">
<h4>CIRC-11</h4>Relays</a></li>
<li><a href="circ12.html">
<h4>CIRC-12</h4>RGB LED blink</a></li>
<li><a href="circ15.html">
<h4>CIRC-15</h4>Dice Simulator</a></li>
</ul>
</li>
<li><a href="https://github.com/WCRSyyc/ardx/"><h3>(WCRS)</h3>Python ARDX</a>
<ul>
<!-- <li><a href="preface.html">
<h4>ABOUT</h4>A Few Words</a></li> -->
<!-- <li><a href="assembling.html">
<h4>ASSMB</h4>Putting It Together</a></li> -->
<!-- <li><a href="starthere.html">
<h4>START</h4>Startup Links</a></li> -->
<!-- <li><a href="programming.html">
<h4>PROG</h4>Programming Primer</a></li> -->
<li><a href="electronics.html">
<h4>ELEC</h4>Electronics Primer</a></li>
<li><a href="fritzing.html">
<h4>FRITZING</h4>Fritzing with ARDX</a></li>
<li><a href="ArdxPythonHowTo.html">
<h4>GUIDE</h4>Python Guide</a></li>
<!--
<li><a href="circ01p.html">
<h4>CIRC-01</h4>Blinking LED</a></li>
<li><a href="circ02p.html">
<h4>CIRC-02</h4>Multiple LEDs</a></li>
<li><a href="circ03p.html">
<h4>CIRC-03</h4>Transistors & Motors</a></li>
<li><a href="circ04p.html">
<h4>CIRC-04</h4>Servos</a></li>
<li><a href="circ05p.html">
<h4>CIRC-05</h4>74HC595 Shift Registers</a></li>
<li><a href="circ06p.html">
<h4>CIRC-06</h4>Piezo Speaker</a></li>
<li><a href="circ07p.html">
<h4>CIRC-07</h4>Pushbuttons</a></li>
<li><a href="circ08p.html">
<h4>CIRC-08</h4>Potentiometers</a></li>
<li><a href="circ09p.html">
<h4>CIRC-09</h4>Photo-Resistors</a></li>
<li><a href="circ10p.html">
<h4>CIRC-10</h4>Temperature</a></li>
<li><a href="circ11p.html">
<h4>CIRC-11</h4>Relays</a></li>
<li><a href="circ12p.html">
<h4>CIRC-12</h4>RGB LED blink</a></li>
<li><a href="circ15p.html">
<h4>CIRC-15</h4>Dice Simulator</a></li> -->
</ul>
</li>
<li><a href="http://www.oomlout.com/a/products/ardx/"><h3>(ARDX)</h3>arduino / netduino experimenter´s kit</a>
</li>
</ul>
</li>
</ul>
</section>
<section>
<h3><a rel="license" href="http://creativecommons.org/licenses/by/4.0/">
<img alt="Creative Commons License"
src="img/80x15.png"></a></h3>
This work is licensed under a <a rel="license"
href="http://creativecommons.org/licenses/by/4.0/">Creative Commons
Attribution 4.0 International License</a>.
</section>
</nav>
<main id="circ-05">
<header>
<h1>CIRC<br/>05</h1>
<h2>.:8 More LEDs:.<br/>.:74HC595 Shift Register:.</h2>
<img src="img/experiments/CIRC-05-square-100.jpg" width="100" height="100" alt="16 pin dip chip">
</header>
<h2>(ARDX) .:Arduino Experimentation Kit:. (ARDX)</h2>
<section>
<h2>What We're Doing</h2>
<p>Time to start playing with chips, or integrated circuits (ICs) as they like to be called. The external packaging of a chip can be very deceptive. For example, the chip on the Arduino board (a microcontroller) and the one we will use in this circuit (a shift register) look very similar but are in fact rather different. The price of the ATMega chip on the Arduino board is a few dollars while the 74HC595 is a couple dozen cents. It's a good introductory chip, and once you're comfortable playing around with it and its datasheet (available online <a href="https://ardx.org/datasheet/IC-74HC595.pdf">http://ardx.org/74HC595</a>) the world of chips will be your oyster. The shift register (also called a serial to parallel converter), will give you an additional 8 outputs (to control LEDs and the like) using only three Arduino pins. They can also be linked together to give you a nearly unlimited number of outputs using the same three pins. To use it you "clock in" the data and then lock it in (latch it). To do this you set the data pin to either HIGH or LOW, pulse the clock, then set the data pin again and pulse the clock repeating until you have shifted out 8 bits of data. Then you pulse the latch and the 8 bits are transferred to the shift registers pins. It sounds complicated but is really simple once you get the hang of it.</p>
<p>(for a more in depth look at how a shift register works visit: <a href="https://en.wikipedia.org/wiki/Shift_register">http://ardx.org/SHIF</a>)</p>
</section>
<section id="circuit">
<h2>The Circuit</h2>
<div id="CIRC-theparts">
<h3>The Parts</h3>
<table>
<tr>
<td><img src="img/parts/CIRC-05-3dsheet-60.png"
width="60" height="36" alt="circuit 5 breadboard sheet 3d view"/></td>
<td>CIRC-05<br/>Breadboard Sheet<br/>x1</td>
<td><img src="img/parts/HEAD-02-60.png"
width="60" height="36" alt="2 pin header"/></td>
<td>2 Pin Header<br/>x4</td>
<td><img src="img/parts/IC-74HC595-60.png"
width="60" height="36" alt="74HC595 dip IC"/></td>
<td>Shift Register<br/>74HC595<br/>x1</td>
<td><img src="img/parts/WIRE-01-60.png"
width="60" height="36" alt="wire"/></td>
<td>Wire</td>
</tr><tr>
<td><img src="img/parts/LED-05R-60.png"
width="60" height="36" alt="10mm LED"/></td>
<td>Red LED<br/>x8</td>
<td><img src="img/parts/RES-561-60.png"
width="60" height="36" alt="resistor"/></td>
<td>560 Ohm Resistor<br/>Green-Blue-Black-Black<br/>x8</td>
<td colspan="4"></td>
</tr>
</table>
</div>
<span class="bb-svg-container"><svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="24 14.5 75 75"
preserveAspectRatio="xMaxYMin meet">
<image height="100" width="100"
xlink:href="img/experiments/CIRC05-bb.svg"/>
</svg></span>
<div>
<h3>Schematic</h3>
<span class="sch-svg-container"><svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="57 18 50 50"
preserveAspectRatio="xMidYMin meet">
<image height="100" width="100"
xlink:href="img/experiments/CIRC05-sch.svg" />
</svg></span>
</div>
<div>
<h3>Resources</h3>
<h4>.:download:.</h4>
<p>Breadboard layout sheet<br/>
<a href="img/experiments/CIRC05-sheet-OOML.pdf">http://ardx.org/BBLS05</a>
</p>
<p>Fritzing diagram<br/><a href="fritzing/CIRC05.fzz">
https://wcrsyyc.github.io/ardx/fritzing/CIRC05.fzz</a></p>
<h4>.:view:.</h4>
<p>
assembly video<br/>
<a href="https://www.youtube.com/watch?v=zYZCKaNw1bY">http://ardx.org/VIDE05</a>
</p>
</div>
</section>
<section id="code">
<h2>Code <span>(no need to type everything in just)</span></h2>
<p>Download the Code from ( <a
href="code/CIRC05-code.txt">
http://ardx.org/CODE05</a> )<br/>
(and then copy the text and paste it into an empty Arduino Sketch)</p>
<pre>/* ---------------------------------------------------------
* | Arduino Experimentation Kit Example Code |
* | CIRC-05 .: 8 More LEDs :. (74HC595 Shift Register) |
* ---------------------------------------------------------
*
* We have already controlled 8 LEDs however this does it in a slightly
* different manner. Rather than using 8 pins we will use just three
* and an additional chip.
*
*
*/
//Pin Definitions
//The 74HC595 uses a serial communication
//link which has three pins
int data = 2;
int clock = 3;
int latch = 4;
//Used for single LED manipulation
int ledState = 0;
const int ON = HIGH;
const int OFF = LOW;
/*
* setup() - this function runs once when you turn your Arduino on
* We set the three control pins to outputs
*/
void setup()
{
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
}
/*
* loop() - this function will start after setup finishes and then repeat
* we set which LEDs we want on then call a routine which sends the states to the 74HC595
*/
void loop() // run over and over again
{
int delayTime = 100; //the number of milliseconds to delay between LED updates
for(int i = 0; i < 256; i++){
updateLEDs(i);
delay(delayTime);
}
}
/*
* updateLEDs() - sends the LED states set in ledStates to the 74HC595
* sequence
*/
void updateLEDs(int value)
{
digitalWrite(latch, LOW); //Pulls the chips latch low
shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
digitalWrite(latch, HIGH); //Pulls the latch high displaying the data
}
/*
* updateLEDsLong() - sends the LED states set in ledStates to the 74HC595
* sequence. Same as updateLEDs except the shifting out is done in software
* so you can see what is happening.
*/
void updateLEDsLong(int value)
{
digitalWrite(latch, LOW); //Pulls the chips latch low
for(int i = 0; i < 8; i++){ //Will repeat 8 times (once for each bit)
int bit = value & B10000000; //We use a "bitmask" to select only the eighth
//bit in our number (the one we are addressing this time through
value = value << 1; //we move our number up one bit value so next time bit 7 will be
//bit 8 and we will do our math on it
if(bit == 128){digitalWrite(data, HIGH);} //if bit 8 is set then set our data pin high
else{digitalWrite(data, LOW);} //if bit 8 is unset then set the data pin low
digitalWrite(clock, HIGH); //the next three lines pulse the clock pin
delay(1);
digitalWrite(clock, LOW);
}
digitalWrite(latch, HIGH); //pulls the latch high shifting our data into being displayed
}
//These are used in the bitwise math that we use to change individual LEDs
//For more details http://en.wikipedia.org/wiki/Bitwise_operation
int bits[] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};
/*
* changeLED(int led, int state) - changes an individual LED
* LEDs are 0 to 7 and state is either 0 - OFF or 1 - ON
*/
void changeLED(int led, int state)
{
ledState = ledState & masks[led]; //clears ledState of the bit we are addressing
if(state == ON){ledState = ledState | bits[led];} //if the bit is on we will add it to ledState
updateLEDs(ledState); //send the new LED state to the shift register
}</pre>
</section>
<section id="CIRC-notworking">
<h2>Not Working? <span>(3 things to try)</span></h2>
<div>
<h3>The Arduino's power LED goes out</h3>
<p>This happened to us a couple of times, it happens when the chip is inserted backwards. If you fix it quickly nothing will break.</p>
</div>
<div>
<h3>Not Quite Working</h3>
<p>Sorry to sound like a broken record but it is probably something as simple as a crossed wire.</p>
</div>
<div>
<h3>Frustration?</h3>
<p>Shoot us an e-mail, this circuit is both simple and complex at the same time. We want to hear about problems you have so we can address them in future editions.<br/>
<a href="mailto:[email protected]">[email protected]</a><br/>
<a href="mailto:[email protected]">[email protected]</a></p>
</div>
</section>
<section id="CIRC-makingBetter">
<h2>Making it Better?</h2>
<h3>Doing it the hard way:</h3>
<p>An Arduino makes rather complex actions very easy, shifting out data is one of these cases. However one of the nice features of an Arduino is you can make things as easy or difficult as you like. Lets try an example of this. In your loop switch the line.<br/>
<code>updateLEDs(i);</code> -> <code>updateLEDsLong(i);</code><br/>
Upload the program and notice nothing has changed. If you look at the code you can see how we are communicating with the chip one bit at a time. (for more details <a href="https://en.wikipedia.org/wiki/Serial_Peripheral_Interface">http://ardx.org/SPI</a> ).</p>
<h3>Controlling Individual LEDs:</h3>
<p>Time to start controlling the LEDs using a method similar to what we did in CIRC02. As the eight LED states are stored in one byte (an 8 bit value) for details on how this works try <a href="https://en.wikipedia.org/wiki/Binary_number">http://ardx.org/BINA</a>. An Arduino is very good at manipulating bits and there are an entire set of operators that help us out. Details on bitwise operations at ( <a href="https://en.wikipedia.org/wiki/Bitwise_operation">http://ardx.org/BITW</a> ).</p>
<h4>Our implementation</h4>
<p>Replace the loop() code with</p>
<pre> int delayTime = 100; //the number of milliseconds to delay
//between LED updates
for(int i = 0; i < 8; i++){
changeLED(i,ON);
delay(delayTime);
}
for(int i = 0; i < 8; i++){
changeLED(i,OFF);
delay(delayTime);
}</pre>
<p>and upload to cause the lights to light up one after another and then off in a similar manner. Check the code and Wikipedia to see how it works, or shoot us an e-mail if you have questions.</p>
<h3>More Animations:</h3>
<p>Now things get more interesting. If you look back to the code from CIRC02 (8 LED Fun) you see we change the LEDs using digitalWrite(led, state), this is the same format as the routine we wrote changeLED(led, state). You can use the animations you wrote for CIRC02 by copying the code into this sketch and changing all the digitalWrite()'s to changeLED()'s. Powerful? Very. (you'll also need to change a few other things but follow the compile errors and it works itself out).</p>
</section>
</main>
<footer>.:Welcome to the Bottom:.</footer>
</body>
</html>