2

I am trying to use MPU 6050 on raspberry pi. For that I enabled i2c on raspi. But after that whenever I am trying to check the modules on my Python 3 or 2 shell for e.g. when I run help('modules'), I get the following error. The program just runs fine, but I don't understand why I get these errors. Does it have any implication in the future if I connect any other sensor?

Automation pHAT detected...
Exception in thread Thread-1:


Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner


 self.run()
  File "/usr/lib/python3/dist-packages/automationhat/pins.py", line 37, in run


 if self.todo() is False:
  File "/usr/lib/python3/dist-packages/automationhat/__init__.py", line 293, in _update_adc
    analog._update()


File "/usr/lib/python3/dist-packages/automationhat/pins.py", line 92, in handler
    return self._do(name, *args, **kwargs)

File "/usr/lib/python3/dist-packages/automationhat/pins.py", line 111, in _do
    _results[node] = handler(*args, **kwargs)

File "/usr/lib/python3/dist-packages/automationhat/__init__.py", line 122, in _update
    self.value = ads1015.read(self.channel)

File "/usr/lib/python3/dist-packages/automationhat/ads1015.py", line 42, in read
    self.i2c_bus.write_i2c_block_data(self.addr, 
REG_CFG, [(config >> 8) & 0xFF, config & 0xFF])
OSError: 
[Errno 121] Remote I/O error

Warning, could not find Analog or Touch...
Please check your i2c settings!

I have taken this code from a website (http://maker.robotistan.com/raspberry-pi-dersleri-16-mpu6050-ivmeolcerjiroskop-kullanimi/)

import smbus
import math
import time

# Guc yonetim register'lari
power_mgmt_1 = 0x6b
power_mgmt_2 = 0x6c

def read_byte(adr):
 return bus.read_byte_data(address, adr)

def read_word(adr):
 high = bus.read_byte_data(address, adr)
 low = bus.read_byte_data(address, adr+1)
 val = (high << 8) + low
 return val

def read_word_2c(adr):
 val = read_word(adr)
 if (val >= 0x8000):
 return -((65535 - val) + 1)
 else:
 return val

def dist(a,b):
 return math.sqrt((a*a)+(b*b))

def get_y_rotation(x,y,z):
 radians = math.atan2(x, dist(y,z))
 return -math.degrees(radians)

def get_x_rotation(x,y,z):
 radians = math.atan2(y, dist(x,z))
 return math.degrees(radians)


bus = smbus.SMBus(1)
address = 0x68 #MPU6050 I2C adresi

#MPU6050 ilk calistiginda uyku modunda oldugundan, calistirmak icin asagidaki komutu veriyoruz:
bus.write_byte_data(address, power_mgmt_1, 0)

while True:
 time.sleep(0.1)
 #Jiroskop register'larini oku
 gyro_xout = read_word_2c(0x43)
 gyro_yout = read_word_2c(0x45)
 gyro_zout = read_word_2c(0x47)

 print "Jiroskop X : ", gyro_xout, " olcekli: ", (gyro_xout / 131)
 print "Jiroskop Y : ", gyro_yout, " olcekli: ", (gyro_yout / 131)
 print "Jiroskop Z: ", gyro_zout, " olcekli: ", (gyro_zout / 131)

 #Ivmeolcer register'larini oku
 accel_xout = read_word_2c(0x3b)
 accel_yout = read_word_2c(0x3d)
 accel_zout = read_word_2c(0x3f)

 accel_xout_scaled = accel_xout / 16384.0
 accel_yout_scaled = accel_yout / 16384.0
 accel_zout_scaled = accel_zout / 16384.0

 print "Ivmeolcer X: ", accel_xout, " olcekli: ", accel_xout_scaled
 print "Ivmeolcer Y: ", accel_yout, " olcekli: ", accel_yout_scaled
 print "Ivmeolcer Z: ", accel_zout, " olcekli: ", accel_zout_scaled

 print "X dondurme: " , get_x_rotation(accel_xout_scaled, accel_yout_scaled, accel_zout_scaled)
 print "Y dondurme: " , get_y_rotation(accel_xout_scaled, accel_yout_scaled, accel_zout_scaled)

 time.sleep(0.5)
  • could you share the code you are using? – linuxgnuru Dec 26 '17 at 18:15
  • Hi. Yes I can share the code. But just for your info, I get this error irrespective of whether the sensor is attached or not or whether I am running any script or not. The sensor runs perfectly when I run the code. But I get these errors when I run help('modules'). I don't know if this has any consequences on my future projects because I will be using the Pi on a project soon that is going to run for 2 months 24x7. – Nischal Dec 27 '17 at 8:47
  • What does sudo i2cdetect -y1 show? – linuxgnuru Dec 27 '17 at 9:26
  • It shows me a matrix and I guess 2 values in the matrix 68 and 77 I guess. Should there just be one value instead of 2? – Nischal Dec 27 '17 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.