Switch a relay on every 2 seconds
dakota77
Posts: 23
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
·
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
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
·· 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
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
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 Savage
Parallax Tech Support
csavage@parallax.com
You have written : "if you added an RTC" : sorry for my ignorance. But what do you mean ?
Mario
www.parallax.com/detail.asp?product_id=604-00005
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Thanks very much for your quick help.
Mario
See: http://www.rhombus-tek.com/co-processors.html·for the "Simple Multi-tasking" co-processor.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
thanks for the link sMT co-processor this is just what i am looking for.
japer
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-
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....
Bob N9LVU
Post Edited (Robert Kubichek) : 12/11/2005 5:41:43 PM GMT
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.
Bob N9LVU
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
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
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