1

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.

Wiring:

3.3V -> VCC
Gnd -> Gnd
SCL -> SCL
SDA -> SDA

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.

Code:

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
ser.readline()
ser.readline()
ser.readline()

GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)



for i in range(0,21):
    GPIO.output(23,True)
    time.sleep(.5)
    GPIO.output(23,False)
    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()
    time.sleep(.5)

GPIO.cleanup()
0

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.

4
  • 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
    Jan 14 '16 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
    Jan 14 '16 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
    Jan 14 '16 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
    Jan 14 '16 at 19:04
0

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, privacy policy and cookie policy

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