Changes between Version 12 and Version 13 of accelerometer


Ignore:
Timestamp:
10/10/2024 08:55:02 PM (8 days ago)
Author:
Tim Harvey
Comment:

removed old linux input driver details and direct I2C bus access details; Linux IIO drivers should be used on all modern kernels

Legend:

Unmodified
Added
Removed
Modified
  • accelerometer

    v12 v13  
    22
    33= Accelerometer and Magnetometer
    4 Many Gateworks board families including ventana and newport come standard with either an Accelerometer, Magnetometer, or other inertial measurement unit (IMU) on a single IC.
     4Many Gateworks board families come standard with either an Accelerometer, Magnetometer, or other inertial measurement unit (IMU) options.
    55
    66== Supported Devices
    7 The specific IMUs used on our boards are described by the following table:
     7The specific devices used on our boards are described by the following table:
    88
    99||= '''Family''' =||= '''Board''' =||= '''Device''' =||= '''Location''' =||
     
    4242|| LIS2MDL magnetometer || iio || IIO_ST_MAGN_I2C_3AXIS ||
    4343|| LSM9DS1 imu || iio || IIO_ST_MAGN_I2C_3AXIS (mag) IIO_ST_LSM6DSX_I2C (accel/gyro) ||
    44 || FXOS8700 accelerometer (3.14/4.4 kernel) || input || INPUT_MMA8451 ||
    45 || FXOS8700 accelerometer (4.19+ kernel)    || iio || FXOS8700_I2C ||
     44|| FXOS8700 accelerometer || iio || FXOS8700_I2C ||
    4645
    4746
    4847
    4948[=#iio]
    50 === Linux industrial I/O (newer kernels)
     49=== Linux industrial I/O bus
    5150The modern approach to IMU devices is to use the [https://www.kernel.org/doc/html/v4.12/driver-api/iio/index.html Linux IIO subsystem]. IIO aims to fill the gap between the somewhat similar {{{hwmon}}} and {{{input}}} subsystems. While the {{{hwmon}}} API is directed at low sample rate sensors (like fan speed control or temperature measurement) the {{{input}}} API is focused on human interaction input devices (keyboard, mouse, touchscreen). In some cases there is considerable
    5251overlap between these and the {{{iio}}} API.
     
    141140 * https://elinux.org/images/a/ac/Clausen.pdf
    142141
    143 [=#input]
    144 === Linux input device access (older kernels)
    145 The ​[https://www.kernel.org/doc/Documentation/input/input.txt Linux input device API] provides access to devices through a {{{/dev/input/event<n>}}} interface. Some of the older kernel's support IMU's via a linux input driver.
    146 
    147 The {{{/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.
    148 
    149 Additionally 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).
    150 
    151 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.
    152 
    153 Example usage:
    154 {{{#!bash
    155 > cat /sys/devices/virtual/input/input2/name # show the name of the sensor
    156 fxos8700_m
    157 > cat /sys/devices/virtual/input/input2/position # show the orientation of the sensor
    158 3
    159 > echo 1 > /sys/devices/virtual/input/input2/enable # enable the sensor (take it out of standby mode)
    160 > evtest /dev/input/event2 # show info and values
    161 > evtest /dev/input/event2
    162 Input driver version is 1.0.1
    163 Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0
    164 Input device name: "fxos8700_m"
    165 Supported events:
    166   Event type 0 (Sync)
    167   Event type 3 (Absolute)
    168     Event code 0 (X)
    169       Value     69
    170       Min    -8192
    171       Max     8191
    172       Fuzz      32
    173       Flat      32
    174     Event code 1 (Y)
    175       Value    -31
    176       Min    -8192
    177       Max     8191
    178       Fuzz      32
    179       Flat      32
    180     Event code 2 (Z)
    181       Value    698
    182       Min    -8192
    183       Max     8191
    184       Fuzz      32
    185       Flat      32
    186 Testing ... (interrupt to exit)
    187 Event: time 1418930877.756913, type 3 (Absolute), code 0 (X), value 69
    188 Event: time 1418930877.756913, type 3 (Absolute), code 1 (Y), value -62
    189 Event: time 1418930877.756913, type 3 (Absolute), code 2 (Z), value 698
    190 Event: time 1418930877.756913, -------------- Report Sync ------------
    191 Event: time 1418930877.996939, type 3 (Absolute), code 1 (Y), value -59
    192 Event: time 1418930877.996939, type 3 (Absolute), code 2 (Z), value 670
    193 Event: time 1418930877.996939, -------------- Report Sync ------------
    194 Event: time 1418930878.116877, type 3 (Absolute), code 1 (Y), value -58
    195 Event: time 1418930878.116877, -------------- Report Sync ------------
    196 Event: time 1418930878.236933, type 3 (Absolute), code 1 (Y), value -64
    197 Event: time 1418930878.236933, -------------- Report Sync ------------
    198 Event: time 1418930878.356942, type 3 (Absolute), code 1 (Y), value -66
    199 Event: time 1418930878.356942, -------------- Report Sync ------------
    200 Event: time 1418930878.476883, type 3 (Absolute), code 2 (Z), value 659
    201 Event: time 1418930878.476883, -------------- Report Sync ------------
    202 Event: time 1418930878.716929, type 3 (Absolute), code 0 (X), value 91
    203 Event: time 1418930878.716929, -------------- Report Sync ------------
    204 Event: time 1418930879.076878, type 3 (Absolute), code 2 (Z), value 652
    205 Event: time 1418930879.076878, -------------- Report Sync ------------
    206 }}}
    207 
    208 References:
    209  * ​[https://www.kernel.org/doc/Documentation/input/input.txt Linux Input API]
    210  * [http://wiki.openmoko.org/wiki/Accelerometer_data_retrieval Example applications in several languages include a simple C application]
    211 
    212142
    213143[=#android]
     
    218148 * ​http://www.tutorialspoint.com/android/android_sensors.htm
    219149
    220 
    221 [=#i2cget]
    222 === Direct i2c Access
    223 This section provides examples for some typical methods of communicating with the IMUs on the i2c bus. The FXOS8700 information will be used but can be adjusted to match the address of the device present on your board. Refer to the linked datasheets to see more detailed register information.
    224 
    225 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.
    226 
    227 Example script:
    228 {{{#!bash
    229 #!/bin/sh
    230 
    231 # set to active mode
    232 i2cset -f -y 2 0x1e 0x2a 1
    233 # enable both accelerometer and magnetometer
    234 i2cset -f -y 2 0x1e 0x5b 3
    235 
    236 while [ 1 ]; do
    237   # accelerometer vector
    238   a_x=$(( $( i2cget -f -y 2 0x1e 0x01 ) << 8 | $( i2cget -f -y 2 0x1e 0x02 ) ))
    239   a_y=$(( $( i2cget -f -y 2 0x1e 0x03 ) << 8 | $( i2cget -f -y 2 0x1e 0x04 ) ))
    240   a_z=$(( $( i2cget -f -y 2 0x1e 0x05 ) << 8 | $( i2cget -f -y 2 0x1e 0x06 ) ))
    241 
    242   # magnetometer vector
    243   m_x=$(( $( i2cget -f -y 2 0x1e 0x33 ) << 8 | $( i2cget -f -y 2 0x1e 0x34 ) ))
    244   m_y=$(( $( i2cget -f -y 2 0x1e 0x35 ) << 8 | $( i2cget -f -y 2 0x1e 0x36 ) ))
    245   m_z=$(( $( i2cget -f -y 2 0x1e 0x37 ) << 8 | $( i2cget -f -y 2 0x1e 0x38 ) ))
    246 
    247   echo "$a_x/$a_y/$a_z $m_x/$m_y/$m_z"
    248 done
    249 }}}
    250 
    251 Running:
    252 {{{#!bash
    253 > ./test
    254 16312/768/1824 65476/65467/690
    255 16240/704/2000 65469/65480/687
    256 16280/688/1912 65498/65467/683
    257 16304/688/1976 65482/65468/697
    258 16288/720/1944 65463/65475/704
    259 16312/656/1944 65477/65461/684
    260 16312/688/2000 65477/65455/680
    261 16240/592/1840 65486/65479/667
    262 16336/672/1944 65483/65467/693
    263 16336/672/1856 65469/65462/668
    264 16352/736/1944 65491/65469/716
    265 16272/672/1944 65489/65472/687
    266 }}}