Python Code to Interface ADXL345 with Raspberry Pi

#The ADXL345 is a small, thin, low power, 3-axis accelerometer
#with high resolution (13-bit) measurement at up to ±16g.
#ADXL345 is connected through I2C interface.
#SDA->Pin3(I2C Data)
#SCL->Pin5(I2C Clock)
#Vcc->Pin1(3.3v)
#Gnd->Pin6(0v)

#import the adxl345 module
import adxl345

#create ADXL345 object
accel = adxl345.ADXL345()

#get axes as g
axes = accel.getAxes(True)
# to get axes as ms^2 use
#axes = accel.getAxes(False)

#put the axes into variables
x = axes[‘x’]
y = axes[‘y’]
z = axes[‘z’]

#print axes
print x
print y
print z