Skip to content

Instantly share code, notes, and snippets.

@pdp7
Last active September 8, 2019 06:16
Show Gist options
  • Save pdp7/cd47cdc2a6747c8b01a5 to your computer and use it in GitHub Desktop.
Save pdp7/cd47cdc2a6747c8b01a5 to your computer and use it in GitHub Desktop.
BeagleBone Green: ADXL345 Grove Acceleromter sensor

Overview

Device Tree Overlay

debian@beaglebone:~$ cat dtc/bb.org-overlays/src/arm/BB-BONE-ADXL345-00A0.dts
/*
 * For ADI ADXL345 Accelerometer:
 * 
 * This Device Tree Overlay is based on:
 * BB-BONE-CRYPTO-00A0.dts
 * Cape support for the CryptoCape
 * Copyright (C) 2014 Cryptotronix
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
/dts-v1/;
/plugin/;

#include <dt-bindings/board/am335x-bbw-bbb-base.h>
#include <dt-bindings/pinctrl/am33xx.h>

/ {
	compatible = "ti,beaglebone", "ti,beaglebone-black", "ti,beaglebone-green";

	/* identification */
	part-number = "BB-BONE-ADXL345";
	version = "00A0";

	fragment@0 {
		target = <&i2c2>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;

			adxl345@0 {
				compatible = "adi,adxl345";
				reg = <0x53>;
				interrupt-parent = <&gpio3>;
				interrupts = <19 0x0>;
			};
		};
	};
};

Load Driver

root@beaglebone:~# i2cdetect -r -y 2
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- 53 UU UU UU UU -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

root@beaglebone:~# echo '7 7 7 7' > /proc/sys/kernel/printk

root@beaglebone:~# modprobe adxl34x
root@beaglebone:~# modprobe adxl34x-i2c

root@beaglebone:~# lsmod
Module                  Size  Used by
adxl34x_i2c             3532  0 
adxl34x                10321  1 adxl34x_i2c

root@beaglebone:~# echo BB-BONE-ADXL345 > /sys/devices/platform/bone_capemgr/slots

root@beaglebone:~# dmesg
[  119.223587] bone_capemgr bone_capemgr: part_number 'BB-BONE-ADXL345', version 'N/A'
[  119.223628] bone_capemgr bone_capemgr: slot #4: override
[  119.223644] bone_capemgr bone_capemgr: Using override eeprom data at slot 4
[  119.223661] bone_capemgr bone_capemgr: slot #4: 'Override Board Name,00A0,Override Manuf,BB-BONE-ADXL345'
[  119.239210] adxl34x_i2c_probe: client=dd9ba400
[  119.243878] adxl34x_i2c_probe: id=  (null)
[  119.248239] adxl34x_i2c_probe: error=1
[  119.250619] adxl34x_probe: irq=145
[  119.259811] adxl34x_probe: pdata=  (null)
[  119.263191] adxl34x_probe: revid=229
[  119.267860] adxl34x_probe: sysfs_create_group returned err=0
[  119.279548] input: ADXL34x accelerometer as /devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2
[  119.282231] adxl34x_probe: input_register_device returned err=0
[  119.303226] adxl34x_probe: return ac=-604340736
[  119.308160] adxl34x_i2c_probe: ac=dbfa7e00
[  119.316952] bone_capemgr bone_capemgr: slot #4: dtbo 'BB-BONE-ADXL345-00A0.dtbo' loaded; overlay id #0

root@beaglebone:~#  cat /proc/interrupts 
           CPU0       
 16:      35886      INTC  68 Level     gp_timer
 19:          1      INTC  78 Level     wkup_m3_txev
 20:       8448      INTC  12 Level     49000000.edma_ccint
 22:         91      INTC  14 Level     49000000.edma_ccerrint
 26:          0      INTC  96 Level     44e07000.gpio
 33:          0  44e07000.gpio   6 Edge      48060000.mmc cd
 59:          0      INTC  98 Level     4804c000.gpio
 92:          0      INTC  32 Level     481ac000.gpio
