Shop OBEX P1 Docs P2 Docs Learn Events
Ping sensor and Datalogger — Parallax Forums

Ping sensor and Datalogger

TabiriTabiri Posts: 23
edited 2011-01-19 00:30 in BASIC Stamp
I have the datalogger and the ping sensor hooked up, and I'm using the datalogger program. It takes measurements from the ping sensor and stores them, and then displays them. The program stores them fine, but when it displays them, it just displays the last one over and over.
Example:

Memory Stick Datalogger Demo V1.0

Initializing...Done!
Synchronizing...Done
Switching to Short Command Mode...Done!
Waiting for Memory Stick...Ready!
Opening Data File...Open!

Writing Data...
Sample 00001 of 00010 --> 00076
Sample 00002 of 00010 --> 00076
Sample 00003 of 00010 --> 00077
Sample 00004 of 00010 --> 00041
Sample 00005 of 00010 --> 00012
Sample 00006 of 00010 --> 00052
Sample 00007 of 00010 --> 00014
Sample 00008 of 00010 --> 00038
Sample 00009 of 00010 --> 00014
Sample 00010 of 00010 --> 00051
Closing Data File...Done!

Opening Data File...Open!
Reading Data...
Sample 00001 of 00010 --> 00051
Sample 00002 of 00010 --> 00051
Sample 00003 of 00010 --> 00051
Sample 00004 of 00010 --> 00051
Sample 00005 of 00010 --> 00051
Sample 00006 of 00010 --> 00051
Sample 00007 of 00010 --> 00051
Sample 00008 of 00010 --> 00051
Sample 00009 of 00010 --> 00051
Sample 00010 of 00010 --> 00051
Closing Data File...Program Complete!


Here's the code.

datalogger demo.bs2

Comments

  • FranklinFranklin Posts: 4,747
    edited 2011-01-14 21:15
    When you are writing you are using a variable called counter. Where is this when you are reading?
  • bsnutbsnut Posts: 521
    edited 2011-01-15 00:58
    I noticed some possible problems with code that you provided and have some questions for you.

    1) Why did you comment this out of the code?
    'inDistance      VAR     Byte                   ' Number Of Samples To Log
    

    2) I understand why you did this. But, did you remove any other code above or below this?
    PULSIN 3, 1, time
    

    What, I would do is connect the demo circuit up has shown at top of the program code and change to this to see if it takes of your problem.
    RCTIME 3, 1, time
    
  • TabiriTabiri Posts: 23
    edited 2011-01-17 17:33
    I copied and pasted in some of the code that I got for the ping sensor. The inDistance was the variable that would display the distance in inches. However, I was running out of space for variables, so I had to comment that out. The " 'Number Of Samples To Log" was originally right after the variable NumSamples.

    The program was originally for a light sensor or thermistor, but since I didn't have one of those, I had to change it to accept the ping data. All I changed was where it gathered the data, and replaced result with cmDistance.
    I got the program working (I had forgotten to replace the result variable in a few places) and I uncovered a new problem. The first measurement it displays on opening the file seems to be a number around the maximum measurement. Then it just moves the rest of the measurements down one space, and never displays the original sample 10.
    example:
    Memory Stick Datalogger Demo V1.0

    Initializing...Done!
    Synchronizing...Done
    Switching to Short Command Mode...Done!
    Waiting for Memory Stick...Ready!
    Opening Data File...Open!

    Writing Data...
    Sample 00001 of 00010 --> 00075
    Sample 00002 of 00010 --> 00075
    Sample 00003 of 00010 --> 00075
    Sample 00004 of 00010 --> 00038
    Sample 00005 of 00010 --> 00040
    Sample 00006 of 00010 --> 00037
    Sample 00007 of 00010 --> 00035
    Sample 00008 of 00010 --> 00036
    Sample 00009 of 00010 --> 00075
    Sample 00010 of 00010 --> 00042
    Closing Data File...Done!

    Opening Data File...Open!
    Reading Data...
    Sample 00001 of 00010 --> 00079
    Sample 00002 of 00010 --> 00075
    Sample 00003 of 00010 --> 00075
    Sample 00004 of 00010 --> 00075
    Sample 00005 of 00010 --> 00038
    Sample 00006 of 00010 --> 00040
    Sample 00007 of 00010 --> 00037
    Sample 00008 of 00010 --> 00035
    Sample 00009 of 00010 --> 00036
    Sample 00010 of 00010 --> 00075
    Closing Data File...Program Complete!
  • bsnutbsnut Posts: 521
    edited 2011-01-18 01:10
    What I would do, is run this test code first that came with Ping sensor to make sure that it is preforming correctly.
    ' Smart Sensors and Applications - PingMeasureCmAndIn.bs2
    ' Measure distance with Ping))) sensor and display in both in & cm
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' Conversion constants for room temperature measurements.
    CmConstant CON 2260
    InConstant CON 890
    cmDistance VAR Word
    inDistance VAR Word
    time VAR Word
    DO
    PULSOUT 15, 5
    PULSIN 15, 1, time
    cmDistance = cmConstant ** time
    inDistance = inConstant ** time
    DEBUG HOME, DEC3 cmDistance, " cm"
    DEBUG CR, DEC3 inDistance, " in"
    PAUSE 100
    LOOP
    
    From, what I see in the above test code, you will need to comment this
    inDistance = inConstant ** time
    
    back into your code to get your program working the way you want it too.
    I think it will provide you with better results if you tried it.
  • TabiriTabiri Posts: 23
    edited 2011-01-18 23:07
    Alright thanks. It seems to be working good now.
  • bsnutbsnut Posts: 521
    edited 2011-01-19 00:30
    I am glad you got it working and that's what we are here for.
Sign In or Register to comment.