Web edits
[beagleboard.org.git] / db / 2769.xml
blob3532f0d86b4f956ac09d59ce0a4934c512f142ea
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="2769" name="accelerometer" prototype="Page" created="1371678639296" lastModified="1387489514386">
5   <hop:parent idref="2471" prototyperef="Page"/>
6     <is_xhtml type="boolean">true</is_xhtml>
7     <http_remotehost>192.91.75.29</http_remotehost>
8     <http_language>en-US,en;q=0.8,fr;q=0.6</http_language>
9     <uri>accelerometer</uri>
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:45:14 CST</time>
12     <hopsession>192.91.75.1opeze1cmz1ei</hopsession>
13     <body>&lt;script src=&quot;/static/bonescript-demo.js&quot;&gt;&lt;/script&gt;\r
14 &lt;div id=&apos;side-menu&apos; class=&quot;t3_sidebar&quot;&gt;\r
15     &lt;ul class=&quot;left-menu&quot;&gt;&lt;strong&gt;Navigation&lt;/strong&gt;\r
16         &lt;li&gt;&lt;a href=&quot;/static/side-menu.html&quot;&gt;Menu contents&lt;/a&gt;&lt;/li&gt;\r
17     &lt;/ul&gt;\r
18 &lt;/div&gt;\r
19 &lt;div class=&quot;t3_content_1&quot;&gt;&lt;div id=&apos;connect-status&apos;&gt;&lt;/div&gt;&lt;div id=&quot;content_child&quot;&gt;\r
20 &lt;h1&gt;Demo: Accelerometer&lt;/h1&gt;\r
21 &lt;p&gt;This example reads values from &lt;a \r
22     href=&quot;https://www.sparkfun.com/products/9269&quot;&gt;Sparkfun’s ADXL335 3-axis\r
23     accelerometer&lt;/a&gt;. Because the output of the ADXL335 is between 0-3.3V \r
24     and because BeagleBone&apos;s analogRead pins are 1.8V tolerant, we used a \r
25     hardware (resistor) voltage divider on each of the accelerometer outputs. \r
26     This provides a range of 0-1.65V to be read on BeagleBone analogRead pins.\r
27 &lt;/p&gt;\r
28 &lt;p&gt;&lt;i&gt;NOTE: Due to output impedance of the ADXL335 being ~32kOhms, a low resistor\r
29 value for the voltage divider is recommended (between 500 Ohms- 1k Ohms).&lt;/i&gt;\r
30 &lt;/p&gt;\r
31 &lt;p&gt;\r
32     \r
33     We need to do simple math before we continue. Ultimately, we want to know the \r
34     value in G’s being exerted on the accelerometer. The output of the\r
35     accelerometer is in volts. The first thing we need to do is calculate a\r
36     formula that will convert volts to Gs for us in our software. This formula\r
37     for us is:\r
38 &lt;/p&gt;\r
39 &lt;p&gt;\r
40     &lt;center&gt;&lt;i&gt;(axisRead - zeroOffset) / (conversionFactor) = acceleration&lt;/center&gt;&lt;br /&gt;\r
41     &lt;center&gt;Where: zeroOffset = 0.0917 and conversionFactor = 0.4584&lt;/i&gt;&lt;/center&gt;\r
42 &lt;/p&gt;\r
43 &lt;h2&gt;Example\r
44  &lt;button class=&quot;dynlink&quot; onclick=&quot;demoRun(&apos;code&apos;)&quot;&gt;run&lt;/button&gt;\r
45  &lt;button class=&quot;dynlink&quot; onclick=&quot;demoRestore(&apos;code&apos;)&quot;&gt;restore&lt;/button&gt;\r
46 &lt;/h2&gt;\r
47 &lt;pre id=&quot;code&quot; class=&quot;use-editor&quot; style=&quot;height:700px;&quot;&gt;\r
48 var b = require(&apos;bonescript&apos;);\r
49 var zeroOffset  = 0.4584;\r
50 var conversionFactor = 0.0917;\r
52 function callADC(){\r
53     b.analogRead(&apos;P9_36&apos;, printX);\r
54     b.analogRead(&apos;P9_38&apos;, printY);\r
55     b.analogRead(&apos;P9_40&apos;, printZ);\r
56 }\r
58 function printX(x) {\r
59     var value = (x.value - zeroOffset)/conversionFactor;\r
60     console.log(&apos;Analog Read Value x: &apos; +value);    \r
61     // when the ADXL335 resting flat on a table or\r
62     //board, then readings should be x:0\r
63 }\r
65 function printY(x) {\r
66     var value = (x.value - zeroOffset)/conversionFactor;\r
67     console.log(&apos;Analog Read Value y: &apos; +value);\r
68     // when the ADXL335 resting flat on a table or\r
69     //board, then readings should be y:0\r
70 }\r
72 function printZ(x) {\r
73     var value = (x.value - zeroOffset)/conversionFactor;\r
74     console.log(&apos;Analog Read Value z: &apos; +value);    \r
75     // when the ADXL335 resting flat on a table or \r
76     //board, then readings should be z:1\r
77     console.log(&apos;&apos;);\r
78 }\r
80 //callADC will be invoked 20 times a sec or once every 50 ms\r
81 var loop = setInterval(callADC, 50);          \r
83 function clear(){\r
84     clearInterval(loop);\r
85 }\r
87 //after 1 second (1000ms), the interval\r
88 setTimeout(clear, 1000);                                \r
89 &lt;/pre&gt;\r
90 &lt;div readonly id=&apos;console-output&apos; style=&quot;height:250px;&quot;&gt;&lt;/div&gt;\r
91 &lt;br&gt;&lt;/br&gt;\r
92 &lt;img align=&quot;center&quot; width=&quot;90%&quot; src=&quot;/static/uploads/bbb_accelerometer_image.png&quot; /&gt;\r
93 &lt;br&gt;&lt;/br&gt;\r
94 &lt;h2&gt;Build and execute instructions&lt;/h2&gt;\r
95 &lt;ul&gt;\r
96  &lt;li&gt;Hook up BeagleBone to the breadboard as shown in the diagram (above).&lt;/li&gt;\r
97  &lt;li&gt;After clicking ‘run’, notice the console output above for the accelerometer\r
98     data.&lt;/li&gt;\r
99  &lt;li&gt;Experiment by altering the second argument in ‘setTimeout(clear, x) to \r
100     another number where x is a value in milliseconds (this value determines how\r
101     long the example will run).&lt;/li&gt;\r
102 &lt;/ul&gt;\r
104 &lt;h2&gt;See also&lt;/h2&gt;\r
105 &lt;h3&gt;Related functions&lt;/h3&gt;\r
106 &lt;ul&gt;\r
107  &lt;li&gt;&lt;a href=&quot;/Support/BoneScript/#require&quot;&gt;require&lt;/a&gt;&lt;/li&gt;\r
108  &lt;li&gt;&lt;a href=&quot;/Support/BoneScript/analogRead/&quot;&gt;analogRead&lt;/a&gt;&lt;/li&gt;\r
109 &lt;/ul&gt;\r
111 &lt;h3&gt;Where to buy&lt;/h3&gt;\r
112 &lt;ul&gt;\r
113  &lt;li&gt;&lt;a href=&quot;https://www.sparkfun.com/products/9267&quot;&gt;Accelerometer&lt;/a&gt;&lt;/li&gt;\r
114 &lt;li&gt; &lt;a href=&quot;http://elinux.org/CircuitCo:BeagleBone_Breadboard#Distributors&quot;&gt;BreadBoard&lt;/a&gt;&lt;/li&gt;\r
115 &lt;li&gt;&lt;a href=&quot;https://www.sparkfun.com/products/11026&quot;&gt;Jumper wires&lt;/a&gt;&lt;/li&gt;\r
116 &lt;li&gt; &lt;a href=&quot;https://www.sparkfun.com/search/products?sort_by=relevance%7Casc&amp;per_page=500&amp;term=resistor&quot;&gt;Resistors&lt;/a&gt;&lt;/li&gt;\r
117 &lt;li&gt;OR you can use the accelerometer on the &lt;a href=&quot;http://boardzoo.com/index.php/beaglebone-black/beaglebone-bacon.html#.UrCCIfRDvz4&quot;&gt;Bacon Cape&lt;/a&gt;, as shown in the video below.&lt;/li&gt;\r
119 &lt;/br&gt;\r
121 &lt;h2&gt;See it in action&lt;/h2&gt;\r
122 &lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;//www.youtube.com/embed/5QxtkUGNWO0&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;</body>
123     <pseudoparent idref="2471" prototyperef="Page"/>
124     <http_referer>http://beagleboard.org/support/BoneScript/accelerometer/edit</http_referer>
125     <http_host>beagleboard.org</http_host>
126     <user>jessica.lynne.callaway@gmail.com</user>
127     <lang>en-us</lang>
128   </hopobject>
129 </xmlroot>