GP2Y0A21YK With IOIO-OTG

56 views
Skip to first unread message

Marius Vosylius

unread,
May 6, 2014, 5:49:02 PM5/6/14
to ioio-...@googlegroups.com
Im looking for solution, how to get Distance in CM using this SHARP GP2Y0A21YK sensor. Anyone have this implemented with IOIO?

Al B

unread,
May 6, 2014, 6:52:57 PM5/6/14
to ioio-...@googlegroups.com
AnalogInput _ir;

@Override
protected void setup() throws ConnectionLostException, InterruptedException {
..
...
   _ir = ioio_.openAnalogInput(40);
....
..
}

@Override
public void loop() throws ConnectionLostException {
..
....
   float value = _ir.getVoltage();
....
..
}

Marius Vosylius

unread,
May 7, 2014, 2:47:01 AM5/7/14
to ioio-...@googlegroups.com

Thanks AI B, this only will get me a voltage, but how I can covert it to distance in cm?

--
You received this message because you are subscribed to a topic in the Google Groups "ioio-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ioio-users/o9KPxMtSyyU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Al B

unread,
May 7, 2014, 11:08:17 AM5/7/14
to ioio-...@googlegroups.com

In that case, then the datasheet is your best friend.




Al B

unread,
May 7, 2014, 11:11:21 AM5/7/14
to ioio-...@googlegroups.com
I meant this chart:


Marius Vosylius

unread,
May 7, 2014, 11:13:07 AM5/7/14
to ioio-...@googlegroups.com
Can you explain me how to use it, Im no actual Idea how programatically implement this chart. :(

Ytai Ben-Tsvi

unread,
May 7, 2014, 12:04:11 PM5/7/14
to ioio-...@googlegroups.com
Lookup table with linear interpolation?


--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.

Marius Vosylius

unread,
May 7, 2014, 12:32:17 PM5/7/14
to ioio-...@googlegroups.com
More detail explanation please.

Marius Vosylius

unread,
May 7, 2014, 2:00:40 PM5/7/14
to ioio-...@googlegroups.com
http://www.acroname.com/articles/linearizing-sharp-ranger.html

Thats what I found, how can I Implement this:

x = (float) ((2914 / (irRange.getVoltage() + 5)) - 1); 

Ytai Ben-Tsvi

unread,
May 7, 2014, 8:14:25 PM5/7/14
to ioio-...@googlegroups.com
Cool. I think the units are wrong though.
Their "V" does not seem to be voltage, but rather "input from a 10-bit ADC" which can mean a lot of things but probably (5 / 1023) volts. They also mention that the output is linear, but not in actually meaningful distance units, so you should (empirically?) find the scaling factor for converting to your unit of choice.

Al B

unread,
May 8, 2014, 2:54:30 AM5/8/14
to ioio-...@googlegroups.com
This series may be helpful too.  Although uses MathLab-Simulink and targets Arduino; it could be applicable to the IOIO as well.

using-infrared-proximity-sensors-with-simulink

Marius Vosylius

unread,
May 8, 2014, 2:57:23 AM5/8/14
to ioio-...@googlegroups.com
http://oomlout.com/PROX/PROX-Guide.pdf

In this pdf shows how to convert reading from Voltage to CM, hopefully this one will work now.

Al B

unread,
May 8, 2014, 8:21:22 PM5/8/14
to ioio-...@googlegroups.com
So which equation did you end using?

A/D Reading to centimeters?
distance = 12343.85 * (10bit reading)^-1.15

or Voltage Reading to Centimeters?
distance = 27.86 (voltage reading)^-1.15
Reply all
Reply to author
Forward
0 new messages