Go to Post The practical experience that students learn by working with the mentors on a real life problem -- with real life constraints -- helps produce people who are good at those professions. - MechEng83 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-04-2015, 03:53
2538Programming 2538Programming is offline
Registered User
FRC #2538
 
Join Date: Dec 2013
Location: Morris MN
Posts: 3
2538Programming is an unknown quantity at this point
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
Reply With Quote
  #2   Spotlight this post!  
Unread 01-04-2015, 04:16
Jefferson Jefferson is offline
Registered User
AKA: Jeff Clements
FRC #0016 (Bomb Squad)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Mountain Home, AR
Posts: 258
Jefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond repute
Re: I2C Rangefinders not working

Quote:
Originally Posted by 2538Programming View Post
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 01-04-2015, 07:59
Woodie Flowers Award
JDNovak JDNovak is offline
Mentor
AKA: John Novak
FRC #0016 (Bomb Squad)
Team Role: Engineer
 
Join Date: Jan 2005
Rookie Year: 1996
Location: Mountain Home, AR
Posts: 52
JDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond repute
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 01-04-2015, 10:53
2538Programming 2538Programming is offline
Registered User
FRC #2538
 
Join Date: Dec 2013
Location: Morris MN
Posts: 3
2538Programming is an unknown quantity at this point
Re: I2C Rangefinders not working

Quote:
Originally Posted by Jefferson View Post
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 View Post
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?
Reply With Quote
  #5   Spotlight this post!  
Unread 01-04-2015, 11:10
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,654
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: I2C Rangefinders not working

Quote:
Originally Posted by JDNovak View Post
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.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #6   Spotlight this post!  
Unread 02-04-2015, 10:56
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: I2C Rangefinders not working

Quote:
Originally Posted by JDNovak View Post
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.
Reply With Quote
  #7   Spotlight this post!  
Unread 06-04-2015, 01:27
Woodie Flowers Award
JDNovak JDNovak is offline
Mentor
AKA: John Novak
FRC #0016 (Bomb Squad)
Team Role: Engineer
 
Join Date: Jan 2005
Rookie Year: 1996
Location: Mountain Home, AR
Posts: 52
JDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond reputeJDNovak has a reputation beyond repute
Re: I2C Rangefinders not working

Quote:
Originally Posted by JDNovak View Post
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:33.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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