[[PageOutline]] = Accelerometer and Magnetometer = Many 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. Note 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. References: * [http://cache.freescale.com/files/sensors/doc/data_sheet/FXOS8700CQ.pdf?pspll=1 FXOS8700CQR1 Datasheet] == OS Support == The FXOS8700 used on many Ventana boards is supported in the following ways: ||= OpenWrt =||= Yocto =||= Android || || i2c/input || i2c/input || i2c/input/sensor HAL || == Android use via the Android sensor HAL == The 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. References: * ​http://www.tutorialspoint.com/android/android_sensors.htm == Linux input device access == The ​[https://www.kernel.org/doc/Documentation/input/input.txt Linux input device API] provides access to devices through a {{{/dev/input/event}}} interface. The FXOS8700 is supported via a linux input driver on all of the Gateworks BSP's. The {{{/sys/class/input/input/name}}} directories will show the device name responsible for the events within that directory which correspond to matching {{{/dev/input/event}}} entries. Additionally there will be an api for the input device in {{{/sys/devices/virtual/input/input/}}} 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). You 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. Example usage: {{{#!bash > cat /sys/devices/virtual/input/input2/name # show the name of the sensor fxos8700_m > cat /sys/devices/virtual/input/input2/position # show the orientation of the sensor 3 > echo 1 > /sys/devices/virtual/input/input2/enable # enable the sensor (take it out of standby mode) > evtest /dev/input/event2 # show info and values > evtest /dev/input/event2 Input driver version is 1.0.1 Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0 Input device name: "fxos8700_m" Supported events: Event type 0 (Sync) Event type 3 (Absolute) Event code 0 (X) Value 69 Min -8192 Max 8191 Fuzz 32 Flat 32 Event code 1 (Y) Value -31 Min -8192 Max 8191 Fuzz 32 Flat 32 Event code 2 (Z) Value 698 Min -8192 Max 8191 Fuzz 32 Flat 32 Testing ... (interrupt to exit) Event: time 1418930877.756913, type 3 (Absolute), code 0 (X), value 69 Event: time 1418930877.756913, type 3 (Absolute), code 1 (Y), value -62 Event: time 1418930877.756913, type 3 (Absolute), code 2 (Z), value 698 Event: time 1418930877.756913, -------------- Report Sync ------------ Event: time 1418930877.996939, type 3 (Absolute), code 1 (Y), value -59 Event: time 1418930877.996939, type 3 (Absolute), code 2 (Z), value 670 Event: time 1418930877.996939, -------------- Report Sync ------------ Event: time 1418930878.116877, type 3 (Absolute), code 1 (Y), value -58 Event: time 1418930878.116877, -------------- Report Sync ------------ Event: time 1418930878.236933, type 3 (Absolute), code 1 (Y), value -64 Event: time 1418930878.236933, -------------- Report Sync ------------ Event: time 1418930878.356942, type 3 (Absolute), code 1 (Y), value -66 Event: time 1418930878.356942, -------------- Report Sync ------------ Event: time 1418930878.476883, type 3 (Absolute), code 2 (Z), value 659 Event: time 1418930878.476883, -------------- Report Sync ------------ Event: time 1418930878.716929, type 3 (Absolute), code 0 (X), value 91 Event: time 1418930878.716929, -------------- Report Sync ------------ Event: time 1418930879.076878, type 3 (Absolute), code 2 (Z), value 652 Event: time 1418930879.076878, -------------- Report Sync ------------ }}} References: * ​https://www.kernel.org/doc/Documentation/input/input.txt - Linux Input API * http://wiki.openmoko.org/wiki/Accelerometer_data_retrieval - Example applications in several languages include a simple C application == direct i2c access == The 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. Example script: {{{#!bash #!/bin/sh # set to active mode i2cset -f -y 2 0x1e 0x2a 1 # enable both accelerometer and magnetometer i2cset -f -y 2 0x1e 0x5b 3 while [ 1 ]; do # accelerometer vector a_x=$(( $( i2cget -f -y 2 0x1e 0x01 ) << 8 | $( i2cget -f -y 2 0x1e 0x02 ) )) a_y=$(( $( i2cget -f -y 2 0x1e 0x03 ) << 8 | $( i2cget -f -y 2 0x1e 0x04 ) )) a_z=$(( $( i2cget -f -y 2 0x1e 0x05 ) << 8 | $( i2cget -f -y 2 0x1e 0x06 ) )) # magnetometer vector m_x=$(( $( i2cget -f -y 2 0x1e 0x33 ) << 8 | $( i2cget -f -y 2 0x1e 0x34 ) )) m_y=$(( $( i2cget -f -y 2 0x1e 0x35 ) << 8 | $( i2cget -f -y 2 0x1e 0x36 ) )) m_z=$(( $( i2cget -f -y 2 0x1e 0x37 ) << 8 | $( i2cget -f -y 2 0x1e 0x38 ) )) echo "$a_x/$a_y/$a_z $m_x/$m_y/$m_z" done }}} Running: {{{#!bash > ./test 16312/768/1824 65476/65467/690 16240/704/2000 65469/65480/687 16280/688/1912 65498/65467/683 16304/688/1976 65482/65468/697 16288/720/1944 65463/65475/704 16312/656/1944 65477/65461/684 16312/688/2000 65477/65455/680 16240/592/1840 65486/65479/667 16336/672/1944 65483/65467/693 16336/672/1856 65469/65462/668 16352/736/1944 65491/65469/716 16272/672/1944 65489/65472/687 }}}