I'm not sure if this will work.

Pat13

Senior Member
So I thought I would ask the Picaxe gurus before I hook everything up and perhaps fry something.
I want one 18M2 to tell another 18M2 when to run code. I think this can be accomplished by connecting an output pin from one 18M2 to an input pin on the other
18M2. The pin on the first picaxe will go high, the second picaxe will look for the it's input to =1 and then run code.
I have read through a number of threads trying to find an answer to this. I realize that by using the serin/serout commands that this can be accomplished, however I am not familiar enough with serial protocols to write the code for that (note that I did use serout commands in first code, but only because those commands where clearly laid out in the MDFly datasheet and in the thread on Tenda modules on this forum). Here is the (abbreviated) code for the controlling Picaxe, Symbol Brunny_Fly =C.2 is the command.
Code:
'#18M2 Witch scene

symbol Aggie = B.0 'MDFly 1 RX
symbol Gertie = B.2 'MDFly 2 RX
symbol Aggie_BZ = pinB.1 'MDFly 1 Busy
symbol Gertie_BZ =pinB.3 'MDFly 2 busy

symbol Cauldron = B.4 'MDFLY 3 RX
symbol Cauldron_BZ = pinB.5 'MDFly 3 RX

symbol Thunder = B.6'MDFly 4 RX
symbol Thunder_BZ = pinB.7 'MDFly 4 Busy
symbol Brunny_Fly = C.2

symbol Baud =T4800 'tenda baud Rate
symbol Trigger =C.1 'trigger, probably PIR
symbol debounce = b5
symbol Retriggertime = w5


Start0:
	
	Retriggertime = 120
		
	Init:	
		high Aggie 'prepare MDFly 1
		pause 400
		high Gertie 'prepare MDFly 2
		pause 400
		pause 400			
		serout Aggie,Baud,($EF) 'stop MDFly 1
		serout Gertie, Baud, ($EF)'stop MDFly 2
		serout Thunder, Baud, ($EF) 'stop MDFly 4
		pause 6000			'wait 10 seconds
		serout Aggie, Baud, ($E8) 'set MDFly 1 volume
		serout Gertie, Baud, ($E8) 'set MDFly 2 volume
		serout Thunder, Baud, ($E8) 'set MDFly 4 volume
		pause 60000	 'wait 1 minute 

	Waiting:
		debounce = 0
		Do
		let w0 = time
		random w0
		If debounce > 50 then 
			goto Happy_Halloween
		pause 3000
		Endif
		readadc Trigger, debounce
		loop while debounce < 50
			


	Happy_Halloween:
			serout Aggie, Baud, ($F2,09)
			pause 2000
			do while Aggie_BZ = 0
			loop
			
			serout Aggie,Baud,($F2,01)
			serout Gertie,Baud, ($F2,01)
			pause 2000
			do while Aggie_BZ = 0
			loop
			
			serout Gertie, Baud, ($F2,02)
			pause 2000
			do while Gertie_BZ = 0
			loop
			
			serout Aggie, Baud, ($F2,03)
			pause 2000
			do while Aggie_BZ = 0
			loop
			
			serout Gertie, Baud, ($F2,04)
			pause 2000
			do while Gertie_BZ = 0
			loop
			
			
			serout Aggie, Baud, ($F2,05)
			pause 2000
			do while Aggie_BZ = 0
			loop
			
			serout Thunder, Baud, ($01)
			pause 2000
			do while Thunder_BZ = 0
			loop
			
			serout Aggie, Baud, ($F2,06)
			pause 2000
			do while Aggie_BZ = 0
			loop
			
			serout Gertie, Baud, ($F2,06)
			pause 2000
			do while Gertie_BZ = 0
			loop
			
			serout Aggie, Baud, ($F2,07)
			pause 2000
			do while Aggie_BZ = 0
			loop
			
			high Brunny_Fly  'send high to second picaxe input
			serout Thunder, Baud, ($01)
			serout Aggie, Baud, ($F2,10)
			serout Gertie, Baud, ($F2, 08)
			pause 2000
			do while Aggie_BZ = 0
			loop
			goto Spellcast
Here is the code for the controlled Picaxe.

Code:
'#18M2 Flying witch 
symbol Up_Away = B.3
symbol Side2Side = B.4
symbol FX = B.5
symbol Trigger = pinC.1



