Shop OBEX P1 Docs P2 Docs Learn Events
Sharp GP2D05 PIR Help! Stamp code keeps looping! — Parallax Forums

Sharp GP2D05 PIR Help! Stamp code keeps looping!

ArchiverArchiver Posts: 46,084
edited 2000-04-30 18:38 in General Discussion
Hi All,

Have a problem using the Sharp GP2D05 and Basic Stamp2.
I modified the example code from Acroname (see below) that came with
the kit. This worked fine and I got a reading from the Sharp PIR.
However, because I wanted to use data logging activex control to save
the readings to a log file I decided I need to use SEROUT. So I thought
I would test another program that uses SEROUT on the basic stamp(2). I
used an example from Al Williams book " Microcontroller projects with
Basic Stamps" - ( pp126 Sample Program.).

The SEROUT example used pin 16 and included SERIN commands. The
problem is that since I ran the SEROUT example on the Stamp the modified
example code from Acroname doesn't work. It stops at the line that reads
in from the sensor to a variable.
Then repeatedly goes back to "DEBUG Start". I think my sensor has blown
as a result of the SERIN commands. But I don't know. Can sending SERIN
commands to pin 16 blow a PIR that has input connection to pin 15?
Any ideas on what else might cause the problem?

Gratefull for any suggestions.

The two examples are listed below.

****** the modified acroname code follows******
'

' variable declarations

val05 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

DEBUG "Start", CR ' indicate beginning

FOR i = 1 TO 100

GOSUB read05 ' take reading

DEBUG dec val05, CR ' display result

PAUSE 100 ' stall so display readable

NEXT

DEBUG "Finish", CR ' indicate end


END ' stop Stamp when done

'

' subroutine read05

'

' This subroutine takes a reading from the connected

' GP2D05 detector and stores the value in "val05".

' Any two pins can be used. Set "dt" to the data line

' of the GP2D05 (pin 3 on JST connector, yellow wire).

' Set cl to the clock line of the GP2D05 (pin 1 on the

' JST connector, green wire). Also, the IN15 needs

' to be set to the correct variable for the data pin

' (data line).


read05:

LOW cl ' turn on detector for reading

DEBUG " detector on ", CR

PAUSE 56 ' wait 56ms for detector to read

val05 = IN15 ' obtain reading from detector

DEBUG dec val05, CR

HIGH cl ' turn off detector

PAUSE 2 ' wait for reset

RETURN

**************************************


