Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Re: GP2D02 + ATmega32

2006-09-10 by James Ronald

Here's another link.  The sample code is in basic and easy to follow.  You should be able to get a good idea of how GP2D02 works.  

http://www.acroname.com/robotics/info/ideas/avrexamp/avrexamp.html#s1
  ----- Original Message ----- 
  From: katraven1 
  To: AVR-Chat@yahoogroups.com 
  Sent: Sunday, September 10, 2006 12:40 PM
  Subject: [AVR-Chat] Re: GP2D02 + ATmega32


  Ok, since the reply to this post showed that obviously some 
  knowledge was lacking in this area I have gone away and redone my 
  coding and interfacing to the GP2D02.

  I've gotten the input correct now (I mistook the pulsing of the 
  input line to be a PWM.. silly me..) and have witnessed the IR flash 
  (via camera).

  It is the output from the sensor which is of concern now... for some 
  reason the output is forever high.. for example, when i want to take 
  a reading i make my input line low, to which the sensor responds by 
  making the output low during the reading, and then high, to which my 
  code response by starting the pulses to read each bit in.

  Yet for some reason the output bit is always high... my 'output' 
  variable is always "255" DEC regardless of the distance the sensor 
  is to a surface..

  am I still missing the mark here? =(

  --- In AVR-Chat@yahoogroups.com, "Larry Barello" <yahoo@...> wrote:
  >
  > Don't use PWM output to drive the unit.  Have you seen
  > http://www.barello.net/Papers/GP2D02?  
  > 
  > The assembly code is complex since it multiplexes three sensors 
  but at it's
  > core it is simple, it does the clocking and shifting of data in 
  s/w which is
  > more than fast enough and easy to control.  I paraphrase below, 
  for one
  > sensor (I used 9 for the loop to discard the first bit, you could 
  re-arrange
  > and make it 8 loops):
  > 
  > Set control port pin low
  > wait for input pin to go high (or a max of 30ms IIRC)
  > for (i = 0; i< 9; i++)
  > {
  > if input high
  > output |= 1; // Set low bit
  > output << 1; // Left shift
  > set control pin low // Clock in next bit
  > wait 1 us
  > set control pin high
  > wait 16 us
  > }
  > set control pin high.
  > 
  > At the end of the routine your data should be in "output" and the 
  sensor
  > should be in a low-power state ready for another reading.  Please 
  make sure
  > the code you write follows the clock diagram in the data sheet. I 
  just
  > paraphrased assembly code I wrote over 7 years ago and might have 
  made a
  > mistake or two...
  > 
  > -----------
  > Larry Barello
  > www.barello.net
  > 
  > 
  > | -----Original Message-----
  > | From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] 
  On Behalf
  > | Of katraven1
  > | Sent: Thursday, August 31, 2006 8:54 AM
  > | To: AVR-Chat@yahoogroups.com
  > | Subject: [QUARANTINE] [AVR-Chat] GP2D02 + ATmega32
  > | Importance: Low
  > | 
  > | Hey guys, me again =P
  > | 
  > | I've been spending the last couple of days trying to get one ex-
  Sharp
  > | infrared sensor to communicate wif my ATmega32. It's jst 
  connected to
  > | the OC0 pin on PORTB generating a pwm to read a signal and the 
  output
  > | of the sensor to one of the other IO pins, similar as used on the
  > | Dilberts (thx Larry!)
  > | 
  > | However, as the output of the sensor is in serial, I can't quite 
  get
  > | the timing right to read it properly...
  > | 
  > | I've read the previous post which converts code for the BSII to C
  > | (http://groups.yahoo.com/group/AVR-Chat/message/7190) but I'm not
  > | quite sure how to build on top of that...
  > | 
  > | *boggled yet again....


[Non-text portions of this message have been removed]

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.