125:          0      INTC  62 Level     481ae000.gpio
145:          0  481ae000.gpio  19 Level     2-0053
158:        101      INTC  72 Level     OMAP UART0
159:       1035      INTC  70 Level     44e0b000.i2c
160:         80      INTC  30 Level     4819c000.i2c
161:      29050      INTC  64 Level     mmc0
163:          0      INTC  77 Level     wkup_m3
169:          0      INTC  75 Level     rtc0
170:          0      INTC  76 Level     rtc0
174:       4045      INTC  41 Level     4a100000.ethernet
175:       4123      INTC  42 Level     4a100000.ethernet
179:          0      INTC  80 Level     48038000.mcasp_tx
180:          0      INTC  81 Level     48038000.mcasp_rx
181:          0      INTC  82 Level     4803c000.mcasp_tx
182:          0      INTC  83 Level     4803c000.mcasp_rx
183:          0      INTC 111 Level     48310000.rng
184:          0      INTC  18 Level     musb-hdrc.0.auto
185:          1      INTC  19 Level     musb-hdrc.1.auto
186:          0      INTC  17 Level     47400000.dma-controller
187:          0      INTC   7 Level     tps65217
IPI0:          0  CPU wakeup interrupts
IPI1:          0  Timer broadcast interrupts
IPI2:          0  Rescheduling interrupts
IPI3:          0  Function call interrupts
IPI4:          0  CPU stop interrupts
IPI5:          0  IRQ work interrupts
IPI6:          0  completion interrupts
Err:          0


root@beaglebone:~# find /sys -type f |grep 2-0053 | grep -v /power/ |xargs more 
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/name
::::::::::::::
adxl345
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/rate
::::::::::::::
8
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/disable
::::::::::::::
0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/id/version
::::::::::::::
0000
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/id/vendor
::::::::::::::
0000
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/id/product
::::::::::::::
0159
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/id/bustype
::::::::::::::
0018
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/name
::::::::::::::
ADXL34x accelerometer
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/phys
::::::::::::::
2-0053/input0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/uniq
::::::::::::::

::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/modalias
::::::::::::::
input:b0018v0000p0159e0000-e0,1,3,k14A,ra0,1,2,mlsfw
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/event2/dev
::::::::::::::
13:66
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/event2/uevent
::::::::::::::
MAJOR=13
MINOR=66
DEVNAME=input/event2
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/properties
::::::::::::::
0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/mouse0/dev
::::::::::::::
13:32
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/mouse0/uevent
::::::::::::::
MAJOR=13
MINOR=32
DEVNAME=input/mouse0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/uevent
::::::::::::::
PRODUCT=18/0/159/0
NAME="ADXL34x accelerometer"
PHYS="2-0053/input0"
PROP=0
EV=b
KEY=400 0 0 0 0 0 0 0 0 0 0
ABS=7
MODALIAS=input:b0018v0000p0159e0000-e0,1,3,k14A,ra0,1,2,mlsfw
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/capabilities/ff
::::::::::::::
0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/capabilities/ev
::::::::::::::
b
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/capabilities/sw
::::::::::::::
0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/capabilities/abs
::::::::::::::
7
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/capabilities/key
::::::::::::::
400 0 0 0 0 0 0 0 0 0 0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/capabilities/led
::::::::::::::
0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/capabilities/msc
::::::::::::::
0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/capabilities/rel
::::::::::::::
0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/input/input2/capabilities/snd
::::::::::::::
0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/modalias
::::::::::::::
i2c:adxl345
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/position
::::::::::::::
(0, 0, 0)
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/calibrate
::::::::::::::
0,0,0
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/uevent
::::::::::::::
DRIVER=adxl34x
OF_NAME=adxl345
OF_FULLNAME=/ocp/i2c@4819c000/adxl345@0
OF_COMPATIBLE_0=adi,adxl345
OF_COMPATIBLE_N=1
MODALIAS=i2c:adxl345
::::::::::::::
/sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0053/autosleep
::::::::::::::
1
root@beaglebone:~#      

root@beaglebone:~# evtest 
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:	Speakup
/dev/input/event1:	tps65217_pwr_but
/dev/input/event2:	ADXL34x accelerometer
Select the device event number [0-2]: 2
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x0 product 0x159 version 0x0
Input device name: "ADXL34x accelerometer"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 330 (BTN_TOUCH)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value      0
      Min    -4096
      Max     4096
      Fuzz       3
      Flat       3
    Event code 1 (ABS_Y)
      Value      0
      Min    -4096
      Max     4096
      Fuzz       3
      Flat       3
    Event code 2 (ABS_Z)
      Value      0
      Min    -4096
      Max     4096
      Fuzz       3
      Flat       3
Properties:
Testing ... (interrupt to exit)


@pdp7
Copy link
Author

pdp7 commented Mar 2, 2016

I'm running Linux 4.5-rc4 built with Robert's linux-dev scripts:
https://github.com/RobertCNelson/linux-dev

@pdp7
Copy link
Author

pdp7 commented Mar 2, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment