Go to Post it's flattering, but a little scary, because I don't know if I'm ready to be an inspiration! - MissInformation [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 06-02-2016, 15:34
TrentMcBignerd TrentMcBignerd is offline
Registered User
FRC #1982
 
Join Date: Feb 2016
Location: Lenexa
Posts: 1
TrentMcBignerd is an unknown quantity at this point
I2C Color Sensor not working

My team recently purchased a Modern Robotics Color Sensor, so we are trying to test it out before implementing it on our robot. However whenever we try to use the read method on the color sensor, it return true, meaning the transfer was aborted. However we tried communicating with it and we can, because we are able to turn on and off the led on the sensor. Can someone please explain?
The problem is at line 150.
https://github.com/CougarRobotics198...new/Robot.java
Reply With Quote
  #2   Spotlight this post!  
Unread 09-02-2016, 14:59
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 103
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: I2C Color Sensor not working

Are you using the color sensor found at: http://www.modernroboticsinc.com/color-sensor

If so, it looks like product page indicates that the address of the sensor is 0x3C. Could it be that you just need to change:

Code:
ColorSensor = new I2C(I2C.Port.kOnboard, 0x1E);
To:

Code:
ColorSensor = new I2C(I2C.Port.kOnboard, 0x3C);
Reply With Quote
  #3   Spotlight this post!  
Unread 09-02-2016, 15:31
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: I2C Color Sensor not working

Quote:
Originally Posted by pblankenbaker View Post
Are you using the color sensor found at: http://www.modernroboticsinc.com/color-sensor

If so, it looks like product page indicates that the address of the sensor is 0x3C. Could it be that you just need to change:

Code:
ColorSensor = new I2C(I2C.Port.kOnboard, 0x1E);
To:

Code:
ColorSensor = new I2C(I2C.Port.kOnboard, 0x3C);
I am not familiar with the I2C class in WPILib but it depends on whether the regAddress parameter in the I2C constructor is expecting a 7-bit address or 8-bit address. If it is 8-bit, then 0x3C is the correct address. But if it is expecting a 7-bit address, then it should be 0x1E. In the I2C spec, register address is actually 7 bits, the LSB of the 8-bit address is used to indicate whether it is a READ or WRITE transaction. So a 7-bit address must shift left one-bit to accommodate the READ/WRITE bit. The Modern Robotics Color Sensor spec specifies an 8-bit address. So it's already shifted one bit to the left. But if the WPILib I2C constructor is expecting a 7-bit address (i.e. it will internally shift one bit to the left and OR-in the READ/WRITE bit), then passing 0x1E to it is correct.
I recommend you try both and see which way it is.
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 09-02-2016, 15:38
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,567
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: I2C Color Sensor not working

Quote:
Originally Posted by mikets View Post
I am not familiar with the I2C class in WPILib but it depends on whether the regAddress parameter in the I2C constructor is expecting a 7-bit address or 8-bit address. If it is 8-bit, then 0x3C is the correct address. But if it is expecting a 7-bit address, then it should be 0x1E. In the I2C spec, register address is actually 7 bits, the LSB of the 8-bit address is used to indicate whether it is a READ or WRITE transaction. So a 7-bit address must shift left one-bit to accommodate the READ/WRITE bit. The Modern Robotics Color Sensor spec specifies an 8-bit address. So it's already shifted one bit to the left. But if the WPILib I2C constructor is expecting a 7-bit address (i.e. it will internally shift one bit to the left and OR-in the READ/WRITE bit), then passing 0x1E to it is correct.
I recommend you try both and see which way it is.
The cRIO expects 8 bit, the roboRIO expects 7 bit.
Reply With Quote
  #5   Spotlight this post!  
Unread 09-02-2016, 21:17
bkeeney bkeeney is offline
Registered User
FRC #1982
 
Join Date: Feb 2016
Location: Lenexa, KS
Posts: 3
bkeeney is an unknown quantity at this point
Re: I2C Color Sensor not working

So what we've experienced is that our addressing appears to be correct. We are able to turn the LED on and off.

What's not working is the I2C read. Code below:

byteAr = new byte[1];
boolean success = !ColorSensor.read(0x04, 1, byteAr);

The read is always returning true, which means the read has failed. If we ignore that and try to use the value in byteAr we get an index out of bounds exception.

Not sure where to go from here since it does not appear to be address related.

FWIW, we were able to connect the sensor to a Raspberry Pi and read from the various address locations. RoboRio no success.

Any ideas?
Reply With Quote
  #6   Spotlight this post!  
Unread 11-02-2016, 19:40
bkeeney bkeeney is offline
Registered User
FRC #1982
 
Join Date: Feb 2016
Location: Lenexa, KS
Posts: 3
bkeeney is an unknown quantity at this point
Re: I2C Color Sensor not working

bump? Anyone?
Reply With Quote
  #7   Spotlight this post!  
Unread 12-02-2016, 12:02
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 103
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: I2C Color Sensor not working

That is strange that the write operation would work while the read operation would not.

Is it possible that the voltage levels would make a difference? I'm not an electronics person, but I think I have noticed that some I2C devices are 3.3V and some are 5V and some will dynamically adjust.

The roboRIO is labeled for 3.3V on the I2C power and from the website (http://www.modernroboticsinc.com/color-sensor) it looks like the sensor is expecting 5V on the power line (the website doesn't say that it won't work on 3.3V, but I didn't see anything saying that it would either).

Does the Raspberry PI that the sensor worked on have a 3.3V I2C bus like the roboRIO or a 5V I2C bus?

Not sure how this might impact things or if it could explain why you can send data to the sensor but not get anything back, but maybe it is something to consider or to ask the manufacturer of the sensor.

I have seen ads for items designed to convert between 3.3V and 5V I2C lines (https://www.adafruit.com/products/757). Have never tried using one though.

Good Luck.
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 22:36.

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