O'Reilly logo

Programming the BeagleBone by Yogesh Chavan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Program to read from ADXL345 sensor

Connect the ADXL345 module to BeagleBone as shown in the diagram. Type the following program in Cloud9, save it as ADXL345.py and run it. You should see a three-axis coordinates list printed after every 2 seconds. If you move the sensor, you will see a change in coordinates.

from Adafruit_I2C import Adafruit_I2C import time ADXL345_I2C_ID = 0x53 # I2C bus id ADXL345_REG_POWER_CTL = 0x2D # Power-saving control ADXL345_REG_DATAX0 = 0x32 # X-axis data 0 accel = Adafruit_I2C(ADXL345_I2C_ID,debug=False) accel.write8(ADXL345_REG_POWER_CTL, 0x08) while True: raw = accel.readList(ADXL345_REG_DATAX0, 6) result = [] for i in range(0, 6, 2): g = raw[i] | (raw[i+1] << 8) if g > 32767: g -= 65536 result.append(g) print "result ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required