Log updates
[beagleboard.org.git] / db / 2769.xml
blobfccf7ef6bc6bd1f6bd5b6436b7fbf24ece0fe4f9
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="1372359627348">
5   <hop:parent idref="2471" prototyperef="Page"/>
6     <is_xhtml type="boolean">true</is_xhtml>
7     <http_remotehost>127.0.0.1</http_remotehost>
8     <http_language>en-US,en;q=0.8</http_language>
9     <uri>accelerometer</uri>
10     <http_browser>Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36</http_browser>
11     <time type="date">27.06.2013 14:00:27 CDT</time>
12     <hopsession>127.0.0.192.94.94.82x695wlrayl</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;</body>
110     <pseudoparent idref="2471" prototyperef="Page"/>
111     <http_referer>http://beagleboard.org/support/BoneScript/accelerometer/edit</http_referer>
112     <http_host>beagleboard.org</http_host>
113     <user>rachelballdesign@gmail.com</user>
114     <lang>en-us</lang>
115   </hopobject>
116 </xmlroot>