Shop OBEX P1 Docs P2 Docs Learn Events
Senior Project - Please Help — Parallax Forums

Senior Project - Please Help

donfettuccinidonfettuccini Posts: 7
edited 2004-12-06 02:12 in BASIC Stamp
Hello everyone!

My partner and I are slimulating a RADAR device with the SRF04 sensor.
I am trying to import the data read from the SRF04 into excel, using the StampDaq program.
I tried using the "testcode" within the help file and add it into·the code I am using for the SRF04·and I am still having trouble.

I can connect to port 3 within StampDaq, but it is·not recieving any data from the SRF04 and entering into excel. The basic command to label the columns in excel are not even showing up in excel after connection is made.

Thanks
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================

' -----[noparse][[/noparse] Program Description ]---------------------------------------------
'
' This program uses the Devantech SRF04 to measure the distance between the
' unit and a target.  Display is raw value, centimeters, and inches.
' The sensor will be put onto of a moving robot which will make a sweep of 3
' sectors.
'sector 1 = front
'sector 2 = robot moves to the left
'sector 3 = robot moves to the right
'Motion will be sector 1, sector 2, sector 1, sector 3 then loop

' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
'
Trigger         PIN     0
Echo            PIN     1

' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
#SELECT $STAMP
  #CASE BS2, BS2E
    Trig10      CON     5                       ' trigger pulse = 10 uS
    ToCm        CON     30                      ' conversion factor to cm
  #CASE BS2SX, BS2P
    Trig10      CON     13
    ToCm        CON     78
  #CASE BS2PE
    Trig10      CON     5
    ToCm        CON     31
#ENDSELECT
 
sPin   CON   3  'Serial Pin - P3, Programming port
Baud   CON   84  'Baud mode for a rate of 9600, 8-N-1
 
' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
samples         VAR     Nib                     ' loop counter
pWidth          VAR     Word                    ' pulse width from sensor
rawDist         VAR     Word                    ' filtered measurment
cm              VAR     Word                    ' centimeters
inches          VAR     Word
counter         VAR     Byte                    'how many readings per sweep
 
 
 PAUSE 1000    'Allow data communications to stabilize
 SEROUT sPin,Baud,[noparse][[/noparse]CR]   'Send a lone CR to ensure StampDAQ buffer is ready

' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
 Configure:
SEROUT sPin,Baud,[noparse][[/noparse]CR,"LABEL,Raw,Centi,Inches,Sector",CR]  'Label 4 columns with Raw, Centi, Inches and Sector
SEROUT sPin,Baud,[noparse][[/noparse]"CLEARDATA",CR]    'Clear all data columns (A-J) in Excel
Setup:
  LOW Trigger
  DEBUG CLS,
        "Devantech SRF04 Demo", CR,
        "--------------------", CR,
        "Raw...........      ", CR,
        "Centimeters...      ", CR,
        "Inches........      ", CR,
        "Sector........      "
' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
Main:
    DO
'---sector 1 ---------------------------------------------------------------------
    GOSUB Get_Sonar                             ' take sonar reading
    DEBUG CRSRXY, 15, 2, DEC rawDist, CLREOL
    cm = rawDist / ToCm                         ' convert to centimeters
    DEBUG CRSRXY, 15, 3, DEC cm, CLREOL
    inches = cm */ $03EF                        ' x 3.937 (to 0.1 inches)
    DEBUG CRSRXY, 15, 4,
          DEC inches / 10, ".", DEC1 inches,
          CLREOL  ,CR
    DEBUG CRSRXY, 15, 5
    DEBUG "1"                                   'display which sector objects in
    PAUSE 1000                                  ' delay between sector
    SEROUT sPin,Baud,[noparse][[/noparse]DEC rawDist, ",", DEC cm,",", DEC1 inches, ",", DEC 1, CR]
'---sector 2 ---------------------------------------------------------------------
      GOSUB Get_Sonar                             ' take sonar reading
    DEBUG CRSRXY, 15, 2, DEC rawDist, CLREOL
    cm = rawDist / ToCm                         ' convert to centimeters
    DEBUG CRSRXY, 15, 3, DEC cm, CLREOL
    inches = cm */ $03EF                        ' x 3.937 (to 0.1 inches)
    DEBUG CRSRXY, 15, 4,
          DEC inches / 10, ".", DEC1 inches,
          CLREOL     ,CR
    DEBUG CRSRXY, 15, 5
    DEBUG "2"
    PAUSE 1000                                  ' delay between sector
    SEROUT sPin,Baud,[noparse][[/noparse]DEC rawDist, ",", DEC cm,",", DEC1 inches, ",", DEC 2, CR]
