Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   I2C Rangefinders not working (http://www.chiefdelphi.com/forums/showthread.php?t=136283)

2538Programming 01-04-2015 03:53

I2C Rangefinders not working
 
We are using maxbotics mb1212 I2C rangefinders and we have tested our rangefinders on an arduino but for some reason, the same approach to reading off the sensors seems to fail. I think our issue may be that it can't find the sensors, which it should totally be able to do, or that it has trouble accessing the command on the sensors. The documentation for the rangefinders is right here http://www.maxbotix.com/documents/I2..._Datasheet.pdf
,as well our Rangefinder code:

Quote:

package org.usfirst.frc2538.RecycleRush2538.subsystems;
import edu.wpi.first.wpilibj.I2C;

public class RangeFinder {

private I2C newRangeFinder;
private byte[] buffer = new byte[2];
private static int count = 2;
private static long echoTime = 0;
private int rangeCM;

// diagnostic
public boolean successfulWrite;
public boolean successfulRead;

// register addresses, must be in hexadecimle
private static int writeRegisterAddress = 0xE0; //224
private static int readRegisterAddress = 0xE1; //225

// write commands
private static int writeData = 81;
private static int writeDataHex = 0x51;

public RangeFinder(int hexAddress) {
newRangeFinder = new I2C(I2C.Port.kOnboard, hexAddress);
}

public void startSensor() {
successfulWrite = !newRangeFinder.write(writeRegisterAddress, writeDataHex);
echoTime = System.currentTimeMillis() + 100;
}

public int getRangeCM() {
if (System.currentTimeMillis() >= echoTime) {
successfulRead = !newRangeFinder.read(readRegisterAddress, count, buffer);
successfulWrite = !newRangeFinder.write(writeRegisterAddress, writeDataHex);
rangeCM = buffer[0] * 256 + buffer[1];
echoTime = System.currentTimeMillis() + 100;
}
return rangeCM;
}


}
Any help we can get is much appreciated, thanks

Jefferson 01-04-2015 04:16

Re: I2C Rangefinders not working
 
Quote:

Originally Posted by 2538Programming (Post 1464726)
We are using maxbotics mb1212 I2C rangefinders and we have tested our rangefinders on an arduino but for some reason, the same approach to reading off the sensors seems to fail. I think our issue may be that it can't find the sensors, which it should totally be able to do, or that it has trouble accessing the command on the sensors. The documentation for the rangefinders is right here http://www.maxbotix.com/documents/I2..._Datasheet.pdf
,as well our Rangefinder code:



Any help we can get is much appreciated, thanks

Do you have pull down resistors on the data and clock wires? I believe the arduinos have them built into the board while the roborio needs them added to the bus.
We are using a similar sensor. I'd be happy to send you our C++ library for it.
Also, be careful if you are usng more than one. They can interfere with each other if the readings are sequenced properly.

JDNovak 01-04-2015 07:59

Re: I2C Rangefinders not working
 
For the RoboRio, the I2C library changed to 7 bit addressing so the range is 1 to 128 instead of 2 to 254. The default address is 112 to the RoboRio.

The Arduino library uses 8 bit addressing.

I don't think this is officially documented anywhere.

For example I used the Arduino example code to set the address to 4 and then accessed the sensor on address 2 from the RoboRio.

The clock and data do need external 120 ohm pullups also.

2538Programming 01-04-2015 10:53

Re: I2C Rangefinders not working
 
Quote:

Originally Posted by Jefferson (Post 1464727)
Do you have pull down resistors on the data and clock wires? I believe the arduinos have them built into the board while the roborio needs them added to the bus.
We are using a similar sensor. I'd be happy to send you our C++ library for it.
Also, be careful if you are usng more than one. They can interfere with each other if the readings are sequenced properly.

We have resisters going from 3.5/5 V to SCL and SDA. We are using three of the rangefinders but I am pretty sure they are wired correctly as we were able to get all three values from the Arduino. If you are willing to send me your library, I would love to check it out, thanks!

Quote:

Originally Posted by JDNovak (Post 1464741)
For the RoboRio, the I2C library changed to 7 bit addressing so the range is 1 to 128 instead of 2 to 254. The default address is 112 to the RoboRio.

The Arduino library uses 8 bit addressing.

I don't think this is officially documented anywhere.

For example I used the Arduino example code to set the address to 4 and then accessed the sensor on address 2 from the RoboRio.

The clock and data do need external 120 ohm pullups also.

This might be the issue, our sensors are addressed at 200, 202, and 204. I will try changing those and get back to you guys. Thanks for responding, I would have never been able to figure that out, why on earth would they do that?

GeeTwo 01-04-2015 11:10

Re: I2C Rangefinders not working
 
Quote:

Originally Posted by JDNovak (Post 1464741)
The clock and data do need external 120 ohm pullups also.

According to page 15 of the RoboRIO user manual,

Quote:

DIO <15..14> on the MXP and the two lines on the I2C port all have 2.2 kΩ pullup resistors to 3.3 V, as shown in Figure 17.

jhersh 02-04-2015 10:56

Re: I2C Rangefinders not working
 
Quote:

Originally Posted by JDNovak (Post 1464741)
The clock and data do need external 120 ohm pullups also.

Perhaps you are mixing up this value with CAN termination resistors? That's a very strong pull for I2C. Also, not needed on roboRIO for I2C.

JDNovak 06-04-2015 01:27

Re: I2C Rangefinders not working
 
Quote:

Originally Posted by JDNovak (Post 1464741)
The clock and data do need external 120 ohm pullups also.

The Arduino I2C library doesn't enable internal pullups so I had to install them to test and set the addresses. I think they are 1.2K instead of 120 ohm. My mistake.

I left them installed on the network when I moved to the roboRIO and they worked with both the main and MXP I2C ports. I had a scope on them at some point and the roboRIO drove the lines low enough.

Somehow I missed the users manual so thanks for the link.


All times are GMT -5. The time now is 10:50.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi