This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
resources:tools-software:android-drivers:sensor-acceleration:adxl345 [08 Nov 2011 16:42] – [Platform data configuration] fix dead link Lars-Peter Clausen | resources:tools-software:android-drivers:sensor-acceleration:adxl345 [03 Jan 2013 20:42] – external edit | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== ADXL345/6 Android Acceleration Sensor ====== | ||
+ | Using the ADXL345/6 under Android as Acceleration Sensor | ||
+ | |||
+ | {{: | ||
+ | |||
+ | The ADXL345/6 can be easily used as Android Acceleration Sensor. | ||
+ | A few steps are necessary to add appropriate sensor support. | ||
+ | |||
+ | ===== Add Linux Driver Support: ===== | ||
+ | |||
+ | Starting with linux-2.6.36 the ADXL34x driver is mainlined. | ||
+ | If you are using an pre linux-2.6.36 kernel get the source from our repositories and add them to your kernel tree. | ||
+ | |||
+ | Example platform data: | ||
+ | |||
+ | <code c> | ||
+ | #include < | ||
+ | static const struct adxl34x_platform_data adxl34x_info = { | ||
+ | .x_axis_offset = 0, | ||
+ | .y_axis_offset = 0, | ||
+ | .z_axis_offset = 0, | ||
+ | .tap_threshold = 0x31, | ||
+ | .tap_duration = 0x10, | ||
+ | .tap_latency = 0x60, | ||
+ | .tap_window = 0xF0, | ||
+ | .tap_axis_control = 0, | ||
+ | .act_axis_control = 0xFF, | ||
+ | .activity_threshold = 5, | ||
+ | .inactivity_threshold = 3, | ||
+ | .inactivity_time = 4, | ||
+ | .free_fall_threshold = 0x7, | ||
+ | .free_fall_time = 0x20, | ||
+ | .data_rate = 0x8, | ||
+ | .data_range = ADXL_FULL_RES, | ||
+ | |||
+ | .ev_type = EV_ABS, | ||
+ | .ev_code_x = ABS_X, /* EV_REL */ | ||
+ | .ev_code_y = ABS_Y, /* EV_REL */ | ||
+ | .ev_code_z = ABS_Z, /* EV_REL */ | ||
+ | |||
+ | .ev_code_tap = {BTN_0, BTN_1, BTN_2}, /* EV_KEY x,y,z */ | ||
+ | |||
+ | / | ||
+ | / | ||
+ | .power_mode = ADXL_AUTO_SLEEP | ADXL_LINK, | ||
+ | .fifo_mode = ADXL_FIFO_STREAM, | ||
+ | .orientation_enable = 0, /* Disable Orientation Reports */ | ||
+ | .deadzone_angle = ADXL_DEADZONE_ANGLE_10p8, | ||
+ | .divisor_length = ADXL_LP_FILTER_DIVISOR_16, | ||
+ | /* EV_KEY {+Z, +Y, +X, -X, -Y, -Z} */ | ||
+ | .ev_codes_orient_3d = {BTN_Z, BTN_Y, BTN_X, BTN_A, BTN_B, BTN_C}, | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | ===== Create an Android sensor library ===== | ||
+ | |||
+ | The readme file in libhardware states: | ||
+ | The source code for the " | ||
+ | The source code for " | ||
+ | |||
+ | The sensor file is typically source code for the " | ||
+ | However for simplicity this example puts it into a common folder structure under libhardware/ | ||
+ | |||
+ | * Create an sensors folder under libhardware/ | ||
+ | |||
+ | * Copy files sensors_adxl34x.c and Android.mk to libhardware/ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | **The files can be downloaded here:**\\ | ||
+ | |||
+ | [[bf> | ||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | * Make sure the makefile in the higher folder hierarchy picks up the one in libhardware/ | ||
+ | |||
+ | * Add following lines to: libhardware/ | ||
+ | |||
+ | < | ||
+ | include $(addsuffix / | ||
+ | modules/ | ||
+ | )) | ||
+ | </ | ||
+ | |||
+ | In your platforms init.rc file make sure all ADXL34x drivers sysfs files {disable, rate} are owned by system: | ||
+ | |||
+ | * Add following lines to your init.rc script: | ||
+ | |||
+ | < | ||
+ | chown system system / | ||
+ | chown system system / | ||
+ | </ | ||
+ | |||
+ | <WRAP tip> | ||
+ | In case the ADXL345/6 is not always event0 you can alternatively approach via / | ||
+ | </ | ||
+ | |||
+ | * Rebuilt your Android tree | ||
+ | |||
+ | <WRAP tip> | ||
+ | Upon start the Android log file (use logcat) should include following lines: | ||
+ | |||
+ | < | ||
+ | I/ | ||
+ | [--snip--] | ||
+ | D/ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Hints ===== | ||
+ | |||
+ | ==== Sample Rate ==== | ||
+ | |||
+ | The ADXL345/6 sample rate is configurable. | ||
+ | The maximum sample rate is by default limited to 200Hz, to change this limit modify define ADXL_MAX_SAMPLE_RATE_VAL in the sensor file. | ||
+ | |||
+ | <WRAP alert> | ||
+ | Very high sample rates > 400Hz can freeze your system! | ||
+ | </ | ||
+ | |||
+ | <source master/ | ||
+ | |||
+ | ==== Platform data configuration ==== | ||
+ | |||
+ | === Don't use BTN_TOUCH === | ||
+ | |||
+ | In case you experience strange input device gui interaction it might be the case that Android EventHub included the ADXL34x as input device. | ||
+ | This is typically the case if you put an BTN_TOUCH key into your ADXL34x drivers platform data. | ||
+ | |||
+ | Upon start EventHub must emit classes=0x0: | ||
+ | < | ||
+ | I/EventHub( 1862): New device: path=/ | ||
+ | </ | ||
+ | classes=0x4 means that the ADXL34x driver is considered as Touchscreen. | ||
+ | |||
+ | === Auto Sleep === | ||
+ | |||
+ | The default platform configuration sets the driver automatically switch to sleep mode during periods of inactivity. | ||
+ | To disable this feature remove ADXL_AUTO_SLEEP from power_mode. | ||
+ | |||
+ | Alternatively during runtime: | ||
+ | < | ||
+ | #echo 0 > / | ||
+ | </ | ||
+ | |||
+ | For more information visit the [[resources/ | ||
+ | |||
+ | |||
+ | ==== The Sources ==== | ||
+ | <source master/ | ||
+ | |||
+ | <source master/ |