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
0x53and the code doesn't crash, but the readings are all locked at some random valuewhen 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()