KATH

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-04-30 16:35
    Hi Kath,

    If I understand what you are saying, it sounds like the Stamp is resetting
    itself. This is often for several reasons:

    1) If your battery (or other supply) is marginal, turning on something that
    requires a bit of power will reset the Stamp.

    2) Noise can enter on the RESET or ATN line, although this is usually
    associated with motors. I don't think an IR sensor is that noisy.

    3) Falling into a return without a GOSUB (doesn't seem to be your problem).

    I don't know how using SEROUT/SERIN on pin 16 (the programming port) could
    affect pin 15 -- never heard of anything like that happening.

    Are you powering of a battery or the mains? When your program worked before,
    did you not have a serial cable connected (or a shorter serial cable)? Noise
    pickup on ATN increases with a longer cable or a disconnected cable.

    Regards,

    Al Williams
    AWC
    * Floating point math for the Stamp, PIC, SX, or any processor at
    http://www.al-williams.com/awce/pak1.htm


    >
    Original Message
    > From: Kath [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=tpLCcpCf64jZqB1t_YktpRox5A-XDjdMHWE2D6BnX0BjNA-r96mZy_D0XO_6yCqZ_y6KGttjSVipexXif8IqnYXDvw]kath@i...[/url
    > Sent: Sunday, April 30, 2000 3:35 AM
    > To: basicstamps@egroups.com
    > Subject: [noparse][[/noparse]basicstamps] Sharp GP2D05 PIR Help! Stamp code keeps looping!
    >
    >
    > Hi All,
    >
    > Have a problem using the Sharp GP2D05 and Basic Stamp2.
    > I modified the example code from Acroname (see below) that came with
    > the kit. This worked fine and I got a reading from the Sharp PIR.
    > However, because I wanted to use data logging activex control to save
    > the readings to a log file I decided I need to use SEROUT. So I thought
    > I would test another program that uses SEROUT on the basic stamp(2). I
    > used an example from Al Williams book " Microcontroller projects with
    > Basic Stamps" - ( pp126 Sample Program.).
    >
    > The SEROUT example used pin 16 and included SERIN commands. The
    > problem is that since I ran the SEROUT example on the Stamp the modified
    > example code from Acroname doesn't work. It stops at the line that reads
    > in from the sensor to a variable.
    > Then repeatedly goes back to "DEBUG Start". I think my sensor has blown
    > as a result of the SERIN commands. But I don't know. Can sending SERIN
    > commands to pin 16 blow a PIR that has input connection to pin 15?
    > Any ideas on what else might cause the problem?
    >
    > Gratefull for any suggestions.
    >
    > The two examples are listed below.
    >
    > ****** the modified acroname code follows******
    > '
    >
    > ' variable declarations
    >
    > val05 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
    >
    > DEBUG "Start", CR ' indicate beginning
    >
    > FOR i = 1 TO 100
    >
    > GOSUB read05 ' take reading
    >
    > DEBUG dec val05, CR ' display result
    >
    > PAUSE 100 ' stall so display readable
    >
    > NEXT
    >
    > DEBUG "Finish", CR ' indicate end
    >
    >
    > END ' stop Stamp when done
    >
    > '
    >
    > ' subroutine read05
    >
    > '
    >
    > ' This subroutine takes a reading from the connected
    >
    > ' GP2D05 detector and stores the value in "val05".
    >
    > ' Any two pins can be used. Set "dt" to the data line
    >
    > ' of the GP2D05 (pin 3 on JST connector, yellow wire).
    >
    > ' Set cl to the clock line of the GP2D05 (pin 1 on the
    >
    > ' JST connector, green wire). Also, the IN15 needs
    >
    > ' to be set to the correct variable for the data pin
    >
    > ' (data line).
    >
    >
    > read05:
    >
    > LOW cl ' turn on detector for reading
    >
    > DEBUG " detector on ", CR
    >
    > PAUSE 56 ' wait 56ms for detector to read
    >
    > val05 = IN15 ' obtain reading from detector
    >
    > DEBUG dec val05, CR
    >
    > HIGH cl ' turn off detector
    >
    > PAUSE 2 ' wait for reset
    >
    > RETURN
    >
    > **************************************
    >
    >
    > KATH
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-04-30 18:36
    I'm assuming she is using the STAMPW terminal which takes care of this
    automatically. Also, many carrier boards (like our CAR-I) use a capacitor to
    allow a single reset pulse through. You can find the hookup for that in the
    Stamp manual.

    Regards,

    Al Williams
    AWC
    * Expand your Stamp I/O: http://www.al-williams.com/awce/pak3.htm


    >
    Original Message
    > From: Dennis Clark [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=LIW3CmBcwyxmL_igoU5Ar8N7tpruqn12KUuiC6WggTxtwzthXnjnnqxeICDXhRbzpTPr9Ucj]dlc@v...[/url
    > Sent: Sunday, April 30, 2000 12:39 PM
    > To: basicstamps@egroups.com
    > Subject: Re: [noparse][[/noparse]basicstamps] Sharp GP2D05 PIR Help! Stamp code keeps
    > looping!
    >
    >
    > Kath,
    >
    > Carefully read the serial I/O section dealing with using port 16. The
    > ATN line will be toggled by the computer which resets the Stamp II. I
    > suggest that you find and put a switch on the ATN (of the Stamp) line
    > if you are going to keep using the port 16 serial I/O.
    >
    > DLC
    >
    > Kath wrote:
    > >
    > > Hi All,
    > >
    > > Have a problem using the Sharp GP2D05 and Basic Stamp2.
    > > I modified the example code from Acroname (see below) that came with
    > > the kit. This worked fine and I got a reading from the Sharp PIR.
    > > However, because I wanted to use data logging activex control to save
    > > the readings to a log file I decided I need to use SEROUT. So I thought
    > > I would test another program that uses SEROUT on the basic stamp(2). I
    > > used an example from Al Williams book " Microcontroller projects with
    > > Basic Stamps" - ( pp126 Sample Program.).
    > >
    > > The SEROUT example used pin 16 and included SERIN commands. The
    > > problem is that since I ran the SEROUT example on the Stamp the modified
    > > example code from Acroname doesn't work. It stops at the line that reads
    > > in from the sensor to a variable.
    > > Then repeatedly goes back to "DEBUG Start". I think my sensor has blown
    > > as a result of the SERIN commands. But I don't know. Can sending SERIN
    > > commands to pin 16 blow a PIR that has input connection to pin 15?
    > > Any ideas on what else might cause the problem?
    > >
    > > Gratefull for any suggestions.
    > >
    > > The two examples are listed below.
    > >
    > > ****** the modified acroname code follows******
    > > '
    > >
    > > ' variable declarations
    > >
    > > val05 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
    > >
    > > DEBUG "Start", CR ' indicate beginning
    > >
    > > FOR i = 1 TO 100
    > >
    > > GOSUB read05 ' take reading
    > >
    > > DEBUG dec val05, CR ' display result
    > >
    > > PAUSE 100 ' stall so display readable
    > >
    > > NEXT
    > >
    > > DEBUG "Finish", CR ' indicate end
    > >
    > > END ' stop Stamp when done
    > >
    > > '
    > >
    > > ' subroutine read05
    > >
    > > '
    > >
    > > ' This subroutine takes a reading from the connected
    > >
    > > ' GP2D05 detector and stores the value in "val05".
    > >
    > > ' Any two pins can be used. Set "dt" to the data line
    > >
    > > ' of the GP2D05 (pin 3 on JST connector, yellow wire).
    > >
    > > ' Set cl to the clock line of the GP2D05 (pin 1 on the
    > >
    > > ' JST connector, green wire). Also, the IN15 needs
    > >
    > > ' to be set to the correct variable for the data pin
    > >
    > > ' (data line).
    > >
    > > read05:
    > >
    > > LOW cl ' turn on detector for reading
    > >
    > > DEBUG " detector on ", CR
    > >
    > > PAUSE 56 ' wait 56ms for detector to read
    > >
    > > val05 = IN15 ' obtain reading from detector
    > >
    > > DEBUG dec val05, CR
    > >
    > > HIGH cl ' turn off detector
    > >
    > > PAUSE 2 ' wait for reset
    > >
    > > RETURN
    > >
    > > **************************************
    > >
    > > KATH
    >
    > --
    >
    > Dennis Clark http://www.verinet.com/~dlc
    > dlc@v...
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-04-30 18:38
    Kath,

    Carefully read the serial I/O section dealing with using port 16. The
    ATN line will be toggled by the computer which resets the Stamp II. I
    suggest that you find and put a switch on the ATN (of the Stamp) line
    if you are going to keep using the port 16 serial I/O.

    DLC

    Kath wrote:
    >
    > Hi All,
    >
    > Have a problem using the Sharp GP2D05 and Basic Stamp2.
    > I modified the example code from Acroname (see below) that came with
    > the kit. This worked fine and I got a reading from the Sharp PIR.
    > However, because I wanted to use data logging activex control to save
    > the readings to a log file I decided I need to use SEROUT. So I thought
    > I would test another program that uses SEROUT on the basic stamp(2). I
    > used an example from Al Williams book " Microcontroller projects with
    > Basic Stamps" - ( pp126 Sample Program.).
    >
    > The SEROUT example used pin 16 and included SERIN commands. The
    > problem is that since I ran the SEROUT example on the Stamp the modified
    > example code from Acroname doesn't work. It stops at the line that reads
    > in from the sensor to a variable.
    > Then repeatedly goes back to "DEBUG Start". I think my sensor has blown
    > as a result of the SERIN commands. But I don't know. Can sending SERIN
    > commands to pin 16 blow a PIR that has input connection to pin 15?
    > Any ideas on what else might cause the problem?
    >
    > Gratefull for any suggestions.
    >
    > The two examples are listed below.
    >
    > ****** the modified acroname code follows******
    > '
    >
    > ' variable declarations
    >
    > val05 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
    >
    > DEBUG "Start", CR ' indicate beginning
    >
    > FOR i = 1 TO 100
    >
    > GOSUB read05 ' take reading
    >
    > DEBUG dec val05, CR ' display result
    >
    > PAUSE 100 ' stall so display readable
    >
    > NEXT
    >
    > DEBUG "Finish", CR ' indicate end
    >
    > END ' stop Stamp when done
    >
    > '
    >
    > ' subroutine read05
    >
    > '
    >
    > ' This subroutine takes a reading from the connected
    >
    > ' GP2D05 detector and stores the value in "val05".
    >
    > ' Any two pins can be used. Set "dt" to the data line
    >
    > ' of the GP2D05 (pin 3 on JST connector, yellow wire).
    >
    > ' Set cl to the clock line of the GP2D05 (pin 1 on the
    >
    > ' JST connector, green wire). Also, the IN15 needs
    >
    > ' to be set to the correct variable for the data pin
    >
    > ' (data line).
    >
    > read05:
    >
    > LOW cl ' turn on detector for reading
    >
    > DEBUG " detector on ", CR
    >
    > PAUSE 56 ' wait 56ms for detector to read
    >
    > val05 = IN15 ' obtain reading from detector
    >
    > DEBUG dec val05, CR
    >
    > HIGH cl ' turn off detector
    >
    > PAUSE 2 ' wait for reset
    >
    > RETURN
    >
    > **************************************
    >
    > KATH

    --
    Dennis Clark http://www.verinet.com/~dlc
    dlc@v...
Sign In or Register to comment.