Author Topic: GP2Y0A02 sharp IR readings needed  (Read 2952 times)

0 Members and 1 Guest are viewing this topic.

Offline benjiTopic starter

  • Supreme Robot
  • *****
  • Posts: 832
  • Helpful? 0
GP2Y0A02 sharp IR readings needed
« on: April 03, 2008, 02:30:45 AM »
hello folks, i had this sharp ir sensor and im working now on interfacing it to my atmega.
the approach i want to do is to make a lookup table of voltages-destances
it goes this way

20 cm - 2.4 v
22 cm - 2.35v
24 cm - 2.23 v
.
.
.
.
150 cm - ????v


has anyone done such a thing before? if yes i would be glad to have all this readings cuz im having lots of problems finding them
(making perfect conditions for the sensor)

if there is any other approach wich is easier to make with the same preciesion i would be glad to hear about it

thanks ,,,,,
good ol' BeNNy

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: GP2Y0A02 sharp IR readings needed
« Reply #1 on: April 03, 2008, 08:35:39 AM »
hey man i recently got this sharp Gp2D12 and i found out my digital  readings using USART , i drew the graph using  excel, found out the best straight trend line and also the equation, so i now have an equation which can give nearby values of digital readings for different angles , why dont u try that technic , this is how my graph loooks like

I dont know if the graph is kind of same for ur sharp ir as the distance measurement capacities are different..
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline benjiTopic starter

  • Supreme Robot
  • *****
  • Posts: 832
  • Helpful? 0
Re: GP2Y0A02 sharp IR readings needed
« Reply #2 on: April 03, 2008, 09:42:41 AM »
thanks for the picture
i guess the output voltage is not the same with my sensor,anyways why would i use uart?
just power the ir and read out by voltmeter ,,,,isnt this easier?

the question is how did you find the equation?based on how many readings?

thanks
good ol' BeNNy

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: GP2Y0A02 sharp IR readings needed
« Reply #3 on: April 03, 2008, 10:40:37 AM »
well if u use uart then u get exact digital readings now using the multimeter means u get the voltage o/p which may not be as realiable and exact as usart , coz in usart i take 2 different readings at a distance and i take 10 distances alltogether so i get a graph which can tell me exactly how much my readings can vary for different distances

and abt the equation , its a facility available in ms excel which derives a nearby equation for the trendline i have set for the graph,although it is not 100% exact but still i can get 70-80 % accuracy with it which is sufficient for my purpose.
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline benjiTopic starter

  • Supreme Robot
  • *****
  • Posts: 832
  • Helpful? 0
Re: GP2Y0A02 sharp IR readings needed
« Reply #4 on: April 03, 2008, 03:27:15 PM »
mmm i kind of seen a function in matlab that does the same thing, ill try using it.

anyways , how do you watch the values on the computer? hyper terminal?
good ol' BeNNy

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: GP2Y0A02 sharp IR readings needed
« Reply #5 on: April 04, 2008, 12:54:52 AM »
well i use uart for that , i have written this code for atmega16 where the sensor input is in pin1 of porta

use the internal 8mhz oscillator and use this code , connect the serial port to the hyper terminal by using maz232 ic and ull get the readings..

Code: [Select]
# include<stdio.h>
# include<avr/io.h>

# include<util/delay.h>
# include<avr/interrupt.h>
# include<stdlib.h>
# include<string.h>
# include<avr/pgmspace.h>



#define USART_BAUDRATE 38400
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL)))- 1)


 char u[11]="adcvalue\r\n";
 char *d;
 char b[10];
 char *p;
 
 unsigned int a;

void adcinitialize();
void uartinitialize();
void adcgetvalue();
void transferusart();
void printvalue(char *);

 int main(void)
  {
   adcinitialize();
   uartinitialize();
   while(1)
    {
adcgetvalue();

     
p=itoa(a,b,10);

strcat_P(b,PSTR("\r\n"));

d=&u[0];

transferusart();

     
     }       
   

   return(0);
   }
 
 
 
 void adcinitialize()
  {
   
  ADCSRA|=_BV(7)|_BV(ADPS2)|_BV(ADPS1);
  ADMUX=0x60;
  ADCSRA|=(1<<ADSC);
  while(!(ADCSRA & (1<<ADIF)));
  ADCSRA|=(1<<ADIF);
  TCCR1B|=(1<<CS12);
 
  }
 
  void uartinitialize()
   {
    UCSRB= (1<<RXEN) | (1<<TXEN);
    UCSRC= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
    UBRRL=BAUD_PRESCALE;
UBRRH=(BAUD_PRESCALE>>8);
   }
void adcgetvalue()
 {
 
   ADMUX=0x61;
   ADCSRA|=(1<<ADSC);
  while(!(ADCSRA & (1<<ADIF)));
  ADCSRA|=(1<<ADIF);
  a=ADCH;
 }
 
void transferusart()
 {
   
   while (*d != '\0')
    {

     while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it
      UDR =*d ; // Echo back the received byte back to the computer
      d++;
}
TCNT1=0;
while(TCNT1<=60000){};
TCNT1=0;
 printvalue(p);
 }
 
 void printvalue(char *l)
  {
   
   while (*l != 0x00)
    {
 

  while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it
      UDR =*l ; // Echo back the received byte back to the computer
     
     
     l++;
    }
TCNT1=0;
while(TCNT1<=60000){};
TCNT1=0;
  }
 

   
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
Re: GP2Y0A02 sharp IR readings needed
« Reply #6 on: April 04, 2008, 01:09:11 AM »
i thought this is supposed to be high level programming much easier to understand and work with by us humans than machine code or even assembley
Check out the uBotino robot controller!

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: GP2Y0A02 sharp IR readings needed
« Reply #7 on: April 04, 2008, 01:24:40 AM »
if this seems complicated , then imagine what assembly or machine lvl language code will look like
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline benjiTopic starter

  • Supreme Robot
  • *****
  • Posts: 832
  • Helpful? 0
Re: GP2Y0A02 sharp IR readings needed
« Reply #8 on: April 04, 2008, 03:41:51 AM »
thanks man ill give it a shot
good ol' BeNNy

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: GP2Y0A02 sharp IR readings needed
« Reply #9 on: April 04, 2008, 03:44:08 AM »
trust me the code will work also change ur fuse settings  to

hfuse 0xd9

lfuse 0xd4
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

 


Get Your Ad Here