简体   繁体   中英

I2C in Raspbery Pi 3 using smbus

I'm trying to interface my accelerometer ADXL3458 to my Raspberry Pi 3 running in ubuntu mate. I have install all the necessary package require for the I2C communication. When I perform this command i2cdetect -y 1 I get this results. 在此处输入图片说明

Now I run this Python code

#!/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()

And I get this result in the oscilloscope 在此处输入图片说明

This infer that my I2C communication is successful. But in the result that I'm printing shows no value in it 在此处输入图片说明

Can please help with problem that I'm facing. Is it anything that I'm doing wrong?

thank you

Auto sleep mode was should not active. Upon commenting #writeACC(0x2D, 16) is working fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM