Shop OBEX P1 Docs P2 Docs Learn Events
Total noob needs help with programm — Parallax Forums

Total noob needs help with programm

WallydragWallydrag Posts: 16
edited 2009-12-12 17:35 in BASIC Stamp
Okay guys, I need a lot of help since I really know nothing.

I'm wanting to use a BASIC Stamp 1 Carrier Board (which means programming a BASIC Stamp 1 Module I think) to control a small DC motor. I'm also wanting to use a parallax PIR sensor to activate the motor.

It doesn't seem like that hard of a thing to accomplish, I just don't really know how to do it.

I'm wanting it to do this:

When the PIR sensor senses movement it activates the motor to turn for 0.5 seconds then stop, pause for 5 seconds, then revers polarity and turn the other way for 0.5 seconds, then pause for 30 seconds and reset.

I also need to control how fast the motor spins but I think I do that with resistors (though I could be wrong).

Any help at all would be very, very appreciated! Thanks!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-08 15:59
    Start with "What's a Microcontroller?" and the "BASIC Stamp Syntax and Reference Manual". You can find the first by going to Parallax's main website and clicking on "Downloads". In the list that you get, if you click on "Stamps in Class Downloads", you'll find the first. If you click on "BASIC Stamp Documentation", you'll find the second. To control a motor the way you want, you'll need an H-bridge like the L293D. Do a Google search for "wiki h-bridge" for an article on h-bridges and how they work. There is sample code for the L293D in Parallax's StampWorks manual which you can download from here: www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/txtSearch/stampworks/List/1/ProductID/144/Default.aspx?SortField=ProductName%2cProductName
  • WallydragWallydrag Posts: 16
    edited 2009-12-09 03:40
    Thanks. Unfortunately the Stamps in Class download uses language for Stamp 2 and I'm going to use a Stamp 1. I'm not familiar enough with PBASIC to know how to convert things from BS2 to BS1. Is there a good BS1 tutorial out there for people with no programming experience?
  • Brad_HBrad_H Posts: 35
    edited 2009-12-09 04:01
    From the Parallax home page go to "product Info", then "microcontrollers", then under Basic Stamp look for downloads, click on "Documentation".· Fourth item down is called "BS1 and BS2 Conversion Tips".·

    Brad
  • Desy2820Desy2820 Posts: 138
    edited 2009-12-09 04:40
    You may also want to look at EFX-Tek's Prop 1 Controller.· It uses a Basic Stamp 1 as it's core, but includes low-side drivers.

    http://www.efx-tek.com/topics/prop-1.html

    Hope this helps!
  • WallydragWallydrag Posts: 16
    edited 2009-12-09 20:29
    Okay, I think I'm getting close but I need some help with the code:

    What I'm trying to make happen is that when the PIR senses a motion it will send a signal to Pin 0. When that signal should trigger "Motor:" to run. I've also tried to make it so that once the stamp recognizes that first signal, it won't recognize any more for 60 seconds. I guess I should make it that once it gets the first signal it reverses to output for 60 seconds the back to input until it gets another signal again.

    My real trouble is that when I check the syntax it highlights the "THEN" and says Error: Expected an operator. Thanks for the help.

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}

    SYMBOL PIR = PIN0

    LET DIRS = %00001110

    Main:
    IF PIR THEN Motor
    PAUSE 60000
    GOTO Main

    Motor:
    HIGH PIN1
    LOW PIN2
    HIGH PIN3

    PAUSE 500

    LOW PIN1
    LOW PIN2
    HIGH PIN3

    PAUSE 5000

    LOW PIN1
    HIGH PIN2
    HIGH PIN3

    PAUSE 500

    LOW PIN1
    LOW PIN2
    HIGH PIN3

    NAP 30000

    GOTO Main
  • Brad_HBrad_H Posts: 35
    edited 2009-12-09 21:01
    Your·IF needs a condition,

    IF PIR = 1 THEN Motor for example. Look at·IF using the Basic Stamp Editor help it explains it.

    Brad
  • WallydragWallydrag Posts: 16
    edited 2009-12-10 22:45
    Okay, say here's a revamped program. Hopefully this is better.

    Hopefully what this program will do is keep checking PIN 0 until it sense a signal being sent from the PIR. When the input sense a signal it will reverse PIN 0 to output so that even if the PIR keeps sending signals it won't see them. The motor will run through it's routine then hang out for 54 seconds (for a total of 60 seconds from start to finish) then reverse PIN 0 back to input so that if the PIR sends another signal it will see it again. Thanks for all the help!

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}

    '
    [noparse][[/noparse] I/O Definitions ]

    SYMBOL Trigger = PIN0
    SYMBOL Yes = 1
    SYMBOL No = 0

    '
    [noparse][[/noparse] Initialization ]

    DIRS = %00001110

    '
    [noparse][[/noparse] Program Code ]

    Main:
    IF Trigger = No THEN GOTO Main
    If Trigger = Yes THEN GOTO Motor


    Motor:

    REVERSE PIN0

    HIGH PIN1
    LOW PIN2
    HIGH PIN3

    PAUSE 500

    LOW PIN1
    LOW PIN2
    HIGH PIN3

    PAUSE 5000

    LOW PIN1
    HIGH PIN2
    HIGH PIN3

    PAUSE 500

    LOW PIN1
    LOW PIN2
    HIGH PIN3

    NAP 60000

    REVERSE PIN0

    GOTO Main
  • FranklinFranklin Posts: 4,747
    edited 2009-12-10 23:42
    You don't need to reverse the pin just ignore the input (don't check it) reversing the pin could cause trouble if you had different voltages on the stamp pin and the pir pin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • WallydragWallydrag Posts: 16
    edited 2009-12-11 00:13
    Is this better then to accomplish what I want?

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}

    '
    [noparse][[/noparse] I/O Definitions ]

    SYMBOL Trigger = PIN0
    SYMBOL Yes = 1
    SYMBOL No = 0

    '
    [noparse][[/noparse] Initialization ]

    DIRS = %00001110

    '
    [noparse][[/noparse] Program Code ]

    Main:

    IF Trigger = No THEN Main
    IF Trigger = Yes THEN Motor


    Motor:

    HIGH PIN1
    LOW PIN2
    HIGH PIN3

    PAUSE 500

    LOW PIN1
    LOW PIN2
    HIGH PIN3

    PAUSE 5000

    LOW PIN1
    HIGH PIN2
    HIGH PIN3

    PAUSE 500

    LOW PIN1
    LOW PIN2
    HIGH PIN3

    NAP 54000

    GOTO Main
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-11 00:17
    You don't need the "IF Trigger = Yes THEN Motor" because, if the "IF Trigger = No THEN Main" doesn't succeed, the program will just continue to "Motor:". In fact, you don't need the "Motor:" either unless you just want it as a sort of comment.
  • WallydragWallydrag Posts: 16
    edited 2009-12-11 00:37
    Okay, I think I'm getting what you saying but let me just make sure:

    If I have only have "IF Trigger = No THEN Main", then when it checks PIN0 and there's no signal it will just go back to the top of the code and right back to checking again.
    But if it checks PIN0 and there is a signal it would continue down the line of commands.

    Is that right? So cleaned up it should look like this:


    ' {$STAMP BS1}
    ' {$PBASIC 1.0}

    '
    [noparse][[/noparse] I/O Definitions ]

    SYMBOL Trigger = PIN0
    SYMBOL No = 0

    '
    [noparse][[/noparse] Initialization ]

    DIRS = %00001110

    '
    [noparse][[/noparse] Program Code ]

    Main:

    IF Trigger = No THEN Main

    HIGH PIN1
    LOW PIN2
    HIGH PIN3

    PAUSE 500

    LOW PIN1
    LOW PIN2
    HIGH PIN3

    PAUSE 5000

    LOW PIN1
    HIGH PIN2
    HIGH PIN3

    PAUSE 500

    LOW PIN1
    LOW PIN2
    HIGH PIN3

    NAP 54000

    GOTO Main
  • WallydragWallydrag Posts: 16
    edited 2009-12-12 17:21
    I was just thinking, I had set the DIRS to %00001110

    This would make Pins 1,2, and 3 output, aka HIGH, wouldn't it? So whenever I start the program those pins would start outputting a HIGH signal, which I don't want to do until the program tells those pins to.

    So, in actuality, I would really want to set the DIRS to %00000000 wouldn't I?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-12 17:27
    By default, any output pins are set to low. On a reset, all variables are set to zero including DIRS and OUTS. Any explicit LOW or HIGH statement will set its corresponding DIRS bit to one to make the specified pin an output.
  • WallydragWallydrag Posts: 16
    edited 2009-12-12 17:35
    So, really, there's no reason for me to set the pin directions at the beginning of the code at all. I can just omit it and be fine.
Sign In or Register to comment.