Changes between Initial Version and Version 1 of accelerometer


Ignore:
Timestamp:
10/22/2017 05:28:45 AM (7 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • accelerometer

    v1 v1  
     1{{{#!html
     2          <div id="wikipage" class="trac-content"><p>
     3</p><div class="wiki-toc">
     4<ol>
     5  <li>
     6    <a href="#AccelerometerandMagnetometer">Accelerometer and Magnetometer</a>
     7    <ol>
     8      <li>
     9        <a href="#OSSupport">OS Support</a>
     10      </li>
     11      <li>
     12        <a href="#AndroiduseviatheAndroidsensorHAL"><strong>Android</strong> use via the Android sensor HAL</a>
     13      </li>
     14      <li>
     15        <a href="#Linuxinputdeviceaccess">Linux <strong>input</strong> device access</a>
     16      </li>
     17      <li>
     18        <a href="#directi2caccess">direct <strong>i2c</strong> access</a>
     19      </li>
     20    </ol>
     21  </li>
     22</ol>
     23</div><p>
     24</p>
     25<h1 id="AccelerometerandMagnetometer">Accelerometer and Magnetometer</h1>
     26<p>
     27Many Ventana models come standard with an Accelerometer and Magnetometer on a single <a class="ext-link" href="http://cache.freescale.com/files/sensors/doc/data_sheet/FXOS8700CQ.pdf?pspll=1"><span class="icon">​</span>FXOS8700CQR1</a> IC.
     28</p>
     29<p>
     30Note that this device has a low power standby mode which it is in by default, so be sure to enable it if you want to read values from it (see examples below). Register 0x2a and 0x5b relate to this.
     31</p>
     32<p>
     33References:
     34</p>
     35<ul><li><a class="ext-link" href="http://cache.freescale.com/files/sensors/doc/data_sheet/FXOS8700CQ.pdf?pspll=1"><span class="icon">​</span>FXOS8700CQR1 Datasheet</a>
     36</li></ul><h2 id="OSSupport">OS Support</h2>
     37<p>
     38The FXOS8700 used on many Ventana boards is supported in the following ways:
     39</p>
     40<table class="wiki">
     41<tr><td> <strong><a class="wiki" href="/wiki/OpenWrt">OpenWrt</a></strong>      </td><td> <strong>Yocto/OE</strong>    </td><td> <strong>Android</strong>
     42</td></tr><tr><td> i2c/input (<a class="changeset" href="/changeset/671" title="ventana: add Freescale MMA8451 driver (FXOS8700)
     43
     44This driver has the ...">r671</a>) </td><td> i2c/input       </td><td> i2c/input/sensor HAL
     45</td></tr></table>
     46<h2 id="AndroiduseviatheAndroidsensorHAL"><strong>Android</strong> use via the Android sensor HAL</h2>
     47<p>
     48The Android BSP will register an accelerometer and a magnetometer sensor with the OS and therefore can be used with apps conforming the the Android sensor API.
     49</p>
     50<p>
     51References:
     52</p>
     53<ul><li><a class="ext-link" href="http://www.tutorialspoint.com/android/android_sensors.htm"><span class="icon">​</span>http://www.tutorialspoint.com/android/android_sensors.htm</a>
     54</li></ul><h2 id="Linuxinputdeviceaccess">Linux <strong>input</strong> device access</h2>
     55<p>
     56The <a class="ext-link" href="https://www.kernel.org/doc/Documentation/input/input.txt"><span class="icon">​</span>Linux input device API</a> provides access to devices through a <tt>/dev/input/event&lt;n&gt;</tt> interface. The FXOS8700 is supported via a linux input driver on all of the Gateworks BSP's.
     57</p>
     58<p>
     59The <tt>/sys/class/input/input&lt;n&gt;/name</tt> directories will show the device name responsible for the events within that directory which correspond to matching <tt>/dev/input/event&lt;n&gt;</tt> entries.
     60</p>
     61<p>
     62Additionally there will be an api for the input device in <tt>/sys/devices/virtual/input/input&lt;n&gt;/</tt> that provides you access to various controllable aspects of the input device such as the polling frequency, the min/max values, the scaling mode used and the position (orientation) of the sensor on the board. The scaling mode and position will cause the values reported to the linux input subsystem to be transformed (for normalization).
     63</p>
     64<p>
     65You can use the popular evtest application to show details and events from a linux input device, or write an application that accesses the device yourself.
     66</p>
     67<p>
     68Example usage:
     69</p>
     70<div class="code"><pre>&gt; cat /sys/devices/virtual/input/input2/name <span class="c"># show the name of the sensor
     71</span>fxos8700_m
     72&gt; cat /sys/devices/virtual/input/input2/position <span class="c"># show the orientation of the sensor
     73</span>3
     74&gt; <span class="nb">echo </span>1 &gt; /sys/devices/virtual/input/input2/enable <span class="c"># enable the sensor (take it out of standby mode)
     75</span>&gt; evtest /dev/input/event2 <span class="c"># show info and values
     76</span>&gt; evtest /dev/input/event2
     77Input driver version is 1.0.1
     78Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0
     79Input device name: <span class="s2">"fxos8700_m"</span>
     80Supported events:
     81  Event <span class="nb">type </span>0 <span class="o">(</span>Sync<span class="o">)</span>
     82  Event <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>
     83    Event code 0 <span class="o">(</span>X<span class="o">)</span>
     84      Value     69
     85      Min    -8192
     86      Max     8191
     87      Fuzz      32
     88      Flat      32
     89    Event code 1 <span class="o">(</span>Y<span class="o">)</span>
     90      Value    -31
     91      Min    -8192
     92      Max     8191
     93      Fuzz      32
     94      Flat      32
     95    Event code 2 <span class="o">(</span>Z<span class="o">)</span>
     96      Value    698
     97      Min    -8192
     98      Max     8191
     99      Fuzz      32
     100      Flat      32
     101Testing ... <span class="o">(</span>interrupt to <span class="nb">exit</span><span class="o">)</span>
     102Event: <span class="nb">time </span>1418930877.756913, <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>, code 0 <span class="o">(</span>X<span class="o">)</span>, value 69
     103Event: <span class="nb">time </span>1418930877.756913, <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>, code 1 <span class="o">(</span>Y<span class="o">)</span>, value -62
     104Event: <span class="nb">time </span>1418930877.756913, <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>, code 2 <span class="o">(</span>Z<span class="o">)</span>, value 698
     105Event: <span class="nb">time </span>1418930877.756913, -------------- Report Sync ------------
     106Event: <span class="nb">time </span>1418930877.996939, <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>, code 1 <span class="o">(</span>Y<span class="o">)</span>, value -59
     107Event: <span class="nb">time </span>1418930877.996939, <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>, code 2 <span class="o">(</span>Z<span class="o">)</span>, value 670
     108Event: <span class="nb">time </span>1418930877.996939, -------------- Report Sync ------------
     109Event: <span class="nb">time </span>1418930878.116877, <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>, code 1 <span class="o">(</span>Y<span class="o">)</span>, value -58
     110Event: <span class="nb">time </span>1418930878.116877, -------------- Report Sync ------------
     111Event: <span class="nb">time </span>1418930878.236933, <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>, code 1 <span class="o">(</span>Y<span class="o">)</span>, value -64
     112Event: <span class="nb">time </span>1418930878.236933, -------------- Report Sync ------------
     113Event: <span class="nb">time </span>1418930878.356942, <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>, code 1 <span class="o">(</span>Y<span class="o">)</span>, value -66
     114Event: <span class="nb">time </span>1418930878.356942, -------------- Report Sync ------------
     115Event: <span class="nb">time </span>1418930878.476883, <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>, code 2 <span class="o">(</span>Z<span class="o">)</span>, value 659
     116Event: <span class="nb">time </span>1418930878.476883, -------------- Report Sync ------------
     117Event: <span class="nb">time </span>1418930878.716929, <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>, code 0 <span class="o">(</span>X<span class="o">)</span>, value 91
     118Event: <span class="nb">time </span>1418930878.716929, -------------- Report Sync ------------
     119Event: <span class="nb">time </span>1418930879.076878, <span class="nb">type </span>3 <span class="o">(</span>Absolute<span class="o">)</span>, code 2 <span class="o">(</span>Z<span class="o">)</span>, value 652
     120Event: <span class="nb">time </span>1418930879.076878, -------------- Report Sync ------------
     121^C
     122</pre></div><p>
     123References:
     124</p>
     125<ul><li><a class="ext-link" href="https://www.kernel.org/doc/Documentation/input/input.txt"><span class="icon">​</span>https://www.kernel.org/doc/Documentation/input/input.txt</a> - Linux Input API
     126</li><li><a class="ext-link" href="http://wiki.openmoko.org/wiki/Accelerometer_data_retrieval"><span class="icon">​</span>http://wiki.openmoko.org/wiki/Accelerometer_data_retrieval</a> - Example applications in several languages include a simple C application
     127</li></ul><h2 id="directi2caccess">direct <strong>i2c</strong> access</h2>
     128<p>
     129The FXOS8700 device is on the third (0 based) i2c bus at a slave address of 0x1e. Therefore you can access it directly without the need of a driver if necessary by knowing the register set from the datasheet.
     130</p>
     131<p>
     132Example script:
     133</p>
     134<div class="code"><pre><span class="c">#!/bin/sh
     135</span>
     136<span class="c"># set to active mode
     137</span>i2cset -f -y 2 0x1e 0x2a 1
     138<span class="c"># enable both accelerometer and magnetometer
     139</span>i2cset -f -y 2 0x1e 0x5b 3
     140
     141<span class="k">while</span> <span class="o">[</span> 1 <span class="o">]</span>; <span class="k">do</span>
     142  <span class="c"># accelerometer vector
     143</span>  <span class="nv">a_x</span><span class="o">=</span><span class="k">$((</span> <span class="k">$(</span> i2cget -f -y 2 0x1e 0x01 <span class="k">)</span> <span class="s">&lt;&lt; 8 | $( i2cget -f -y 2 0x1e 0x02 ) ))
     144  a_y=$(( $( i2cget -f -y 2 0x1e 0x03 ) &lt;&lt; 8</span> <span class="o">|</span> <span class="k">$(</span> i2cget -f -y 2 0x1e 0x04 <span class="k">)</span> <span class="k">))</span>
     145  <span class="nv">a_z</span><span class="o">=</span><span class="k">$((</span> <span class="k">$(</span> i2cget -f -y 2 0x1e 0x05 <span class="k">)</span> <span class="s">&lt;&lt; 8 | $( i2cget -f -y 2 0x1e 0x06 ) ))
     146
     147  # magnetometer vector
     148  m_x=$(( $( i2cget -f -y 2 0x1e 0x33 ) &lt;&lt; 8</span> <span class="o">|</span> <span class="k">$(</span> i2cget -f -y 2 0x1e 0x34 <span class="k">)</span> <span class="k">))</span>
     149  <span class="nv">m_y</span><span class="o">=</span><span class="k">$((</span> <span class="k">$(</span> i2cget -f -y 2 0x1e 0x35 <span class="k">)</span> <span class="s">&lt;&lt; 8 | $( i2cget -f -y 2 0x1e 0x36 ) ))
     150  m_z=$(( $( i2cget -f -y 2 0x1e 0x37 ) &lt;&lt; 8</span> <span class="o">|</span> <span class="k">$(</span> i2cget -f -y 2 0x1e 0x38 <span class="k">)</span> <span class="k">))</span>
     151
     152  <span class="nb">echo</span> <span class="s2">"$a_x/$a_y/$a_z $m_x/$m_y/$m_z"</span>
     153<span class="k">done</span>
     154</pre></div><p>
     155Running:
     156</p>
     157<div class="code"><pre>&gt; ./test
     15816312/768/1824 65476/65467/690
     15916240/704/2000 65469/65480/687
     16016280/688/1912 65498/65467/683
     16116304/688/1976 65482/65468/697
     16216288/720/1944 65463/65475/704
     16316312/656/1944 65477/65461/684
     16416312/688/2000 65477/65455/680
     16516240/592/1840 65486/65479/667
     16616336/672/1944 65483/65467/693
     16716336/672/1856 65469/65462/668
     16816352/736/1944 65491/65469/716
     16916272/672/1944 65489/65472/687^C
     170</pre></div
     171}}}