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

Here is some of my com code (Adapted from Brian Dean's sample code
#include <stdio.h>
#include <avr/pgmspace.h>
#include <avr/signal.h>
#include <avr/interrupt.h>

FILE * def_uart;
 
void uart_putc(uint8_t uart, char c)
{
// output a carriage return for every newline because 
//I am viewing this through windows
 
  if (c == '\n') {
    /* first output a carriage return */
    uart_putc(uart, '\r');
  }
  if (uart == 0) {
    while ((UCSR0A & BV(UDRE)) == 0)
      ;
    UDR0 = c;
  }
  else if (uart == 1) {
    while ((UCSR1A & BV(UDRE)) == 0)
      ;
    UDR1 = c;
  }
}

int def_putc(char ch)
{
  uart_putc(DEF_UART, ch);
  return ch;
}

 
SIGNAL(SIG_UART0_RECV)
{
  uint8_t c; 
 
  c = inp(UDR0);
  if (bit_is_clear(UCSR0A, FE)) {
    ringbuf_put(&uartbuf, c); // <-- this puts the charactor in a buffer
for later processing.
    GotText = 1;
  }
}

 
int setbaud(void)  
{ 
 
 /* initialize UART input ring buffer */
 ringbuf_init(&uartbuf, uart_buffer, sizeof(uart_buffer));
 
  
 /* enable UART0  9600 baud for 16Mhz clock see data sheet table*/ 
 UBRR0H = 0;
 UBRR0L = 103; 
 
 // enable transmit and receive and receive interrupt
 UCSR0B = BV(RXEN)|BV(TXEN)|BV(RXCIE);
 
 /* enable UART1   9600 baud for 16Mhz clock see data sheet table*/ 
 UBRR1H = 0;
 UBRR1L = 103;
 
 // enable transmit and receive and receive interrupt
 UCSR1B = BV(RXEN)|BV(TXEN)|BV(RXCIE);
 
 /* initialize stdin, stdout, stderr */
 stdin    = fdevopen(def_putc, NULL, 0);
 
 stdout   = stdin;
 stderr   = stdin;
 def_uart = stdin;
 
return 0;
} 
 
 
the to send stuff
printf("TL %i\n\r",TargetLeftPWM);
 
 
-----Original Message-----
From: Honea [mailto:fredit@charter.net] 
Sent: Wednesday, March 02, 2005 1:14 AM
To: AVR-Chat@yahoogroups.com
Subject: Re: [AVR-Chat] Sharp Distance sensor: GP2D02 and an AVR


In my acroname manual for the  gp2d02 it says "the interface between the
microprocessor and the detector is a serial interface".
 
There is an analog version of this sensor.. but I don't have it :)
 
So, I guess I just need to know how to do serial comm with out using an
uart (?)
 
thanks
Lee
 
 
 

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

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











Yahoo! Groups Sponsor	

ADVERTISEMENT
 
<http://us.ard.yahoo.com/SIG=129cp5j47/M=298184.6018725.7038619.3001176/
D=groups/S=1706554205:HM/EXP=1109830447/A=2593423/R=0/SIG=11el9gslf/*htt
p://www.netflix.com/Default?mqso=60190075> click here	
 
<http://us.adserver.yahoo.com/l?M=298184.6018725.7038619.3001176/D=group
s/S=:HM/A=2593423/rand=503221904> 	


  _____  

Yahoo! Groups Links


*	To visit your group on the web, go to:
http://groups.yahoo.com/group/AVR-Chat/
  

*	To unsubscribe from this group, send an email to:
AVR-Chat-unsubscribe@yahoogroups.com
<mailto:AVR-Chat-unsubscribe@yahoogroups.com?subject=Unsubscribe> 
  

*	Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> .

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.