Shop OBEX P1 Docs P2 Docs Learn Events
Switch a relay on every 2 seconds — Parallax Forums

Switch a relay on every 2 seconds

dakota77dakota77 Posts: 23
edited 2005-12-12 09:26 in BASIC Stamp
Hello,

I'm using basic stamp to do aerial photography.
I would like to write a little applet to switch a relay on every 2 seconds. (This relay drives a photo camera).

I'm new to Bstamp, I suppose this type of code has already been written.

Could you give me a few advices to write down this code ?

Thanks for your help
Mario


·

Comments

  • JonathanJonathan Posts: 1,023
    edited 2005-12-09 16:11
    Mario,

    Very easy to do. You will need a transistor to switch the realy, and a diode to protect the Stamp from EMF generated by the relay coil.

    You should download a copy of "What's a Microcontroller". It has all the information you will need. The code, if all the Stamp is doing is activating thr camera, would be very simple, pehaps something like this:



    main:
    pause 2000 ' Wait for 2 seconds
    HIGH 0 ' Set this number to whichever Stamp pin is connected to the relay

    GOTO main

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Steve RennellsSteve Rennells Posts: 40
    edited 2005-12-09 16:13
    I think I saw an article in Nuts & Volts about this a few months back. They printed some of the pictures the camera took. I can't remember if any code was listed, tho.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-12-09 16:26
    Jonathan,

    ·· Your code never de-energizes the relay.· It should read:

    Relay  PIN  0
     
    DO
      HIGH Relay
      PAUSE 100
      LOW Relay
      PAUSE 1900
    LOOP
    

    The relay only needs to be energized briefly, then de-energized.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • JonathanJonathan Posts: 1,023
    edited 2005-12-09 16:31
    Chris,

    Ouch! Quite right. *note to self* Do not type without enough coffee! Assuming of course, that I have a brain to be stimulated!

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • dakota77dakota77 Posts: 23
    edited 2005-12-09 17:15
    Hello,

    Thanks for your help.
    The problem is that the Stamp must continuously scan 12 buttons status. These buttons are used to control servos which change camera's position and orientation. So if I use pause the Stamp will stop and will not check events.
    In Visual Basic there is a function ON TIMER. When the selected timer is elapsed, the relay is switched on.
    Thanks again for your help.

    This is the code I use:
    '******************************************************************************************
    svo VAR Byte
    sync CON 255 'Mini SSC sync byte
    pos0 VAR Byte 'Positionnement voulu Watec Byte variable holds position value
    pos1 VAR Byte 'Positionnement voulu Minolta
    pos2 VAR Byte 'Focale Minolta
    poa0 VAR Byte 'Positionnement actuel Watec
    poa1 VAR Byte 'Positionnement actuel Minolta
    poa2 VAR Byte 'Focale actuelle Minolta
    '******************************************************************************************
    n96n CON $40f0
    BtnWrk VAR Byte
    m VAR Byte
    x VAR Byte
    n VAR Byte
    '******************************************************************************************
    svo=0
    'pos0=130:serout 13,n96n,[noparse][[/noparse]sync,0,pos0]
    'pos1=150:serout 13,n96n,[noparse][[/noparse]sync,1,pos1]
    'pos2=100:serout 13,n96n,[noparse][[/noparse]sync,2,pos2]
    DEBUG "d
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-12-09 17:29
    As you may have noticed, pasting your code into messages not only makes it hard to work with, but can be trashed by the font and/or emoticons that get inserted.· There is a formatted code entry window (The pound sign) but you should definately attach it to messages instead.· Anyway, if you added an RTC you could fire the relay in a loop, then when 2 seconds have elapsed you could do it again.· It wouldn't be hard.· Otherwise you can approximate based on cycles through your loop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • dakota77dakota77 Posts: 23
    edited 2005-12-09 18:11
    Chris, sorry for the code and thanks for your reply.
    You have written : "if you added an RTC" : sorry for my ignorance. But what do you mean ?

    Mario
  • Steve RennellsSteve Rennells Posts: 40
    edited 2005-12-09 18:18
    I think Chris is referring to the DS1302 or some variant . . .

    www.parallax.com/detail.asp?product_id=604-00005
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-12-09 18:19
    If you added a Real-Time Clock chip, such as the DS1302 you would have the time available.· Another option would be to simply set up a 555 timer to activate the relay.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • dakota77dakota77 Posts: 23
    edited 2005-12-09 18:35
    I prefer the 555 timer. I will try to find this component here in Belgium.
    Thanks very much for your quick help.
    Mario
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-12-09 19:24
    The sMT co-processor makes a very nice 'tick' generator, and has nice examples on using it to implement PBasic level multi-tasking code. I'm not sure of the current requirements -- I assume they are quite low, as it's implemented on an AVR chip.

    See: http://www.rhombus-tek.com/co-processors.html·for the "Simple Multi-tasking" co-processor.
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-12-09 19:40
    Jonathan said...(trimmed)
    Chris,
    Ouch! Quite right. *note to self* Do not type without enough coffee! Assuming of course, that I have a brain to be stimulated!
    No problem...Happens to me sometimes too...And I don't have lack of coffee to use as an excuse (I don't drink it).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • japerjaper Posts: 105
    edited 2005-12-10 10:23
    hello allanlane5
    thanks for the link sMT co-processor this is just what i am looking for.

    japer
  • dakota77dakota77 Posts: 23
    edited 2005-12-11 07:36
    Hello,

    These photos are taken from a big plane (not rc). I will use 555 timer.

    For relay control no problem. It's already working. When I push a button, the relay is fired.

    What I want to do is that when a button is pressed the Basic Stamp fires the relay every 2 seconds automatically. And stops when the button is pressed again.

    I need the wiring diagram·to connect 555 to Basic Stamp·and sample code.

    I suppose I have to reset the 555 and then check in a loop when the 2 seconds are elapsed.

    Thanks for your help.
  • Robert KubichekRobert Kubichek Posts: 343
    edited 2005-12-11 17:26
    dakota77 said...
    Hello,

    These photos are taken from a big plane (not rc). I will use 555 timer.

    For relay control no problem. It's already working. When I push a button, the relay is fired.

    What I want to do is that when a button is pressed the Basic Stamp fires the relay every 2 seconds automatically. And stops when the button is pressed again.

    I need the wiring diagram to connect 555 to Basic Stamp and sample code.

    I suppose I have to reset the 555 and then check in a loop when the 2 seconds are elapsed.

    Thanks for your help.

    The switch that turns on the power to the 555, can be a simple push on, push off or latcher switch that can also turn on a power led to indicate status....
    The 555 can be set up to output a square wave every 2 seconds as long as the power is on, each time it pulses, it turns on a transistor that in turn controlls a relay....
    It is a very simple circuit, and a search for 555 timers on the net brings up the following links- smile.gif

    www.williamson-labs.com/480_555.htm

    www.uoguelph.ca/~antoon/gadgets/555/555.html

    www.electronics-lab.com/articles/basics/components/555astable.htm

    www.falstad.com/circuit/ex-555.html

    www.interq.or.jp/japan/se-inoue/e_ckt5.htm

    All these links have more than enough info to get you started.... smilewinkgrin.gif

    Bob N9LVU scool.gif

    Post Edited (Robert Kubichek) : 12/11/2005 5:41:43 PM GMT
  • dakota77dakota77 Posts: 23
    edited 2005-12-11 20:26
    Hello Bob,
    Thanks for your reply and very useful links.
    My idea whas to fire the relay with the Bstamp.
    I'd use the 555 only as a chronometer : when I push a button connected to the Bstamp, this one resets the 555 which starts counting. The Bstamp does a loop and checks if the number of cycles corresponding to 2 seconds has exceeded.
    If yes, the bstamp fires the relay and resets the 555 .. and so on.

    But I think my knowledge in electronics is too weak to find out a working solution without spending weeks to search.

    Thanks for your help.
    Mario
  • Robert KubichekRobert Kubichek Posts: 343
    edited 2005-12-11 21:47
    dakota77 said...
    Hello Bob,
    Thanks for your reply and very useful links.
    My idea whas to fire the relay with the Bstamp.
    I'd use the 555 only as a chronometer : when I push a button connected to the Bstamp, this one resets the 555 which starts counting. The Bstamp does a loop and checks if the number of cycles corresponding to 2 seconds has exceeded.
    If yes, the bstamp fires the relay and resets the 555 .. and so on.

    But I think my knowledge in electronics is too weak to find out a working solution without spending weeks to search.

    Thanks for your help.
    Mario

    You can do everything using a stamp, or a LM555 (timer) / LM122 (precision timer, with load trany) standalone.
    Does it have to be exactly every 2 minutes???
    If it does, hook up a rtc to stamp to get accurate timing, or use the LM122 .
    If the timing is not critical, a 555 set up in astable mode will do the job nicely with out the need for a stamp.
    With both timers, the circuit would be very small, with few components. turn.gif

    Bob N9LVU scool.gif
  • dakota77dakota77 Posts: 23
    edited 2005-12-11 22:02
    Hello Bob
    Thanks for your reply.
    In fact the relay will be fired every 2 seconds. But in the future this timing will vary in relation with the aricraft ground speed :
    If the ground speed is 100 kts the relay will be fired every second...
    On board I have an Ipaq wich is connected to a BT gps. It reads the ground speed information and calculates the time between each photo. So I will have to transmit this value (1 sec, 2 sec...) to the Stamp and this one will drive the relay.
    I think that 555 together with Stamp is a good solution. But I don't know how to hook it to the stamp.

    Thanks
    Mario
  • Robert KubichekRobert Kubichek Posts: 343
    edited 2005-12-11 22:45
    dakota77 said...
    Hello Bob
    Thanks for your reply.
    In fact the relay will be fired every 2 seconds. But in the future this timing will vary in relation with the aricraft ground speed :
    If the ground speed is 100 kts the relay will be fired every second...
    On board I have an Ipaq wich is connected to a BT gps. It reads the ground speed information and calculates the time between each photo. So I will have to transmit this value (1 sec, 2 sec...) to the Stamp and this one will drive the relay.
    I think that 555 together with Stamp is a good solution. But I don't know how to hook it to the stamp.

    Thanks
    Mario
    You know that with a GPS unit you can get very accurate timing.
    I would use the GPS unit to set up a counter in the stamp, to count up to the firing interval, then switch the relay to take a picture when that count is reached.
    Typicaly you can get a 1 pps signal from a gps unit.

    Bob N9LVU scool.gif
  • dakota77dakota77 Posts: 23
    edited 2005-12-12 09:26
    Yes it's another good idea.
    1) That means that the Bluetooth gps must be connected together to the stamp and to the Ipaq. Because on this one there is an aeronautical moving map.
    2) For me it's seems complicate to handle the gps sentences with the Bstamp but I have solved this problem with the Ipaq and Nsbasic.
    3) The first step would be to use a simple solution : 555 as a chronograph - time reference connected to one pin of the Bstamp. The Bstamp checks the 555 in a loop. When the delay is exceeded, the Bstamp fires the relay connected to another pin.
    But I don't know how to physically interface the Bstamp and 555.
    Thanks for your suggestions.
    Mario
Sign In or Register to comment.