Skip to content

I/O Error on this python code in raspberry pi 2  #1

Description

@rohitpatil597

hi sir,
thanks for sharing this code.I have some doughts about this code.I run this same code in RPi board.after installing smbus and enabling I2C model.but it's showing i/o error, so please help me for this error.
the error is
[
pi@raspberrypi:~/Desktop/Nexsys $ sudo python ADXL345.py
Traceback (most recent call last):
File "ADXL345.py", line 6, in
bus.write_byte_data(0x53, 0x2C, 0x0A)
IOError: [Errno 5] Input/output error
]
my code is:

import smbus
import time

bus = smbus.SMBus(1)

bus.write_byte_data(0x53, 0x2C, 0x0A)
bus.write_byte_data(0x53, 0x2D, 0x08)
bus.write_byte_data(0x53, 0x31, 0x08)

time.sleep(0.5)

data0 = bus.read_byte_data(0x53, 0x32)
data1 = bus.read_byte_data(0x53, 0x33)

xAccl = ((data1 & 0x03) * 256) + data0

if xAccl > 511 :
xAccl -= 1024
data0 = bus.read_byte_data(0x53, 0x34)
data1 = bus.read_byte_data(0x53, 0x35)
yAccl = ((data1 & 0x03) * 256) + data0
if yAccl > 511 :
yAccl -= 1024
data0 = bus.read_byte_data(0x53, 0x36)
data1 = bus.read_byte_data(0x53, 0x37)
zAccl = ((data1 & 0x03) * 256) + data0
if zAccl > 511 :
zAccl -= 1024

Output data to screen

print "Acceleration in X-Axis : %d" %xAccl
print "Acceleration in Y-Axis : %d" %yAccl
print "Acceleration in Z-Axis : %d" %zAccl

thanks,
rohitpatil597@gmail.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions