Yahoo Groups archive

AVR-Chat

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

Message

RE: [AVR-Chat] Sharp Distance sensor: GP2D02 and an AVR

2005-03-02 by wbounce

After looking at my reply and your stuff again 
I think shift in must be ADC analog to digital converter. On my Atmega
128 this would be done on port F. Sorry if I and not be of more help
because I have not done anything with that yet.
 

-----Original Message-----
From: wbounce [mailto:wbounce@safeplace.net] 
Sent: Tuesday, March 01, 2005 10:17 PM
To: AVR-Chat@yahoogroups.com
Subject: RE: [AVR-Chat] Sharp Distance sensor: GP2D02 and an AVR



Variable are declared like 
uint8_t val02,i;

Pins on AVR are like 
PINA1
My AVR has ports A through G

The For would look like
For(i=0;i < 100; i++)
	{
	}

I have no idea what 
  SHIFTIN dt, cl, MSBPOST, [val02]
does. 

-----Original Message-----
From: Honea [mailto:fredit@charter.net] 
Sent: Tuesday, March 01, 2005 7:26 PM
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] Sharp Distance sensor: GP2D02 and an AVR



I am trying to convert some bs2 code for my distance sensor to work in C
for 
my AVR.

Here is the sensor and bs2 code.
http://www.acroname.com/robotics/info/examples/GP2D02-4/GP2D02-4.html

'--------------------------------------------------------
' variable declarations

val02 var byte ' value where reading is stored
i var byte ' count variable for loop


'--------------------------------------------------------
' constant declarations

cl con 14 ' pin 14 is output (clock)
dt con 15 ' pin 15 is the input (data)


'--------------------------------------------------------
' I/O pin setup for detector

INPUT dt ' make pin 15 the input
HIGH cl ' make pin 14 output and high


'--------------------------------------------------------
' main loop

DEBUG "Start", CR ' indicate beginning

FOR i = 1 TO 100 ' take and display 100 readings
  GOSUB read02 ' call measurement routine
  DEBUG dec val02, CR ' display the value
  PAUSE 100 ' stall so display readable
NEXT

DEBUG "Finish" ' indicate end

END ' stop Stamp when done


'--------------------------------------------------------
' subroutine read02
'
' This subroutine takes a reading from the connected
' GP2D02 detector and stores the value in "val02".
' Any two pins can be used.  Set "dt" to the data line
' of the GP2D02 (pin 4 on JST connector, yellow wire).
' Set cl to the clock line of the GP2D02 (pin 2 on the
' JST connector, green wire).

read02:
  LOW cl ' turn on detector for reading
  rl:
  IF IN15 = 0 THEN rl ' wait for input high
  SHIFTIN dt, cl, MSBPOST, [val02]
  HIGH cl ' turn detector off
  PAUSE 1 ' let detector reset
RETURN


-------------------------------------------------------------

Basically, I just need to know the gnu equal of this command: "  SHIFTIN
dt, 
cl, MSBPOST, [val02]"


Or if anyone has working code for this sensor, that would be great too
:)


thanks!
Lee





 
Yahoo! Groups Links



 






 
Yahoo! Groups Links

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.