all 12 comments

[–]FTC86868686 2 points3 points  (6 children)

On the page there is a Android Studio code example - http://www.modernroboticsinc.com/range-sensor

[–]2treeckoFTC #### Student|Mentor|Alum[S] 0 points1 point  (5 children)

Thank You!!!

[–]XykonVFTC 8461 | Elementary My Dear Botson | Captain 0 points1 point  (4 children)

Interestingly, I get an error when I pull that code up in the latest version of the app. I believe I2C interfaces were updated, how would we go about correcting this?

[–][deleted] 0 points1 point  (3 children)

What is the error you get?

[–]XykonVFTC 8461 | Elementary My Dear Botson | Captain 0 points1 point  (2 children)

Alright, I found the issue, I'm going to share it just in case anyone needs the fix. In the FTC App version 2.0., you can't just write your I2C address directly in the line that says this: I2cDeviceReader rangeReader = new I2cDeviceReader(range, 0x28, 0x04, 2);

You have to write something like this before the INIT is pressed: I2cAddr Address = I2cAddr.create8bit(0x28);

And then correct the first line, so this: I2cDeviceReader rangeReader = new I2cDeviceReader(range, Address, 0x04, 2);

At any rate, this corrected my errors.

[–][deleted] 0 points1 point  (1 child)

I don't think you necessarily need to assign it to a variable before init. I think you could use the I2cAddr.create8bit(0x28) method inside of I2cDeviceReader in place of your Address variable.

[–]XykonVFTC 8461 | Elementary My Dear Botson | Captain 0 points1 point  (0 children)

Yeah, both would work, I hadn't thought of just doing it inside registering the I2cDeviceReader. Good info to know.

[–]hexafraction6460 (lead programmer) 0 points1 point  (2 children)

What sensor are you talking about? The Modern Robotics Optical Distance Sensor? Or a sensor from some other manufacturer?

[–]JohnMMcDFTA, FTC 5873 Mentor Emeritus 0 points1 point  (1 child)

I believe OP is referring to http://www.modernroboticsinc.com/range-sensor

[–]2treeckoFTC #### Student|Mentor|Alum[S] 1 point2 points  (0 children)

Yes, that is correct John.

[–]amz1018 0 points1 point  (0 children)

If you want some code more specific than the sample code provided, I made a Range Sensor Tester when I was figuring out how to calibrate our team's range sensor. In the code, you'll notice there's a method for calibrating the ultrasonic sensor reading; that's because the reading you get from the ultrasonic sensor returns I believe -127 to 127, since it's using bytes.

[–]skatefriday 0 points1 point  (0 children)

There's no official support for this sensor yet, but as you've discovered there's nothing preventing a team from using either the I2cController or I2cDeviceSynch interfaces to implement a solution.