Trigger a Picaxe 14m2 From another picaxe 14m2

curtis_1966

New Member
As the title says, how could I achieve this.

1st chip is connected to a pir, when 1st chip is triggered, trigger 2nd picaxe. Don't want 2nd chip connected to PIR at all.

Thank You For Your Help In Advance.
 

lbenson

Senior Member
Raise a pin high in picaxe #1 when the pir is triggered; monitor low-to-high transition in picaxe #2 (and for possible repeats, high-to-low). Put 1K resistor in-line between the picaxes to prevent damage if one pin is brought low while the connected pin on the other picaxe is brought high.
 

curtis_1966

New Member
Oh wow, I'm so new to this not much in programming skills here. This is what I have to Detect Pir on first 14m2 chip.

Code:
#Picaxe 14M2

symbol TENDA=C.0
symbol PIR_IN=pinB.5
symbol PIR_COUNT=b5

TESTIT:
 
	 Do : Loop Until PIR_IN=1		'PIR debounce code
                
                Do
                PIR_COUNT = PIR_COUNT + 1 * PIR_IN
                Loop Until PIR_COUNT = 10
                PIR_COUNT = 0
                
	goto Routine
Now I want to relay that signal to a separate 14m2 board but not connected to the pir.
 

lbenson

Senior Member
Once you determine that you have a valid triggering of the PIR, you can bring another line high (for instance, "high b.4")--perhaps for long enough for the 2nd picaxe to pick up the signal, maybe with, say, "pause 1000").

Then with the 2nd picaxe, you watch for that line to go high, with something like "if pinc.3 = 1 then ... ". You'll probably need to note when that pin goes low again so you don't re-trigger from the original signal. What is the second picaxe doing?
 

curtis_1966

New Member
2nd chip is just retriggering when connected to pir.

2nd chip code is as follows.

Code:
main:
	if pinB.5=0 then
		setfreq m16					;is the type of movement input low?
		MovementType=0				;yes, set the index to start of table
		low EyesOutput				;and set Eyes output to low (off)
		Temp_LSB=7					;and do all 7 movement types
	else
	setfreq m4
	pause 500	
	serout TENDA,4800, (01)                           'Play MP3
	pause 500	
	servo B.2,210                                               'turn head
	servopos B.2,210
	for b16=1 to 5                                             'delay for mp3
	pause 1000
	next b16	
	servopos B.2,130                                             'turn head
	pause 500
	setfreq m16
		
		MovementType=HeadDataSize		;no, set the index to start of second data table
		High EyesOutput				;and set Eyes output to High (on)
		Temp_LSB=5					;Don't do LookAt or NodNo
	endif
	
	Random Random_Word				;get next random number
	
	Temp_LSB=Random_MSB * Temp_LSB /256;		;get a random from 0 to 4 or 0 to 6
	if LastCommand = Temp_LSB then Main		;get another command if repeating the last one.

	On Temp_LSB gosub LookHome,LookFarLeft,LookNearLeft,LookFarRight,LookNearRight,LookAt,NodNo

	Goto Main
As you can tell my problem is not to have a delay in that routine, well not a long one at least.
 

lbenson

Senior Member
Since your main loop in the second picaxe can be more than 2 seconds long (in the "else" clause, pause 500, pause 500, pause 1000), then you either need to hold your triggering pin high for longer than that in the picaxe1 program, or if you need instantaneous response, use an interrupt in picaxe2.

If you feel you need an interrupt, read about the setint command in Manual 2 (several times--it's tricky). When using interrupts, it's best to make sure you are seeing the signals correctly with test code and "polling" before you try the interrupts. Trying to debug what turns out to be a hardware error when you are using interrupts can be maddening.
 

Dartmoor

Member
When I have wait delays in the loop (eg your 'picaxe2') and I want to read inputs that can change quickly, then I make use of the multiple program slots (or whatever the correct term is).
ie you can have several 'main loops' running in (virtual) parallel. On the 14m2 I think it is 3 or 4 loops available.
One loop has the delays in it and another loop just keeps whizzing round reading all the inputs.
The interrupt will work, but you are limited to a max of 1 interrupt!
I am a newbie too, so I could be wrong!
 

hippy

Technical Support
Staff member
One trick for a PICAXE signalling another is, not to pulse an output, but to toggle that output. The receiving PICAXE can then simply look for a change of state from earlier.

That's not a magical solution to all timing issues but it can alleviate a lot of them.
 

curtis_1966

New Member
Thanks guys for all your input, I'm getting a little deep now. I'll read up on your suggestions.

When 2nd chip hooked up to the PIR, it constantly interrupts the low state head turn and the else part of the routine (which is the high state). What kind of difference is there between the PIR signal and a PICAXE signal? The first Chip will control all timing, I just want to interrupt that low state part which seems like its scanning the pin b.5 an waiting for it to go high.

Once again, I appreciate all your help.
Curtis
 

curtis_1966

New Member
thanks guys for all your help, decided to just rewrite the code to accommodate a pir hooked to both boards no biggie just not what I had planned. Once again ty all for you help.
 
Top