My project is using two TMP102's, one BMP180, and one ADXL345, all on I2C (there are a few other items, but not on I2C).

I'm having no issues with anything but the ADXL345. Even when it's the only thing connected, it's usually not showing up in the i2cdetect list.


3.3V -> VCC
Gnd -> Gnd

I can get it to show up in a few circumstances:

  • when I tie the CS to VCC/3.3V, it shows up as 0x53 and the code doesn't crash, but the readings are all locked at some random value

  • when I tie the SDO to VCC with a 10k resistor (to not draw much current), it shows up as 0x08, but there's still an IO error from the code

I have two of these that I've swapped out and tried, and have even tried with a Pololu ADXL345 breakout, all with the same issue, so I don't think that the board's fried.


from Tkinter import *
import RPi.GPIO as GPIO
import smbus
import time
import Adafruit_BMP.BMP085 as BMP085
import serial
import adxl345

starttime = time.time()

#sensor objects
sensor = BMP085.BMP085()
accel = adxl345.ADXL345()

#G-M uses serial
ser = serial.Serial('/dev/ttyUSB0',9600)

#BMP stuff
bus = smbus.SMBus(1)

#ADXL stuff
axes = accel.getAxes(False) #gives a in m/s^2; True for g
accel.setRange(adxl345.RANGE_4G) #2G,4G,8G,16G available

def readAccel():
    return [axes['x'],axes['y'],axes['z']]

def readT(sensor):
    if sensor == 1:
        addr = 0x48
    elif sensor == 2:
        addr = 0x49
    data = bus.read_i2c_block_data(addr,0)
    return (((data[0] <<8) | data[1]) >> 4) *.0625

def readBMP(thing):
    if thing == 'T':
        return sensor.read_temperature()
    elif thing == 'P':
        return sensor.read_pressure()

#clear buffer

GPIO.setup(23, GPIO.OUT)

for i in range(0,21):
    elapsed = time.time()-starttime
    print time.strftime('%I:%M:%S'), 'Elapsed time:', round(elapsed),'s'

    print 'Temp 1:',readT(1),'C; Temp 2:', readT(2),'C; BMP Temp:', readBMP('T'),'C'
    print 'Pressure:',readBMP('P'),'Pa; Accel:', readAccel()
    print ser.readline()


2 Answers 2


The correct I2C address is 0x53, so you need (at least) to strap CS to Vcc.

Check the documentation for you module. Mine required two lines strapped.

  • The documentation is scarce - Sparkfun's site's startup has only four lines used (VCC, Gnd, SDA, SCL). It's for Arduino, and I didn't think that it would make a difference, but maybe it does. Which other line might it be?
    – DeltaG
    Commented Jan 14, 2016 at 13:53
  • @DeltaG Have a look at the ADXL345 spec. It tells you how the device differentiates between SPI and I2C mode. That should make clear which lines need strapping.
    – joan
    Commented Jan 14, 2016 at 13:59
  • The ADXL datasheet doesn't include whatever's happening on the breakout, though, which is my issue. I think that I might be having an issue with how the SF breakout, in particular, is wired.
    – DeltaG
    Commented Jan 14, 2016 at 15:13
  • @DeltaG "I2C mode is enabled if the CS pin is tied high to VDD I/O" seems pretty clear. Just strap CS to 3V3. Any other problems you are having are down to your reading software.
    – joan
    Commented Jan 14, 2016 at 19:04

Joan's strapping CS to 3V3 did work; the documentation (for the SF breakout board) doesn't indicate it, but it is the answer.

Once I had that, the issue was a coding one: accel.getAxes(False) needs to be called each time a measurement is made, so I was reporting the initial acceleration measurement over and over, unintentionally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.