BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Tue Oct 23, 2018 1:35 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Devantech SRF04 Ultrasonic Range Finder
PostPosted: Wed Apr 10, 2013 7:58 pm 
Offline
New User

Joined: Wed Apr 10, 2013 5:06 pm
Posts: 2
I met a problem when I was interfacing SRF04 to basic atom pro40.
I wanted to show the result of centimeter on lcd display, but it always returned 0.
I tried both PULSIN and RCTIME, they didn't work.
This is my code, can anybody help me?
Code:
' range finder lcd display
lcd con P3
ECHO_RAW var word
DIST_CM var word
CONV_CM con 6
ECHO con P4
TRIGGER con P5

'---------------
LOW TRIGGER
SEROUT lcd, i9600, [22,12] 'Clear lcd display
PAUSE 500
SEROUT lcd, i9600, [128,"centim:"]

main:
  gosub range_finder
  SEROUT lcd, i9600, [138,DEC DIST_CM]
  goto main
END

range_finder:
  PULSOUT TRIGGER, 1
  PULSIN ECHO,1,ECHO_RAW
  DIST_CM = (ECHO_RAW/CONV_CM ) 'Convert to centimeter
  PAUSE 1
  return


Top
 Profile  
 
 Post subject: Re: Devantech SRF04 Ultrasonic Range Finder
PostPosted: Thu Apr 11, 2013 2:53 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
It has been a long time since I played with one of these...

My quick look at docs, looks like the pulse width out should be a minimum of 10us , and the time units are in .5us so you might try increasing the value on the pulsout to 20 and see if that helps.

Also I have not used pulsin in a while, so don't remember if it properly set the IO pin to input... So I would probably add an INPUT ECHO to the startup code to see if that helps.

I would also play around with pauses, between attempts, maybe between the pulseout and pulsin...

Edit: did a search up on Lynxmotion forum and found several hits... Some code that I think a person got working is in the thread:
http://www.lynxmotion.net/viewtopic.php?f=4&t=5034


Good Luck

Kurt


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO