BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Mon Jul 16, 2018 1:56 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: need code for basicatom 28 + ping parallax
PostPosted: Fri Jan 20, 2006 7:00 am 
Has anyone ever done the interface before?
I couldn't get mine to work
I was translating parallax example code to basicatom but no luck
couldn't find the right number for the trigger and scale
Help please...


Top
  
 
 Post subject: Re: need code for basicatom 28 + ping parallax
PostPosted: Fri Jan 20, 2006 7:00 am 
Thx kjennejohn.

This is the code that I've been using: (Code are based on example given by parallax)

' -----[ I/O Definitions ]-------------------------------------------------
Ping CON P15

' -----[ Constants ]-------------------------------------------------------
Trigger CON 10
Scale CON $A00
RawToIn CON 889 ' 1 / 73.746 (with **)
RawToCm CON 2257 ' 1 / 29.034 (with **)

' -----[ Variables ]-------------------------------------------------------
rawDist VAR Word ' raw measurement
inches VAR Word
cm VAR Word

' -----[ Initialization ]--------------------------------------------------
' -----[ Program Code ]----------------------------------------------------
Main:
GOSUB Get_Sonar ' get sensor value
inches = rawDist ** RawToIn ' convert to inches
cm = rawDist ** RawToCm ' convert to centimeters''
gosub Distance
PAUSE 100
goto Main


' -----[ Subroutines ]-----------------------------------------------------

' This subroutine triggers the Ping sonar sensor and measures
' the echo pulse. The raw value from the sensor is converted to
' microseconds based on the Stamp module in use. This value is
' divided by two to remove the return trip -- the result value is
' the distance from the sensor to the target in microseconds.
Distance:
DEBUG [0, "Parallax Ping Sonar "]
DEBUG [13, "====================="]
DEBUG [13, "Time (uS)..... ", dec rawDist]
DEBUG [13, "Inches........ ", dec inches]
DEBUG [13, "Centimeters... ", dec cm]
RETURN
Get_Sonar:
LOW Ping ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, 1, rawDist ' measure echo pulse
rawDist = rawDist */ Scale ' convert to uS
rawDist = rawDist / 2 ' remove return trip
RETURN
'=======================================================================

Output:

Parallax Ping Sonar
=====================
Time (uS)..... 0
Inches........ 0
Centimeters... 0

There is an article that explain how to get all the numbers
http://www.parallax.com/dl/docs/prod/acc/PingISeeYou.pdf

the problem is ini the 'Get_Sonar', pulsout then pulsin, led blink but no 'rawDist'
I think the problem is in the Trigger. Incorrect number for Trigger.


Top
  
 
 Post subject: Re: need code for basicatom 28 + ping parallax
PostPosted: Fri Jan 20, 2006 7:48 pm 
A note: The Ping kit is sold by Parallax. It is a (semi-) intelligent ultrasonic distance sensor. It uses one wire/one pin to talk to a microprocessor. You can find the product info page here:
http://www.parallax.com/detail.asp?product_id=28015-5pack

This is a 5-pack, $100. It is probably available for $20 - $25 in singles.

The following source is the Stamp code for the Ping demo. I'm not really qualified to convert this, but no doubt, with this info, someone knowledgable can help here.

kenjj

' =========================================================================
'
' File...... Serial_LCD_Template.BS2
' Purpose... Template for Parallax Serial LCD
' Author.... (c) Parallax, Inc. -- All Rights Reserved
' E-mail.... support@parallax.com
' Started...
' Updated... 11 FEB 2005
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Ping PIN 8 ' Ping))) IO pin
LCD PIN 15 ' serial output to LCD


' -----[ Constants ]-------------------------------------------------------

#SELECT $STAMP
#CASE BS2, BS2E
T2400 CON 396
T9600 CON 84
T19K2 CON 32
Trigger CON 5 ' trigger pulse = 10 uS
Scale CON $200 ' raw x 2.00 = uS
#CASE BS2SX, BS2P
T2400 CON 1021
T9600 CON 240
T19K2 CON 110
Trigger CON 13
Scale CON $0CD ' raw x 0.80 = uS
#CASE BS2PE
T2400 CON 396
T9600 CON 84
T19K2 CON 32
Trigger CON 5
Scale CON $1E1 ' raw x 1.88 = uS
#ENDSELECT

LcdBaud CON T19K2

LcdBkSpc CON $08 ' move cursor left
LcdRt CON $09 ' move cursor right
LcdLF CON $0A ' move cursor down 1 line
LcdCls CON $0C ' clear LCD (use PAUSE 5 after)
LcdCR CON $0D ' move pos 0 of next line
LcdBLon CON $11 ' backlight on
LcdBLoff CON $12 ' backlight off
LcdOff CON $15 ' LCD off
LcdOn1 CON $16 ' LCD on; cursor off, blink off
LcdOn2 CON $17 ' LCD on; cursor off, blink on
LcdOn3 CON $18 ' LCD on; cursor on, blink off
LcdOn4 CON $19 ' LCD on; cursor on, blink on
LcdLine1 CON $80 ' move to line 1, column 0
LcdLine2 CON $94 ' move to line 2, column 0

LcdCC0 CON $F8 ' define custom char 0
LcdCC1 CON $F9 ' define custom char 1
LcdCC2 CON $FA ' define custom char 2
LcdCC3 CON $FB ' define custom char 3
LcdCC4 CON $FC ' define custom char 4
LcdCC5 CON $FD ' define custom char 5
LcdCC6 CON $FE ' define custom char 6
LcdCC7 CON $FF ' define custom char 7

RawToIn CON 889 ' 1 / 73.746 (with **)
RawToCm CON 2257 ' 1 / 29.034 (with **)

IsHigh CON 1 ' for PULSOUT
IsLow CON 0


' -----[ Variables ]-------------------------------------------------------

rawDist VAR Word ' raw measurement
inches VAR Word
cm VAR Word

spc VAR Nib ' spaces (for right-justification)


' -----[ EEPROM Data ]-----------------------------------------------------


' -----[ Initialization


Top
  
 
 Post subject: Re: need code for basicatom 28 + ping parallax
PostPosted: Wed Mar 08, 2006 5:15 pm 
I am having the same exact problem. The LED blinks when I PULSOUT but the PULSIN command times out having never received a return pulse from the ultrasonic sensor. Any help is greatly appreciated.


Top
  
 
 Post subject: Re: need code for basicatom 28 + ping parallax
PostPosted: Sat Mar 11, 2006 7:00 am 
For whats its worth, my 2 cents on the Atom vs the BS2. The Atom stomps the crap out of
the BS2, but (this a big but) the BS2 has more code examples applied for it then the
ATOM. After all the standard Atom will support parallel LCDs, something the BS2 can't do
(you'll need one the more expensive stamps for this). You'll get more code space with the
Atom, along with the In-Circuit-Debugger (ICD), which lets you watch the code run line for
line.
In my opinion, its fine to have and use both. Each have thier place and purpose in different
appalactions.


Top
  
 
 Post subject: Re: need code for basicatom 28 + ping parallax
PostPosted: Sat Mar 11, 2006 5:23 pm 
try changing the trigger pulse because the the processing speeds have changed. try substituting a 41 or 42 for the trigger rather than 5. That should compensate for the different processing speeds. Let me know if this works. I don't have the basicatom but I have used the ping with a BS2. Have you been happy with the basicAtom?


Top
  
 
 Post subject: Re: need code for basicatom 28 + ping parallax
PostPosted: Mon Mar 13, 2006 7:00 am 
Kyle...
here is the code
hope this help

I'm answering my own post :)


' -----[ I/O Definitions ]-------------------------------------------------

Ping CON P15

' -----[ Constants ]-------------------------------------------------------

Trigger CON 10
RawToIn CON 73.746
RawToCm CON 29.034

' -----[ Variables ]-------------------------------------------------------

rawDist VAR Word ' raw measurement
inches VAR Long
cm VAR Long

' -----[ Program Code ]----------------------------------------------------


Main:
GOSUB Get_Sonar ' get sensor value
inches = float rawDist FDIV float RawToIn ' convert to inches
cm = float rawDist FDIV float RawToCm ' convert to centimeters''
GOSUB Display
PAUSE 100
GOTO Main

' -----[ Subroutines ]-----------------------------------------------------

' This subroutine triggers the Ping sonar sensor and measures
' the echo pulse. The raw value from the sensor is converted to
' microseconds based on the Stamp module in use. This value is
' divided by two to remove the return trip -- the result value is
' the distance from the sensor to the target in microseconds.

Display:
SEROUT S_OUT, I9600, [0, "Parallax Ping Sonar "]
SEROUT S_OUT, I9600, [13, "====================="]
SEROUT S_OUT, I9600, [13, "Time (uS)..... ", dec rawDist]
SEROUT S_OUT, I9600, [13, "Inches........ ", real inches]
SEROUT S_OUT, I9600, [13, "Centimeters... ", real cm]
RETURN

Get_Sonar:
HIGH Ping ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, 1, rawDist ' measure echo pulse
rawDist = rawDist / 2 ' remove return trip
RETURN


Top
  
 
 Post subject: Re: need code for basicatom 28 + ping parallax
PostPosted: Tue Mar 14, 2006 7:00 am 
Thank you SO MUCH choco!


Top
  
 
 Post subject: Re: need code for basicatom 28 + ping parallax
PostPosted: Sat Aug 29, 2009 11:27 pm 
Offline
Master

Joined: Mon Aug 18, 2008 1:26 am
Posts: 799
Location: CA bay Area
I am moving this to the Atom Section. I'm not comfortable with it here in Projects. There are no diagrams or pictures, and starts with a question.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: need code for basicatom 28 + ping parallax
PostPosted: Thu Nov 15, 2012 11:04 pm 
Offline
Citizen

Joined: Mon Oct 29, 2012 2:19 pm
Posts: 6
I am trying this code on the ARC32 and get this error:

Error: FILE \TEST.BAS(LINE 24) : [TOKEN RAWDIST] : Unexpected token type

Are they not compatible?


Top
 Profile  
 
 Post subject: Re: need code for basicatom 28 + ping parallax
PostPosted: Fri Nov 07, 2014 10:58 pm 
Offline
New User

Joined: Fri Nov 07, 2014 10:55 pm
Posts: 1
Let me know if this works. I don't have the basicatom but I have used the ping with a BS2. Have you been happy with the basicAtom?


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


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