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

Hardware used:


2)Raspberry pi 2-https://www.raspberrypi.org/products/raspberry-pi-2-model-b/

  1. I2C shield for raspberry pi 2 and 3-https://store.ncd.io/product/i2c-shield-for-raspberry-pi-3-pi2-with-inward-facing-i2c-port/

Description:I am using ADXL345 and raspberry pi 2 .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)


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 to screen:

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

Possibility 1 is there is a connection problem or a dud device. You might validate that the device is actually working; one suggestion here : try “sudo i2cdetect -y 1”. 

Possibility 2 is the ADXL345 sample fails to take into account timing issues with RPi.  I suggest looking at this forum question and use the “try / except” solution.  (or here)

Oh yeah, apparently there may be a difference in the Rpi version, try SMBus(0) ?