Changes between Version 1 and Version 2 of ventana/accelerometer


Ignore:
Timestamp:
01/15/2018 09:49:08 AM (6 weeks ago)
Author:
Tim Harvey
Comment:

convert restored html to wiki markup

Legend:

Unmodified
Added
Removed
Modified
  • ventana/accelerometer

    v1 v2  
    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>
    27 Many 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>
     1[[PageOutline]]
     2
     3= Accelerometer and Magnetometer =
     4Many Ventana models come standard with an Accelerometer and Magnetometer on a single ​[http://cache.freescale.com/files/sensors/doc/data_sheet/FXOS8700CQ.pdf?pspll=1 FXOS8700CQR1 ] IC.
     5
    306Note 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>
     7
    338References:
    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>
     9 * [http://cache.freescale.com/files/sensors/doc/data_sheet/FXOS8700CQ.pdf?pspll=1 FXOS8700CQR1 Datasheet]
     10
     11== OS Support ==
    3812The 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)
     13||= OpenWrt =||= Yocto =||= Android ||
     14|| i2c/input || i2c/input || i2c/input/sensor HAL ||
    4315
    44 This 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>
     16== Android use via the Android sensor HAL ==
    4817The 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>
     18
    5119References:
    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>
    56 The <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>
    59 The <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>
    62 Additionally 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>
     20 * ​http://www.tutorialspoint.com/android/android_sensors.htm
     21
     22
     23== Linux input device access ==
     24The ​[https://www.kernel.org/doc/Documentation/input/input.txt Linux input device API] provides access to devices through a {{{/dev/input/event<n>}}} interface. The FXOS8700 is supported via a linux input driver on all of the Gateworks BSP's.
     25
     26The {{{/sys/class/input/input<n>/name}}} directories will show the device name responsible for the events within that directory which correspond to matching {{{/dev/input/event<n>}}} entries.
     27
     28Additionally there will be an api for the input device in {{{/sys/devices/virtual/input/input<n>/}}} 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).
     29
    6530You 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>
     31
    6832Example 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
     33{{{#!bash
     34> cat /sys/devices/virtual/input/input2/name # show the name of the sensor
     35fxos8700_m
     36> cat /sys/devices/virtual/input/input2/position # show the orientation of the sensor
     373
     38> echo 1 > /sys/devices/virtual/input/input2/enable # enable the sensor (take it out of standby mode)
     39> evtest /dev/input/event2 # show info and values
     40> evtest /dev/input/event2
    7741Input driver version is 1.0.1
    7842Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0
    79 Input device name: <span class="s2">"fxos8700_m"</span>
     43Input device name: "fxos8700_m"
    8044Supported 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>
     45  Event type 0 (Sync)
     46  Event type 3 (Absolute)
     47    Event code 0 (X)
    8448      Value     69
    8549      Min    -8192
     
    8751      Fuzz      32
    8852      Flat      32
    89     Event code 1 <span class="o">(</span>Y<span class="o">)</span>
     53    Event code 1 (Y)
    9054      Value    -31
    9155      Min    -8192
     
    9357      Fuzz      32
    9458      Flat      32
    95     Event code 2 <span class="o">(</span>Z<span class="o">)</span>
     59    Event code 2 (Z)
    9660      Value    698
    9761      Min    -8192
     
    9963      Fuzz      32
    10064      Flat      32
    101 Testing ... <span class="o">(</span>interrupt to <span class="nb">exit</span><span class="o">)</span>
    102 Event: <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
    103 Event: <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
    104 Event: <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
    105 Event: <span class="nb">time </span>1418930877.756913, -------------- Report Sync ------------
    106 Event: <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
    107 Event: <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
    108 Event: <span class="nb">time </span>1418930877.996939, -------------- Report Sync ------------
    109 Event: <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
    110 Event: <span class="nb">time </span>1418930878.116877, -------------- Report Sync ------------
    111 Event: <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
    112 Event: <span class="nb">time </span>1418930878.236933, -------------- Report Sync ------------
    113 Event: <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
    114 Event: <span class="nb">time </span>1418930878.356942, -------------- Report Sync ------------
    115 Event: <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
    116 Event: <span class="nb">time </span>1418930878.476883, -------------- Report Sync ------------
    117 Event: <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
    118 Event: <span class="nb">time </span>1418930878.716929, -------------- Report Sync ------------
    119 Event: <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
    120 Event: <span class="nb">time </span>1418930879.076878, -------------- Report Sync ------------
    121 ^C
    122 </pre></div><p>
     65Testing ... (interrupt to exit)
     66Event: time 1418930877.756913, type 3 (Absolute), code 0 (X), value 69
     67Event: time 1418930877.756913, type 3 (Absolute), code 1 (Y), value -62
     68Event: time 1418930877.756913, type 3 (Absolute), code 2 (Z), value 698
     69Event: time 1418930877.756913, -------------- Report Sync ------------
     70Event: time 1418930877.996939, type 3 (Absolute), code 1 (Y), value -59
     71Event: time 1418930877.996939, type 3 (Absolute), code 2 (Z), value 670
     72Event: time 1418930877.996939, -------------- Report Sync ------------
     73Event: time 1418930878.116877, type 3 (Absolute), code 1 (Y), value -58
     74Event: time 1418930878.116877, -------------- Report Sync ------------
     75Event: time 1418930878.236933, type 3 (Absolute), code 1 (Y), value -64
     76Event: time 1418930878.236933, -------------- Report Sync ------------
     77Event: time 1418930878.356942, type 3 (Absolute), code 1 (Y), value -66
     78Event: time 1418930878.356942, -------------- Report Sync ------------
     79Event: time 1418930878.476883, type 3 (Absolute), code 2 (Z), value 659
     80Event: time 1418930878.476883, -------------- Report Sync ------------
     81Event: time 1418930878.716929, type 3 (Absolute), code 0 (X), value 91
     82Event: time 1418930878.716929, -------------- Report Sync ------------
     83Event: time 1418930879.076878, type 3 (Absolute), code 2 (Z), value 652
     84Event: time 1418930879.076878, -------------- Report Sync ------------
     85}}}
     86
    12387References:
    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>
     88 * ​https://www.kernel.org/doc/Documentation/input/input.txt - Linux Input API
     89 * http://wiki.openmoko.org/wiki/Accelerometer_data_retrieval - Example applications in several languages include a simple C application
     90
     91
     92== direct i2c access ==
    12993The 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>
     94
    13295Example 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
     96{{{#!bash
     97#!/bin/sh
    14098
    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 ) ))
     99# set to active mode
     100i2cset -f -y 2 0x1e 0x2a 1
     101# enable both accelerometer and magnetometer
     102i2cset -f -y 2 0x1e 0x5b 3
     103
     104while [ 1 ]; do
     105  # accelerometer vector
     106  a_x=$(( $( i2cget -f -y 2 0x1e 0x01 ) << 8 | $( i2cget -f -y 2 0x1e 0x02 ) ))
     107  a_y=$(( $( i2cget -f -y 2 0x1e 0x03 ) << 8 | $( i2cget -f -y 2 0x1e 0x04 ) ))
     108  a_z=$(( $( i2cget -f -y 2 0x1e 0x05 ) << 8 | $( i2cget -f -y 2 0x1e 0x06 ) ))
    146109
    147110  # 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>
     111  m_x=$(( $( i2cget -f -y 2 0x1e 0x33 ) << 8 | $( i2cget -f -y 2 0x1e 0x34 ) ))
     112  m_y=$(( $( i2cget -f -y 2 0x1e 0x35 ) << 8 | $( i2cget -f -y 2 0x1e 0x36 ) ))
     113  m_z=$(( $( i2cget -f -y 2 0x1e 0x37 ) << 8 | $( i2cget -f -y 2 0x1e 0x38 ) ))
    151114
    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>
     115  echo "$a_x/$a_y/$a_z $m_x/$m_y/$m_z"
     116done
     117}}}
     118
    155119Running:
    156 </p>
    157 <div class="code"><pre>&gt; ./test
     120{{{#!bash
     121> ./test
    15812216312/768/1824 65476/65467/690
    15912316240/704/2000 65469/65480/687
     
    16713116336/672/1856 65469/65462/668
    16813216352/736/1944 65491/65469/716
    169 16272/672/1944 65489/65472/687^C
    170 </pre></div
     13316272/672/1944 65489/65472/687
    171134}}}