|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
I2C Error on read() or write()
I'm trying to use the ITG3200 gyro on the AndyMark breakout board (am-2314). I translated some code I found from Java to Python, which you can find on PasteBin below, along with the original.
I'm getting the below error when both using my custom ITG3200 class and the ADXL345_I2C class. Code:
Traceback (most recent call last):
File "/home/lvuser/py/robot.py", line 268, in <module>
wpilib.run(MyRobot)
File "/usr/local/lib/python3.5/site-packages/wpilib/_impl/main.py", line 101, in run
retval = options.cmdobj.run(options, robot_class, **kwargs)
File "/usr/local/lib/python3.5/site-packages/hal/main.py", line 11, in run
return robot_class.main(robot_class)
File "/usr/local/lib/python3.5/site-packages/wpilib/robotbase.py", line 178, in main
robot.startCompetition()
File "/usr/local/lib/python3.5/site-packages/wpilib/iterativerobot.py", line 78, in startCompetition
self.robotInit()
File "/home/lvuser/py/robot.py", line 252, in robotInit
self.subsystems['drive'] = DriveSubsystem()
File "/home/lvuser/py/robot.py", line 39, in __init__
self.gyro.init()
File "/home/lvuser/py/ITG3200.py", line 142, in init
if not self.testConnection():
File "/home/lvuser/py/ITG3200.py", line 236, in testConnection
return self.getDeviceID() == 0b110100
File "/home/lvuser/py/ITG3200.py", line 246, in getDeviceID
return self.getRegisterBits(RA_WHO_AM_I, DEVID_BIT, DEVID_LENGTH)
File "/home/lvuser/py/ITG3200.py", line 268, in getRegisterBits
containingByte = self.getRegisterByte(register)
File "/home/lvuser/py/ITG3200.py", line 265, in getRegisterByte
return self.readI2C(register, 1)[0]
File "/home/lvuser/py/ITG3200.py", line 83, in readI2C
return self.i2c.read(register, count)
File "/usr/local/lib/python3.5/site-packages/wpilib/i2c.py", line 145, in read
return self.transaction([registerAddress], count)
File "/usr/local/lib/python3.5/site-packages/wpilib/i2c.py", line 84, in transaction
dataToSend, receiveSize)
File "/usr/local/lib/python3.5/site-packages/hal/functions.py", line 407, in i2CTransaction
raise IOError(_os.strerror(C.get_errno()))
OSError: Success
My translated code: http://pastebin.com/CKr5prZs Original: https://github.com/bussell/SparkFun6...roITG3200.java RobotPy is 2016.2.0 on robot and driver station. Is this a bug in robotpy or am I messing up somewhere? Thanks for the help. |
|
#2
|
||||
|
||||
|
Re: I2C Error on read() or write()
Quote:
What value are you passing in for 'port' to the I2C constructor? I ask because I see that in HAL it checks to see if port < 0, and returns -1 if so -- which wouldn't set errno (and perhaps why you're seeing the 'success' message). I'll add a check for that so it can't happen in the future... This error also reminds me of this bug that someone reported for WPILib. |
|
#3
|
||||
|
||||
|
Re: I2C Error on read() or write()
Also, once this works, it'd make for a nice pull request to robotpy-wpilib-utilities. Just saying.
![]() |
|
#4
|
||||
|
||||
|
Re: I2C Error on read() or write()
Another thought. The java I2C function does not throw if there's an error, it just returns true. Can you add some error checking to the java code (maybe throw an exception if it returns false from i2c.read?), rerun it, and see if you get an error?
|
|
#5
|
||||
|
||||
|
Re: I2C Error on read() or write()
Thanks for the suggestions. The port is I2C.Port.kOnboard. I don't have access to the robot at the moment, but I'll test the Java code later.
|
|
#6
|
||||
|
||||
|
Re: I2C Error on read() or write()
Thanks for the help. Turns out that I had connected the board incorrectly, and that the data I was getting from Java was random noise, which I did not get in Python because I never ran initialize() in Java.
Again, thanks for the help. I got the gyro working. It still throws an error every once in a while (but good data otherwise), which the code catches and replaces with an array of zeroes. I'd like a better solution, and to get to the bottom of the I2C errors, but that is a project for later. I'll definitely add it to robotpy-wpilib-utilities once decoding and calibration is all figured out. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|