J'essaie d'interfacer mon accéléromètre ADXL3458 à mon Raspberry Pi 3 fonctionnant sous ubuntu mate. J'ai installer tout le paquet nécessaire pour la communication I2C. Quand j'effectue cette commande i2cdetect -y 1
j'obtiens ce résultat. I2C dans Raspbery Pi 3 en utilisant smbus
Maintenant, j'exécuter ce code Python
#!/usr/bin/env python
import smbus
import time
import math
from math import sin, cos, pi
bus = smbus.SMBus(1)
print bus
ACC_ADRESS = 0x53
acc_x = 0.0
acc_y = 0.0
acc_z = 0.0
def writeACC (register, value):
bus.write_byte_data(ACC_ADRESS, register, value)
return -1
def readACC_byte (addr):
return bus.read_byte_data(ACC_ADRESS, addr)
def readACC_word (addr):
LSB = bus.read_byte_data(ACC_ADRESS, addr)
MSB = bus.read_byte_data(ACC_ADRESS, addr + 1)
val = (MSB << 8) | LSB
return val
def setupACC():
# Sleep mode
writeACC(0x2D, 0)
# Mesurement mode
writeACC(0x2D, 8)
# enable Autu sleep mode
writeACC(0x2D, 16)
while True:
time.sleep(0.1)
acc_x = readACC_word(0x32)
acc_y = readACC_word(0x34)
acc_z = readACC_word(0x36)
print "Acc_x :\n", acc_x
print "Acc_y :\n", acc_y
print "Acc_z :\n", acc_z
time.sleep(0.5)
if __name__ == '__main__':
setupACC()
Et j'obtenir ce résultat dans l'oscilloscope
Ce déduisons que ma communication I2C est réussie. Mais dans le résultat que j'imprime ne montre aucune valeur dans
Peut s'il vous plaît aider avec le problème que je suis confronté. Est-ce quelque chose que je fais mal?
merci