Start0:


		Waiting: 
			do
			let w7 = time
			random w7
			if Trigger = 1 then  'if pin on first picaxe goes high, run program
				goto Flying
			endif
			loop
		Flying:
                	High Up_Away
               	random w7
                	w8=w7//1000 + 5000 'random ON time between 1 and 5 seconds
                	pause w8
                	Low Up_Away
                	random w7
                	w8=w7//1000 + 3000 'random OFF time between 1 and 5 seconds
		pause w8
		High Up_Away
                	random w7
                	w8=w7//1000 + 5000 'random ON time between 1 and 5 seconds
                	pause w8
                	Low Up_Away
                	random w7
                	w8=w7//1000 + 3000 'random OFF time between 1 and 5 seconds
		pause w8
		High Up_Away
               	random w7
                	w8=w7//1000 + 3000 'random ON time between 1 and 5 seconds
                	pause w8
                	Low Up_Away
			goto Waiting
Start1:
		Waiting1:
			do
			let w3 =time
			random w3
			if Trigger = 1 then 'if pin on first picaxe goes high, run program
				goto Swoop
			endif
			loop

            Swoop:
                	High Side2Side
                	random w3
                	w4=w3//1000 + 5000 'random ON time between 1 and 5 seconds
                	pause w4
                	Low Side2Side
                	random w3
                	w4=w3//1000 + 3000 'random OFF time between 1 and 5 seconds
		pause w4
	              High Side2Side
                	random w3
                	w4=w3//1000 + 5000 'random ON time between 1 and 5 seconds
                	pause w4
                	Low Side2Side
                	random w3
                	w4=w3//1000 + 3000 'random OFF time between 1 and 5 seconds
		pause w4
		High Side2Side
                	random w3
                	w4=w3//1000 + 3000 'random ON time between 1 and 5 seconds
                	pause w4
                	Low Side2Side
                	goto Waiting1
Start2:
		Waiting2:
			do
			if Trigger = 1 then 'if pin on first picaxe goes high, run program
				goto Shock_Awe
			endif
			loop
	      Shock_Awe: 
                	High FX
               	Pause 14000
               	Low FX
               	goto Waiting2
thanks in advance for your input.
 

Jamster

Senior Member
Are those technical names for the MDfly modules? ;)

The only thing I would note circuit wise is that you should include a resistor between the chips to prevent surges/damage to the pins.

In the first code you set the Brunny_Fly pin high, but never set it low again... is this intentional?

Think that's all but I'm likey to be proved wrong, I always miss something... :)

Jamster
 

Pat13

Senior Member
Are those technical names for the MDfly modules? ;)

The only thing I would note circuit wise is that you should include a resistor between the chips to prevent surges/damage to the pins.

In the first code you set the Brunny_Fly pin high, but never set it low again... is this intentional?

Think that's all but I'm likey to be proved wrong, I always miss something... :)

Jamster
Thanks Jamster, nice catch on not setting the pin low again. I would be standing there wondering why this prop won't stop, LOL! I thought I might need a resistor, would 10K be too much?
 

premelec

Senior Member
10K unnecessarily high - it's just to limit over current mistakes - 330 to 1000 more appropriate...
 

John West

Senior Member
For a moment there I thought Regina was in California. I must be one of those "Ugly Americans" I'm always reading about who thinks the world revolves around the USA. :)
 

Pat13

Senior Member
So continuing on with this build. I am going to use a CHI030 to control the Flying Witch. She will have: one 12VDC Vent motor for her side to side head movement, two 12VDC pneumatic solenoids to control the Up_Away and Side2Side air cylinders, a hacked power bar with a 12V relay to control FX (strobe light, fog machine) and LED eyes. I want the head movement to be random so have used modulus to generate random pause times. I also want the eyes to stay on but to strobe when triggered. I am encountering a syntax error during the "Strobe_Eyes" section ("if FX = 0 then"). I'm not sure how to write this out. The "Triggered" event should last around 14 seconds. Should I nix the "do/loop" in Strobe_Eyes and put high, pause , low pause until I get roughly 14 seconds? Also, should I have diodes across the terminals on the CHI030 for the solenoids and motor (already have them on the relays)?
Here is the code
Code:
'#18M2 Flying witch 
symbol Up_Away = B.3
symbol Side2Side = B.4
symbol FX = B.5
symbol Head= B.0
symbol Eyes = B.1
symbol Trigger = pinC.1



