reed switch

adumas

Member
I'm a newbie and am having problems configuring 2 chips.

I have configured 2 chips (powered by the same 4.5 power supply).

When a reed switch is activated (connected to an 08m chip) an led goes off and then a signal is sent (via a simple wire) to the second chip (18x chip) where another led flashes.

The goal is to see how one chip can interactively talk to another.

If I don't connect the 08m by the wire, the reed switch & led go off fine. When I connect the wire over to the 18x, then the 08m chip will no longer fire - and the 18x doesn't light up.

Do I have the programming or the wiring configured correctly?



PICAXE-08M
.--._.--.
--| 1 8 |--
--| 2 7 |--
--| 3 6 |-- positive to reed switch
--| 4 5 |-- led; output wire to pin 6 of picaxe-18x
`-------'


PICAXE-18X

.---._.---.
--| 1 18 |--
--| 2 17 |--
--| 3 16 |--
--| 4 15 |--
--| 5 14 |--
input wire --| 6 13 |--
--| 7 12 |--
--| 8 11 |--
led --| 9 10 |--
`---------'




**********************************************************************************************
PICAXE-08M Program


b1 = 0

main:

readadc 1, b1
if b1 = 4 then flash
goto main

flash:

high 2
pause 50
low 2
pause 50

b1 = 0

pause 50

goto main

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

PICAXE-18X

b1 = 0

main:

readadc 6, b1
if b1 = 6 then flash
goto main

flash:
high 2
pause 50
low 2
pause 50

goto main



 

MORA99

Senior Member
Have you tried with 2 supplies?
If its batteries, maybe they dont have enough power to run both, I had that problem when running both a tx and rx 433mhz radio module and 2 picaxe off the same 3xAA
 

adumas

Member
Should not be a problem. I have a 12v supply (and have an adjustable power supply / lm317 with caps circuit that converts things down to 4.5)...

But I'll give it a go anyways.
 

Rickharris

Senior Member
Wouldn't it be easier to read the reed switch as a digital input?
<code><pre><font size=2 face='Courier'>
Start:
If pin 1=0 then flash ' you appear to have connected the switch to ground and may need a pull up resistor to ensure the pin goes high when the switch is open.
goto start

flash:
'etc
</font></pre></code>
 

demonicpicaxeguy

Senior Member
effectively your reed switch will float when the contact aren't closed unless pulled either which way by a resistor
and whats probably happening is that it's floating higher when the serial wire isn't connected
 

Tom2000

Senior Member
Also, physical pin 6 of the 18X is an output. You'll need to connect the wire from the 08M to physical pins 1, 18, 17, 16, or 15.

Good luck!

Tom
 

boriz

Senior Member
Adumas.

For future reference, place &quot;[&quot;code&quot;]&quot; at the top of your diagrams (and programs), and place &quot;[&quot;/code&quot;]&quot; at the bottom. (without quotes)

To illustrate.

Without code tags:

+---+
| |
| +---+
+--+ |
| |
+----------+

main:
do
random w0
if b1&gt;127 then
high 2
else
high 3
endif
loop
end


With code tags:
<code><pre><font size=2 face='Courier'>
+---+
| |
| +---+
+--+ |
| |
+----------+

main:
do
random w0
if b1&gt;127 then
high 2
else
high 3
endif
loop
end
</font></pre></code>

Try it :)

Edited by - boriz on 13/06/2007 22:45:54
 

adumas

Member
Thanks for the messages...

I'm going back to the 08m and disconnecting it from the 18x (starting from the top)...

And I'll narrate exactly what I am doing so it might help you all.

I have put one end of the wire from the reed switch to pin 1 and the other to a 10k resistor that goes to ground.

Then I modified my main code to read:

main:
debug
if pin1 = 1 then flash
goto main

If I try to activate the switch, pins = 16 and then dirs = 20 and all of the other values remain 0. And the loop executes indefinately.
 

boriz

Senior Member
&quot; I have put one end of the wire from the reed switch to pin 1 and the other to a 10k resistor that goes to ground.&quot;

By your description. You have the reed switch wired like this?
http://img340.imageshack.us/my.php?image=rd1ah2.gif


IF YES&#8230;

You have misunderstood the nature of PICAXE inputs. Your circuit could work if the PICAXE inputs were current driven, but they are VOLTAGE driven. So you need to provide the input with a specific voltage for each condition you need to detect. In a digital system there are only two voltages that are important: 0v and +v.

When the reed switch is closed, you will read '0' on that input because there is a connection to 0v and nothing else. When the reed is opened, the input will float, with unpredictable results. CMOS inputs have such a tiny input resistance that the inputs will try to adopt the highest nearest voltage. Even if that is the 16,000 volts or -16,000 volts on your finger after you drag your feet on the carpet. Or maybe the few volts it picks up by radio, after all an IC pin is just a very short aerial.

Your reed switch should be wired like this:
http://img507.imageshack.us/my.php?image=rd2ch7.gif

This forces the input to be one voltage or the other. When the reed is open, the input is dragged to 0v by the resistor. When the reed is closed, the input is connected to +v. No chance to float.



IF NO&#8230;

Sorry. I misunderstood.
 

adumas

Member
Thanks much for the reply. So I made sure the circuit is wired as you suggested.

I changed my main loop to be:

main:
if pin1 = 1 then flash
goto main

When I activate the reed switch, my pins = 16 and my dirs = 20. Nothing else changes...
 

adumas

Member
Urgh... Sorry - I reset all of the wires, and now the switch is working... Now I'll get back to interfacing with the 18x...
 

adumas

Member
Ok... Whew... I was about to lose it - everything is now working great...


I modified the code on 08m:

in the flash subroutine I added:
pulsout 2, 200
pause 10
goto main

on the 18x side
I modified the main routine:
if pin1 = 1 then flash
goto main


Sound good?

I appreciate all the input - if there is any other wisdom you would like to pass along, I would appreciate it...
 

boriz

Senior Member
&#8220;wisdom&#8221;? Ok&#8230;



-Never eat a hot soldering iron.

-Your girlfriend/wife is always right. (especially when you are sure she is wrong)

-Always wash behind your ears.

-Never kill a Buddhist monk.

-Always connect transistors the right way round.

-Never drink 3 bottles of wine then cycle home with no lights.

Etc&#8230;

 
Top