'---sector 1 --------------------------------------------------------------------
    GOSUB Get_Sonar                             ' take sonar reading
    DEBUG CRSRXY, 15, 2, DEC rawDist, CLREOL
    cm = rawDist / ToCm                         ' convert to centimeters
    DEBUG CRSRXY, 15, 3, DEC cm, CLREOL
    inches = cm */ $03EF                        ' x 3.937 (to 0.1 inches)
    DEBUG CRSRXY, 15, 4,
          DEC inches / 10, ".", DEC1 inches,
          CLREOL     ,CR
    DEBUG CRSRXY, 15, 5
    DEBUG "1"
    PAUSE 1000                                  ' delay between sector
    SEROUT sPin,Baud,[noparse][[/noparse]DEC rawDist, ",", DEC cm,",", DEC1 inches, ",", DEC 1, CR]
'---sector 3 ----------------------------------------------------------------
    GOSUB Get_Sonar                             ' take sonar reading
    DEBUG CRSRXY, 15, 2, DEC rawDist, CLREOL
    cm = rawDist / ToCm                         ' convert to centimeters
    DEBUG CRSRXY, 15, 3, DEC cm, CLREOL
    inches = cm */ $03EF                        ' x 3.937 (to 0.1 inches)
    DEBUG CRSRXY, 15, 4,
          DEC inches / 10, ".", DEC1 inches,
          CLREOL     ,CR
    DEBUG CRSRXY, 15, 5
    DEBUG "3"
    PAUSE 1000                                  ' delay between sector
    SEROUT sPin,Baud,[noparse][[/noparse]DEC rawDist, ",", DEC cm,",", DEC1 inches, ",", DEC 3, CR]
 ' NEXT
    LOOP
  END

' -----[noparse][[/noparse] Subroutines ]-----------------------------------------------------
Get_Sonar:
  rawDist = 0                                   ' clear measurement
  FOR samples = 1 TO 5                          ' take five samples
    PULSOUT Trigger, Trig10                     ' 10 uS trigger pulse
    #SELECT $STamp
      #CASE BS2, BS2E
        RCTIME Echo, 1, pWidth                  ' measure pulse
      #CASE #ELSE
        PULSIN Echo, 1, pWidth                  ' measure pulse
    #ENDSELECT
    rawDist = rawDist + (pWidth / 5)            ' simple digital filter
    PAUSE 10                                    ' minimum period between
  NEXT
  RETURN