Start0:


		Waiting: 
			do			'do/loop
			let w7 = time
			random w7		
			let w1 = time
			random w1
			High Eyes		'turn LED eyes on
			high Head		'turn vent motor on
			w2=w1//3000+ 10000
			pause w2		'random "on" time for vent motor
			low Head
			w2=w1//3000+10000
			pause w2		'random "off" time for vent motor
			if Trigger = 1 then	'if C.1 detects high go to next section of code
				goto Flying
			endif
			loop
		Flying:
			High Head 'turn head on and leave it on until "goto Waiting"
                	High Up_Away
               	random w7
                	w8=w7//1000 + 5000 'random ON time between 1 and 5 seconds
                	pause w8
                	Low Up_Away
                	random w7
                	w8=w7//1000 + 3000 'random OFF time between 1 and 5 seconds
		    	pause w8
		     	High Up_Away
                	random w7
                	w8=w7//1000 + 5000 'random ON time between 1 and 5 seconds
                	pause w8
                	Low Up_Away
                	random w7
                	w8=w7//1000 + 3000 'random OFF time between 1 and 5 seconds
		    	pause w8
		    	High Up_Away
               	random w7
                	w8=w7//1000 + 3000 'random ON time between 1 and 5 seconds
                	pause w8
                	Low Up_Away
                	Low Head
			goto Waiting
Start1:
		Waiting1:
			do
			let w3 =time
			random w3
			if Trigger = 1 then
				goto Swoop
			endif
			loop

            Swoop:
                	High Side2Side
                	random w3
                	w4=w3//1000 + 5000 'random ON time between 1 and 5 seconds
                	pause w4
                	Low Side2Side
                	random w3
                	w4=w3//1000 + 3000 'random OFF time between 1 and 5 seconds
		    	pause w4
			High Side2Side
                	random w3
                	w4=w3//1000 + 5000 'random ON time between 1 and 5 seconds
                	pause w4
                	Low Side2Side
                	random w3
                	w4=w3//1000 + 3000 'random OFF time between 1 and 5 seconds
		    	pause w4
		    	High Side2Side
                	random w3
                	w4=w3//1000 + 3000 'random ON time between 1 and 5 seconds
                	pause w4
                	Low Side2Side
                	goto Waiting1
Start2:
		Waiting2:
			do
			if Trigger = 1 then
				goto Strobe_eyes
			endif
			loop
		Strobe_Eyes:
			do
			high Eyes
			pause 500
			low Eyes
			pause 60
			if FX = 0 then
				goto Waiting2
			endif
			loop
Start3:
		Waiting3:
			do
			if Trigger = 1 then
				goto Shock_Awe
			endif
			loop
	      Shock_Awe: 
                	High FX
               	Pause 14000
               	Low FX
               	goto Waiting3
Thanks in advance
 

hippy

Technical Support
Staff member
I am encountering a syntax error during the "Strobe_Eyes" section ("if FX = 0 then"). I'm not sure how to write this out.
FX is defined as a pin (B.5) so to read the FX input you will need something like -

If pinB.5 = 0 Then

And you could name pinB.5 as a symbol such as -

Symbol pinFX = pinB.5

If pinFX = 0 Then
 

mrburnette

Senior Member
<...>The only thing I would note circuit wise is that you should include a resistor between the chips to prevent surges/damage to the pins.
For PICAXE to PICAXE pins tied as Output to Input, the DC input impedance (resistance) for the CMOS input without the weak-pullups active is (from PIC datasheet) is around 5nA. The sink/source capability of a PICAXE is 20mA or greater. The election to use a "safety" resistor in this situation is purely optional. I would recommend it for beginners and intermediates working with breadboards because it is easy to short something as one plays. But, in any final design, I would avoid it because the R and any stray C will cause a signal skew at higher frequencies. Added to the trace inductance of a printed circuit board and the RLC "could" become an issue. By keeping R out of the equation (except for the low value associated with the pc board trace) there is far less chance of any issues.

- Ray
 

inglewoodpete

Senior Member
...I would recommend it for beginners and intermediates working with breadboards because it is easy to short something as one plays. ..
Ray, I assume you mean wiring errors: it's not matter of accidental short circuits. The real risk when getting two microcontrollers communicating is accidentally setting both pins as outputs. Any multi-chip system under development, regardless of the experience level of the developer, runs the risk of code being downloaded to the wrong controller or data sent out the wrong pin. PICAXEs are cheap but waiting for a replacement is really frustrating. I use a 330 ohm resistor whenever I have two PICAXEs intercommunicating. It's a rare PICAXE that gets used in a production environment.
 

mrburnette

