1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <?xml-stylesheet type="text/xsl" href="helma.xsl"?>
3 <xmlroot xmlns:hop="http://www.helma.org/docs/guide/features/database">
4 <hopobject id="2825" name="cape_bacon" prototype="Page" created="1372735831412" lastModified="1387490012600">
5 <hop:parent idref="2471" prototyperef="Page"/>
6 <is_xhtml type="boolean">true</is_xhtml>
7 <http_remotehost>192.94.94.105</http_remotehost>
8 <http_language>en-US,en;q=0.8,fr;q=0.6</http_language>
10 <http_browser>Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36</http_browser>
11 <time type="date">19.12.2013 15:53:32 CST</time>
12 <hopsession>192.94.94.c19vyxgotgkm</hopsession>
13 <body><script src="/static/bonescript-demo.js"></script>
\r
14 <script src="/static/jquery-ui.min.js"></script>
\r
15 <h2>BoneScript</h2>
\r
16 <div id='side-menu' class="t3_sidebar">
\r
17 <ul class="left-menu">
\r
18 <strong>Navigation</strong>
\r
19 <li><a href="/Support/BoneScript/menu/">Menu contents</a></li>
\r
22 <div class="t3_content_1">
\r
23 <div id='connect-status'></div>
\r
24 <div id="content_child">
\r
26 <h1>Bacon Cape</h1>
\r
27 <p>The Bacon Cape is an add-on board meant to give you access to some
\r
28 hardware to help build your understanding of doing basic embedded I/O on
\r
31 <h2>Board activity</h2>
\r
32 <p>When you visit this page and you have a BeagleBone running BoneScript 0.2.3
\r
33 or newer with a Bacon Cape attached on your local network or connected to
\r
34 your computer over USB, this display will dyanmically update
\r
35 to reflect the board status. The box color should reflect the color of the
\r
36 RGB LED. The top slider should reflect the status of the push button and
\r
37 turn on the blue LED. The middle slider should reflect the status of the
\r
38 slide potentiometer and adjust the brightness of the green LED. The bottom
\r
39 slider should be adjustable on the page and adjust the brightness of the red
\r
42 <p>More information about the cape can be found at <a href="http://elinux.org/Bacon_Cape">
\r
43 the eLinux.org Bacon Cape page.
\r
44 </a></p>
\r
45 <h2>Components</h2>
\r
47 These are the major components of the Bacon Cape.
\r
50 <li><em>S1</em>: a simple push button provides a digital input
\r
52 <li><em>P8_19</em>: digital I/O connection to BeagleBone</li>
\r
53 <li>Configured as active-low (low when pressed) and uses and external pull-up</li>
\r
56 <li><em>D1</em>: an RGB LED provides an indicator for digital output
\r
58 <li><em>P9_16</em>: digital I/O connection for <em><font color="blue">BLUE</font></em></li>
\r
59 <li><em>P9_14</em>: digital I/O connection for <em><font color="green">GREEN</font></em></li>
\r
60 <li><em>P9_42</em>: digital I/O connection for <em><font color="red">RED</font></em></li>
\r
61 <li>Configured as active-high (lit when high)</li>
\r
64 <li><em>R10</em>: a slide potentiometer provides an analog input
\r
66 <li><em>P9_36</em>: analog input connection to BeagleBone</li>
\r
69 <li><em>U1</em>: shift register feeding a 7 segment display
\r
70 <img src="/static/images/cape-bacon-seg7.png" align="right" />
\r
72 <li><em>P9_22</em>: CLOCK</li>
\r
73 <li><em>P9_17</em>: LATCH</li>
\r
74 <li><em>P9_18</em>: DATA</li>
\r
75 <li><em>P9_15</em>: CLEAR</li>
\r
76 <li><em>LED1</em>: connected to shift register output in common anode (active-low) configuration</li>
\r
77 <li><em>a</em>: last bit shifted out</li>
\r
78 <li><em>h</em>: first bit shifted out</li>
\r
80 <li><em>U2</em>: I2C EEPROM connected to I2C2</li>
\r
83 onbonescriptinit = function() {
\r
84 $(document).ready(function(){ demoRun('code'); });
\r
88 <button class="dynlink" id="runbutton">run</button>
\r
90 <div style="display: table;">
\r
91 <div style="display: table-row; width=500px;">
\r
92 <div id="led1" style="display: table-cell; height:50px;"></div>
\r
93 <div style="display: table-cell; height:50px">
\r
94 <div id="slider1" style="width:400px; vertical-align:center;"></div>
\r
95 <div id="slider2" style="width:400px; vertical-align:center;"></div>
\r
96 <div id="slider3" style="width:400px; vertical-align:center;"></div>
\r
101 <div readonly id='console-output' style='height:80px;width:600px;'></div>
\r
102 <h2>Code</h2>
\r
103 <pre id="code" class="use-editor" style="height:3500px;width:600px;">
\r
104 // read in BoneScript library
\r
105 var b = require('bonescript');
\r
107 // define used pins
\r
108 var LED_RED = 'P9_42';
\r
109 var LED_GREEN = 'P9_14';
\r
110 var LED_BLUE = 'P9_16';
\r
111 var BUTTON = 'P8_19';
\r
112 var POT = 'P9_36';
\r
113 var S_DATA = 'P9_18';
\r
114 var S_CLOCK = 'P9_22';
\r
115 var S_LATCH = 'P9_17';
\r
116 var S_CLEAR = 'P9_15';
\r
118 // define other global variables
\r
121 var segments = [ 0xC0, 0xF9, 0xA4, 0xB0, 0x99,
\r
122 0x92, 0x82, 0xF8, 0x80, 0x90 ];
\r
127 // attach jQuery elements
\r
129 $('#slider1').slider();
\r
130 $('#slider2').slider();
\r
131 $('#slider3').slider();
\r
132 $('#led1').css('width', '50px');
\r
133 $('#led1').css('height', '50px');
\r
134 $('#led1').css('background-color', 'rgb(0,0,0)');
\r
135 $("#slider3").bind("slidechange", function(event, ui) {
\r
136 updateRed({value:(ui.value/100.0)});
\r
138 //$('#runbutton').removeAttr('onclick');
\r
139 $('#runbutton').click(runClick);
\r
142 // configure pins as inputs/outputs
\r
143 b.pinMode(S_DATA, b.OUTPUT);
\r
144 b.pinMode(S_CLOCK, b.OUTPUT);
\r
145 b.pinMode(S_LATCH, b.OUTPUT);
\r
146 b.pinMode(S_CLEAR, b.OUTPUT);
\r
147 b.pinMode('USR0', b.OUTPUT);
\r
148 b.pinMode('USR1', b.OUTPUT);
\r
149 b.pinMode('USR2', b.OUTPUT);
\r
150 b.pinMode('USR3', b.OUTPUT);
\r
151 //b.pinMode(LED_RED, b.OUTPUT);
\r
152 //b.pinMode(LED_GREEN, b.OUTPUT);
\r
153 //b.pinMode(LED_BLUE, b.OUTPUT);
\r
154 b.pinMode(BUTTON, b.INPUT);
\r
157 b.digitalWrite('USR0', b.LOW);
\r
158 b.digitalWrite('USR1', b.LOW);
\r
159 b.digitalWrite('USR2', b.LOW);
\r
160 b.digitalWrite('USR3', b.LOW);
\r
161 b.analogWrite(LED_RED, 0);
\r
162 b.analogWrite(LED_GREEN, 0);
\r
163 b.analogWrite(LED_BLUE, 0);
\r
164 b.digitalWrite(S_DATA, b.LOW);
\r
165 b.digitalWrite(S_CLOCK, b.LOW);
\r
166 b.digitalWrite(S_LATCH, b.LOW);
\r
167 b.digitalWrite(S_CLEAR, b.HIGH);
\r
168 //b.attachInterrupt(BUTTON, true, b.CHANGE, handleButton);
\r
170 // call function to read status and perform updates
\r
172 console.log('Starting Bacon Cape demo');
\r
173 b.getPlatform(onGetPlatform);
\r
176 function onGetPlatform(x) {
\r
178 scheduleNextUpdate();
\r
181 function scheduleNextUpdate() {
\r
182 // test for stop and then schedule next update for 50ms
\r
185 console.log('Stopped Bacon Cape demo');
\r
187 setTimeout(update, 50);
\r
191 function update() {
\r
193 s = (s == b.LOW) ? b.HIGH : b.LOW;
\r
194 if(platform.bonescript != '0.2.3') {
\r
195 b.digitalWrite('USR0', s, doAnalogRead);
\r
197 b.digitalWrite('USR0', s, do7SegUpdate);
\r
201 function do7SegUpdate(x) {
\r
202 // update 7segment LED
\r
203 digit = (digit + 1) % 10;
\r
205 // shift out the character LED pattern
\r
206 b.shiftOut(S_DATA, S_CLOCK, b.MSBFIRST,
\r
207 segments[digit], doLatch);
\r
210 function doLatch() {
\r
211 // latch in the value
\r
212 b.digitalWrite(S_LATCH, b.HIGH, doLatchLow);
\r
215 function doLatchLow() {
\r
216 b.digitalWrite(S_LATCH, b.LOW, doAnalogRead);
\r
219 function doAnalogRead() {
\r
220 b.digitalRead(BUTTON, updateBlue);
\r
223 function updateBlue(x) {
\r
224 if(typeof x.value == 'undefined') return;
\r
225 updateLED({blue:1-x.value});
\r
226 b.analogRead(POT, updateGreen);
\r
229 function updateGreen(x) {
\r
230 if(typeof x.value == 'undefined') return;
\r
231 updateLED({green:1-x.value});
\r
232 scheduleNextUpdate();
\r
235 function updateRed(x) {
\r
237 if(typeof x.value == 'undefined') return;
\r
238 updateLED({red:x.value});
\r
242 function updateLED(led) {
\r
243 if(typeof led.red == 'number') {
\r
244 b.analogWrite(LED_RED, led.red);
\r
245 this.red = led.red;
\r
247 if(typeof led.green == 'number') {
\r
248 b.analogWrite(LED_GREEN, led.green);
\r
249 this.green = led.green;
\r
251 if(typeof led.blue == 'number') {
\r
252 b.analogWrite(LED_BLUE, led.blue);
\r
253 this.blue = led.blue;
\r
256 if(typeof this.red == 'undefined') this.red = 0;
\r
257 if(typeof this.green == 'undefined') this.green = 0;
\r
258 if(typeof this.blue == 'undefined') this.blue = 0;
\r
259 var rgb = 'rgb(' + Math.round(this.red*255) + ',' +
\r
260 Math.round(this.green*255) + ',' +
\r
261 Math.round(this.blue*255) + ')';
\r
262 $('#led1').css('background-color', rgb);
\r
263 $("#slider1").slider("option", "value", this.blue*100);
\r
264 $("#slider2").slider("option", "value", this.green*100);
\r
268 function runClick() {
\r
274 $('#runbutton').html('stop');
\r
276 } else if(!stopped) {
\r
278 var p = '/sys/class/leds/beaglebone:green:usr';
\r
279 b.digitalWrite('USR0', b.LOW);
\r
280 b.digitalWrite('USR1', b.LOW);
\r
281 b.digitalWrite('USR2', b.LOW);
\r
282 b.digitalWrite('USR3', b.LOW);
\r
283 b.writeTextFile(p+'0/trigger', 'heartbeat');
\r
284 b.writeTextFile(p+'1/trigger', 'mmc0');
\r
285 b.writeTextFile(p+'2/trigger', 'cpu0');
\r
286 b.writeTextFile(p+'3/trigger', 'mmc1');
\r
288 $('#runbutton').html('run');
\r
294 window.onbeforeunload = restore;
\r
295 function restore() {
\r
296 var b = require('bonescript');
\r
297 var p = '/sys/class/leds/beaglebone:green:usr';
\r
298 b.digitalWrite('USR0', b.LOW);
\r
299 b.digitalWrite('USR1', b.LOW);
\r
300 b.digitalWrite('USR2', b.LOW);
\r
301 b.digitalWrite('USR3', b.LOW);
\r
302 b.writeTextFile(p+'0/trigger', 'heartbeat');
\r
303 b.writeTextFile(p+'1/trigger', 'mmc0');
\r
304 b.writeTextFile(p+'2/trigger', 'cpu0');
\r
305 b.writeTextFile(p+'3/trigger', 'mmc1');
\r
306 //b.detachInterrupt('P8_19');
\r
309 <h2>See also</h2>
\r
310 <h3>Reference</h3>
\r
312 <li><a href="http://elinux.org/Bacon_Cape" class="external">Bacon Cape
\r
314 </a></li>
\r
316 <h3>Topics</h3>
\r
318 <li><a href="/Support/bone101/#headers">BeagleBone expansion headers</a></li>
\r
319 <li><a href="/Support/BoneScript/#analogio">Analog I/O</a></li>
\r
321 <h3>Related functions</h3>
\r
323 <li><a href="/Support/BoneScript/#require">require</a></li>
\r
324 <li><a href="/Support/BoneScript/pinMode/">pinMode</a></li>
\r
325 <li><a href="/Support/BoneScript/analogWrite/">analogWrite</a></li>
\r
326 <li><a href="/Support/BoneScript/analogRead/">analogRead</a></li>
\r
327 <li><a href="/Support/BoneScript/digitalWrite/">digitalWrite</a></li>
\r
328 <li><a href="/Support/BoneScript/digitalRead/">digitalRead</a></li>
\r
330 <h3>Where to buy</h3>
\r
332 <li><a href="http://boardzoo.com/index.php/beaglebone-black/beaglebone-bacon.html#.UrCCIfRDvz4">Bacon Cape</a></li>
\r
336 </div></div>
\r
337 <div style="clear:both; padding-left:210px;"><h2>See it in action</h2>
\r
338 <iframe width="560" height="315" src="//www.youtube.com/embed/EE_cECo-7uA" frameborder="0" allowfullscreen></iframe> </div>
\r
340 <pseudoparent idref="2471" prototyperef="Page"/>
341 <http_referer>http://beagleboard.org/support/BoneScript/cape_bacon/edit</http_referer>
342 <http_host>beagleboard.org</http_host>
343 <user>jessica.lynne.callaway@gmail.com</user>