Comments

  • steve_bsteve_b Posts: 1,563
    edited 2004-11-30 20:59
    are you receiving garbage at least?

    you have used 84 as your baudmode value
    "Baud·· CON·· 84· 'Baud mode for a rate of 9600, 8-N-1"

    I don't think 84 is a valid number.

    If you are running a BS2 and want 9600,8N1 and you're not going thru a RS232 tx chip then you want 16624 as your baudmode value.

    That's the first thing I popped on...(I'm at work so don't have time to go thru the rest!!)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    http://www.geocities.com/paulsopenstage

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."

  • steve_bsteve_b Posts: 1,563
    edited 2004-11-30 21:05
    Hold on...maybe if I scrolled down my help file a little further I'd see!!

    84 is a valid number...but it is for a TRUE signal.· I think you only want TRUE if you are going thru an RS232 tx'r chip (like a MAX232).

    (at least I had to use TRUE on my latest rig; while the inverted # worked for data w/o the chip).

    So, you might want to try the inverted value for 96,8N1· which is 16468.



    sorry for the confusion...hope this helps!



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    http://www.geocities.com/paulsopenstage

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."

  • donfettuccinidonfettuccini Posts: 7
    edited 2004-11-30 22:16
    I made the change (84 to 16468) but unfortunately problem still exist.
    I don't recieve any garbage values or any values.

    I did notice when I use the "Simple Data Test Code" provided by StampDaq and set the port to 3 the same problem occurs.
    The "Simple Data Test Code" works when I set the port to 1 within StampDaq.

    But when I set the port to 1 using my code, error "StampDaq could not connect. Please check port setting."

    -Hernan
  • NewzedNewzed Posts: 2,503
    edited 2004-11-30 22:59
    Why don't you switch to Hyperterminal?· Capturing data to Excel is a very simple thing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    New Combo LCD Backpack

    http://hometown.aol.com/newzed/index.html
    ·
  • donfettuccinidonfettuccini Posts: 7
    edited 2004-12-01 00:22
    I don't know how to switch to Hyperterminal. All these equipment and PBasic language is fairly new to me.
  • steve_bsteve_b Posts: 1,563
    edited 2004-12-01 01:14
    Hyperterminal is a program that comes with Windows.

    if you're a windows user than you'll have to find it in through your Start button (Start>Programs>Accesories>Communications· ....may vary between some versions of windows).

    Anyhow, load up hyperterminal.· They'll ask you for a connection profile name.· Just type anything you want...or something intelligable to be easier to go back to.

    Next it'll ask you what you want to connect to.· At the bottom of the window there's a field for "Connect Using:".· Click this and select the com port you're on.· The next window asks you what port settings you want.· Select your 9600 N81 in there.

    You're pretty well in it now.· If you're connected properly then you should be seeing your data.

    how are you expecting to get your data?· You are outputting serial data on pin3 of the stamp (P3) and you are also debugging data through PBasic to your PC.

    What kind of board are you using for your BS2?· A Board Of Education (BOE)? or something else?·

    I'll guess that you want the data that's going out of pin3.· You'll have to attach a wire from I/O pin3 (not the physical pin3) to pin2 of your rs232 connector.· You'll also need a ground.· So connect a wire from pin5 of your Rs232 cable to Vss/Gnd of your BS2.

    You'll have to make a cable yourself....or splice in to one and attach on to the right wires.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    http://www.geocities.com/paulsopenstage

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."

  • donfettuccinidonfettuccini Posts: 7
    edited 2004-12-01 18:10
    I must be doing something wrong, because I can't get the·HyperTerminal·or StampDaq to work.
    ·
    I am using a BOE, BS2 and the SRF04. The SRF04 is connected to
    Vss, Vdd, the trigger pulse input pin is connected to P0 and the echo pulse output pin is connected to P1.
    ·
    The StampDaq help file said the sPin should be 16 and the baudmode value should be 84.
    ·
    The “Simple Data Test Code” works with sPin = 16, baudmode = 84 and having the port set to 1 within StampDaq.
    ·
    But when I connect the SRF04 and set the same values for sPin, baudmode and setting the port to 1 within StampDaq – error “StampDaq could not connect. Please check port settingappears.
    ·
    Any help is appreciated; I have to present the project to my teacher on Monday.
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-01 19:12
    What are you using for power? A 9-volt battery? Could it be almost dead?

    The error you describe tends to come from the 'new' device (the SRF04) pulling enough current that the BS2 can't run. This shouldn't happen with an SRF04, so I can only conclude your power-supply is weak.
  • dandreaedandreae Posts: 1,375
    edited 2004-12-01 22:00
    Hello,

    I set this up and I was receiving ASCII errors in the Stamp DAQ box that look like this:

    Error:· Data < ASCII 13 or ASCII 200

    I'll look into it some more and see what I can come up with.

    Dave



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Tech Support
    dandreae@parallax.com
    www.parallax.com

    ·
  • dandreaedandreae Posts: 1,375
    edited 2004-12-01 23:10
    I have commented all of your debug statements and I got it to work in centimeters.· I believe the problem is in your debug statements that relate to inches.· You cannot use CRSRXY, it's ASCII value is less than 13 and the Stamp DAQ won't accept anything under ASCII value 13 or over 200.

    Dave




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Tech Support
    dandreae@parallax.com
    www.parallax.com



    Post Edited (Dave Andreae (Parallax)) : 12/1/2004 11:24:43 PM GMT
  • donfettuccinidonfettuccini Posts: 7
    edited 2004-12-02 01:53
    Dave,

    Is it possible·to send me the code that worked for you. I commented out all of the debug statements·and I still can't read any data. Can you let me know what port within StampDaq you connected to.

    Thanks
  • dandreaedandreae Posts: 1,375
    edited 2004-12-02 17:04
    Hello,

    Here is the code that I used (attached).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Tech Support
    dandreae@parallax.com
    www.parallax.com
  • donfettuccinidonfettuccini Posts: 7
    edited 2004-12-06 02:12
    Thanks everyone for their input.

    Its seems to be reading inputs now.

    Thanks
Sign In or Register to comment.