Senior Member
Ray, I assume you mean wiring errors: it's not matter of accidental short circuits. The real risk when getting two microcontrollers communicating is accidentally setting both pins as outputs. Any multi-chip system under development, regardless of the experience level of the developer, runs the risk of code being downloaded to the wrong controller or data sent out the wrong pin. PICAXEs are cheap but waiting for a replacement is really frustrating. I use a 330 ohm resistor whenever I have two PICAXEs intercommunicating. It's a rare PICAXE that gets used in a production environment.
Yep... I was discussing wiring errors. I guess you can throw in programming errors into that too, but honestly if a "seasoned" PICAXER blew the Input/Output buffer(s) because of a download programming error, I think they would be best to keep such instances to themselves and count the small cost of chip replacement as a vital part of their continuing-education expense.

When I prototype multiple chips, I do 'em one-at-a-time and I double-check the input/output registers multiple times... on a breadboard with a logic jumper or DMM or depending on the circuit with my O-scope. The code is working at least in PIN functions prior to connecting two chips... or more.

I agree that the 330 resistor is good practice on a breadboard during prototyping sessions. I do not agree it is good design for a final circuit if there is sufficiently high data rates between the two chips.

PICAXEs are cheap but waiting for a replacement is really frustrating.
Even retired and on a fixed income, I manage to keep at least two of any PICAXE in the parts drawer. But, I work only with a very limited set of chips: 08M2, 14/18M2, 20X2. If I were working into the higher pin count and more costly chip$, maybe I would always use those 330 Ohm resistors. :eek:

I stand by my original statement:
But, in any final design, I would avoid it because the R and any stray C will cause a signal skew at higher frequencies.
If one is working at a few KHz, no big deal (usually!) I have the test equipment in my lab to model such concerns, but for those that do not, my recommendation is to become competent with any of the widely available (free) SPICE programs that can model digital/analog signal degredation.

I did not mention it, but at very high digital frequencies, one should consider the weak-pullup on the input gate or perhaps an external pullup to condition the leading/trailing edges of the digital waveforms by enforcing a known steady-state current through the chip interconnection.

- Ray


CMOS Output-2-Input.jpg
SPICE Simulation link: SPICE
Code:
$ 0 5.0E-6 382.76258214399064 99 5.0 50
f 160 176 224 176 1 1.5
f 160 272 224 272 0 1.5
w 224 192 224 224 0
w 224 224 224 256 0
w 160 176 160 224 0
w 160 224 160 272 0
R 224 160 224 112 0 0 40.0 5.0 0.0 0.0 0.5
g 224 288 224 320 0
g 528 288 528 320 0
R 528 160 528 112 0 0 40.0 5.0 0.0 0.0 0.5
M 528 224 592 224 0 2.5
w 464 224 464 272 0
w 464 176 464 224 0
w 528 224 528 256 0
w 528 192 528 224 0
f 464 272 528 272 0 1.5
f 464 176 528 176 1 1.5
R 160 224 80 224 0 2 10000.0 5.0 5.0 0.0 0.5
w 224 224 240 224 0
w 464 224 448 224 0
r 320 224 384 224 0 330.0
c 384 224 384 160 0 1.0E-11 -0.007168783868073625
c 384 224 384 288 0 1.0E-11 4.992831216131926
g 384 288 384 320 0
R 384 160 384 112 0 0 40.0 5.0 0.0 0.0 0.5
c 320 224 320 160 0 1.0E-11 -4.2203372153259977E-4
c 320 224 320 288 0 1.0E-11 4.999577966278467
R 320 160 320 112 0 0 40.0 5.0 0.0 0.0 0.5
g 320 288 320 320 0
l 240 224 320 224 0 5.0E-12 2.9408015589371672E-5
l 384 224 448 224 0 5.0E-12 4.0874421902703517E-10
x 18 426 453 432 0 24 Top :: Input Gate  Bottom :: Output Gate
x 178 228 218 234 0 24 Out
x 473 227 493 233 0 24 In
o 19 64 0 34 8.183476519740355 9.765625000000001E-155 0 -1
o 18 64 0 35 8.749002899132048 1.7087896287367282E-4 0 -1
Note/Disclaimer: Simulations are rarely accurate when doing a What-If analysis; actual lab measurements should be performed to back-up the SPICE simulation and provide real world results. However, SPICE approximations are a good starting point to experiment and understand potential issues and then use this knowledge to formulate a true test plan for the bench circuit.
 
Last edited:
Top