18M2 Tenda Issues

Pat13

Senior Member
Hello all
I'm hoping someone can enlighten me as to what I am missing in this code. The idea for the code is that the 18M2 tells the Tenda to randomly select an mp3 from Folder 1. It then waits for an input (within a do/loop). If it receives an input, it selects the first mp3 from Folder 2, as well as sending an output high to a slave 18M2, which begins its routine. If it does not receive an input when the mp3 is finished (input pin monitors when Tenda Busy pin goes high inactive) it will randomly select another mp3 from folder 1. Once the routine has begun, it will do more of the same, waiting for an input and when received, selecting the next mp3 from folder 2 and sending output high to various slaves. I am using a purpose built pcb, with direct connection via traces to between the 18M32 and the Tenda board. All grounds are connected. I have ensured continuity between all appropriate contacts.
It is getting some of it right! When input is received, it is sending a high output, telling a slave to begin its routine. But as far as the Tenda goes, its not behaving as I intended. It is not selecting an mp3 UNTIL it gets an input. It won't advance beyond that initial selection. I have tried other Tendas and am getting the same results, yet they function properly in other pcbs.
Here is the code
Code:
'#18M2 Supreme Overlord
symbol Witches_SX= B.0		'Output to Witches 18M2 RX pin
symbol Witches_RX = pinB.1	'Input From Witches 18M2 SX pin
symbol Craven_SX= B.2		'Output to Raven 18M2 RX pin
symbol Craven_RX= pinB.3	'Input from Raven !8M2 SX pin
symbol Tenda_BZ = pinB.4 	'Input from Tenda Busy pin
symbol Tenda = B.5		'Output to Tenda RX pin
symbol Yardhaunt_SX = B.6	'Output to Yard props 18M2 RX pin
symbol Yardhaunt_RX = pinB.7	'Input from Yard props 18M2 SX pin



symbol Baud = T4800 		'Tenda Baud rate
symbol Countdown = w5

	Init:				'intialise pins, turing outputs low and prepping Tenda
		low Yardhaunt_SX
		pause 400
		low Witches_SX
		pause 400
		low Craven_SX
		pause 400
		high Tenda		'high command to B.5
		pause 1000
		serout Tenda, Baud, ($EF)	'stop Tenda
		pause 5000
		serout Tenda, Baud, ($E8)	'turn up Tenda volume
		pause 5000
		
		goto Waiting
		
		Waiting:	'do/loop waiting for input from Witch Overlord
			high Tenda	'
			pause 200
			
			serout Tenda, Baud, ($000) 'randomly select ambient music
			
			pause 2000
			
			Do
			
				let Witches_RX = 0
				If Witches_RX = 1 then 
					goto Happy_Halloween	'if input is high go to routine	
				elseif Tenda_BZ = 1 then
					goto Waiting		'if mp3 finishes with no input, randomly select mp3
				pause 1000
				Endif
			loop while Witches_RX = 0
		
		Happy_Halloween:	'Opening routine
		
			high Yardhaunt_SX 
			high Tenda  'send yard overlord command to begin its routine
			serout Tenda, Baud, ($F2,01) 'play music for this routine
			pause 4000
			low Yardhaunt_SX	
			
			Do
				let Witches_RX = 0
				If Witches_RX = 1 then 
					goto Flying		'if input is high go to routine
				pause 1000
				Endif
			loop while Witches_RX = 0
		
		Flying:
		
			high Yardhaunt_SX
			high Tenda
			serout Tenda, Baud, ($F2,02)
			pause 4000
			low Yardhaunt_SX
			do while Tenda_BZ = 0
			loop
		
		Graveyard:	'beginning of Graveyard routine
			high Tenda
			serout Tenda, Baud, ($F2,03)
			Countdown = 45
			do 
				Countdown = Countdown - 1
				pause 1000
			loop
			
			do while Tenda_BZ = 0
			loop
			
		
		Craven_Crania:
		
			high Craven_SX
			serout Tenda, Baud, ($F2,04)
			pause 4000
			low Craven_SX
			
		Do
				let Craven_RX = 0
				If Craven_RX = 1 then 
					goto Graveyard_2	'if input is high go to routine
				pause 1000
				Endif
			loop while Craven_RX = 0
			
		Graveyard_2: 'the second run of the Graveyard props, timed to music

			high Tenda
			high Witches_SX
			high Yardhaunt_SX
			serout Tenda, Baud, ($F2,05)
			
			pause 2000
			low Witches_SX
			low Yardhaunt_SX
			
			Countdown = 45
			do 
				Countdown = Countdown - 1
				pause 1000
			loop
			
			do while Tenda_BZ = 0
			loop
	Second_Act:

			high Tenda
			serout Tenda, Baud, ($F2,06)
			high Witches_SX
			pause 2000
			low Witches_SX
			Do
				pause 1000
				let Witches_RX = 0
				If Witches_RX = 1 then 
					goto Flying_2	
				Endif
			loop while Witches_RX = 0

	Flying_2:	
	
			high Tenda
			serout Tenda, Baud, ($F2,02)						'Gargoyles breath fiery smoke while Brunswick the witch flies about
			pause 3000
			do while Tenda_BZ = 0
			loop
			
			goto Waiting
I have a similar code that is working, in fact this one is based on that code. I can post that as well.
Any help greatly appreciated
 

Technical

Technical Support
Staff member
This probably doesn't do what you want / work as you expect - try to switch an input pin to 'low' then try and read it again (which won't work)?

let Witches_RX = 0
If Witches_RX = 1 then


Also all your 'high Tenda' lines are not required, simply have one right at the start of the program.
 

Jeff Haas

Senior Member
Why are you doing this in several places?

Code:
		Waiting:	'do/loop waiting for input from Witch Overlord
			high Tenda	'
My experience with the Tenda boards is after initializing them and setting the volume, you don't have to tell them anything until you want them to play a file. Then just send the serout command.
 

BESQUEUT

Senior Member
I'm hoping someone can enlighten me as to what I am missing in this code...
I am equally lost in your code... Maybe you can make it more readable and "structured".
As Pointed by Technical, somes lines probably doesn't do what you expect.
Example :
goto Waiting
Waiting:

The goto Waiting doesn't make sense.

let Witches_RX = 0
If Witches_RX = 1 then
goto Flying 'if input is high go to routine
pause 1000
Endif

The pause 1000 will never been executed...
 
Last edited:

Pat13

Senior Member
Thanks to everyone for your speedy response. I will try to answer as best I can. Bear in mind that I am a hobbyist, a Halloween prop builder, who uses Picaxe within that hobby. My code writing is at best rudimentary.
This probably doesn't do what you want / work as you expect - try to switch an input pin to 'low' then try and read it again (which won't work)?

let Witches_RX = 0
If Witches_RX = 1 then


Also all your 'high Tenda' lines are not required, simply have one right at the start of the program.
Actually that does seem to work. I have used it successfully in another code. As soon as Witches_RX goes high, the code jumps to the appropriate section. The problem seems to be specifically with the Tenda. However, I will remove it from the code.

Why are you doing this in several places?

Code:
		Waiting:	'do/loop waiting for input from Witch Overlord
			high Tenda	'
My experience with the Tenda boards is after initializing them and setting the volume, you don't have to tell them anything until you want them to play a file. Then just send the serout command.
In the first few drafts of the code, I did not include those "high Tenda" statements, it was only in the "Init:" portion. As I became more frustrated, I was trying to find a way to "force the issue", as it were. I have used a version of this code with great success in my other props. Why it is not working in this version is perplexing to me. I tried the code in another piece of hardware that is functioning properly and it seems to work. I believe I have a hardware issue, but I can't seem to pinpoint what it is. I have checked the continuity across the entire board and have found no obvious issues. There is pin to pin continuity where there should be, and no continuity where there shouldn't.
I am equally lost in your code... Maybe you can make it more readable and "structured".
As Pointed by Technical, somes lines probably doesn't do what you expect.
Example :
goto Waiting
Waiting:

The goto Waiting doesn't make sense.

let Witches_RX = 0
If Witches_RX = 1 then
goto Flying 'if input is high go to routine
pause 1000
Endif

The pause 1000 will never been executed...
As I stated above, I am a hobbyist, a Halloween prop builder who stumbled upon Picaxe a few years ago and realised that it could do what the expensive prop controllers could do, at a fraction of the cost. I am not a programmer, or an IT tech. Simply a guy trying to build cool stuff to entertain kids on Halloween. My code writing was non existent until a few years ago and is now rudimentary at best.
Again, "goto Waiting" was not in the original drafts of the code. I was trying to find a way to get the serout portion to be executed. After further experimentation last night I believe I have a hardware issue. I flashed a picaxe in an identical board and the serout portion executed. I just can't figure out what the hardware problem is. My power source is good, an ATX power supply, with a steady 5VDC and 12VDC and plenty of amps. Continuity checks out, all grounds are connected. And none of the pins have continuity with 5VDC, 12VDC or ground.Perplexed :(
 

hippy

Technical Support
Staff member
I tried the code in another piece of hardware that is functioning properly and it seems to work. I believe I have a hardware issue, but I can't seem to pinpoint what it is.
It might be worth posting a circuit diagram and a photo of your hardware.
 

BESQUEUT

Senior Member
I do not want to criticize your code. I only said that making an effort to structure it will make it more readable for you, and for us.
Also no command will be executed after a goto if no label is present.
Mistake or not : we don't known (and this is not our problem...)
We only point that this code will probably not do what you expect.
I have a similar code that is working, in fact this one is based on that code. I can post that as well.
That's a good idea : publish working and not working code.

Maybe you can temporary replace the
serout Tenda
by
sertxd
to verify the sended command.

I tried the code in another piece of hardware that is functioning properly and it seems to work
Why seems ? Does it work or not ?
 
Last edited:

Pat13

Senior Member
Just to illustrate, here is the first version, more or less, of this code I wrote to control my two witches. (I added a couple of lines to reflect what I want to achieve this year, tried to highlight those in red, but post wouldn't save it). It is bulky, cumbersome and the furthest thing from elegance, but it works.
As well, I removed all the Spellcast portion of the code, as it was too many characters for this post. And it is redundant. But as you can see, the whole code is redundant!

I have also included a Youtube video from my haunt last year. The Witches appear at 00:16. The cauldron splash and cackle is the beginning of Happy_Halloween.

https://www.youtube.com/watch?v=dDOTNKdayQ0
Code:
'#18M2 Witch Scene. 18M2 controls all of the folders/mp3s three MDFly boards, sends and receives logic high to and from CHI030 board that controls yard animatronics, sends logic high to 5vdc relays to turn on/off spotlights and sends logic high to two CHI030 boards that control flying witch

symbol Gertie = B.0         'MDFly 1 RX line (pin 15)
symbol Gertie_BZ =pinB.1     'MDFly 1 busy line (pin 13)
symbol Aggie = B.2         'MDFly 2 RX line (pin 15)
symbol Aggie_BZ = pinB.3     'MDFly 2 Busy line (pin 13)


symbol Thunder = B.5        'MDFly 3 RX line (pin 15)
symbol Thunder_BZ = pinB.4    'MDFly 3 Busy line (pin 13)
symbol Brunny_Fly = C.7

symbol Baud =T4800         'tenda baud Rate
symbol Trigger =pinC.2         'trigger, momentary switch 5VDC high active
symbol Retriggertime = w5      'delay before scene can be retriggered
symbol Aggie_Light = C.1    'Logic high sent to relay to turn on spotlight
symbol Gertie_Light = C.0    'Logic high sent to relay to turn on spotlight

symbol Witches_SX = B.6
symbol Witches_RX =pinB.7
Start0:
    
    Retriggertime = 60
        
    Init:                'Initialize active pins by first turning them off and then turning them on
        low Aggie_Light
        pause 400
        low Gertie_Light
        pause 400
        low Brunny_Fly
        pause 400
        low Witches_SX
        pause 400
        high Gertie             'prepare MDFly 1
        pause 400
        high Aggie                 'prepare MDFly 2
        pause 400
        high Thunder             'prepare MDFly 3
        pause 400            
        serout Aggie,Baud,($EF)     'stop MDFly 1
        serout Gertie, Baud, ($EF)    'stop MDFly 2
        serout Thunder, Baud, ($EF)     'stop MDFly 3
        pause 6000                    'wait 6 seconds
        serout Gertie, Baud, ($E8)     'set MDFly 1 volume
        serout Aggie, Baud, ($E8)     'set MDFly 2 volume
        serout Thunder, Baud, ($E8)     'set MDFly 3 volume
        pause 10000                 'wait 20 seconds 

    Waiting:                    'Wait for Trigger to start routines
        
        Low Witches_SX
        Do
        let Trigger = 0            'set Trigger as low
        let w0 = time
        random w0
        If Trigger = 1 then 
            goto Happy_Halloween    'if switch is pressed go to routine
        pause 1000
        Endif
        loop while Trigger = 0
            


    Happy_Halloween:                    'this begins the routine with a cauldron splash and cackling
            high Witches_SX
            pause 100
            serout Aggie, Baud, ($F2,09)        'all mp3s for this routine are in folder2 on both MDFlys    
            serout Gertie, Baud, ($F2,10)
            Do                        'strobe the two witch spots while the opening mp3 plays
            high Aggie_Light
            low Gertie_Light
            pause 100
            low Aggie_Light 
            high Gertie_Light
            pause 100
            loop while Aggie_BZ= 0
            
           [COLOR=#ff0000] low Witches_SX[/COLOR]
            high Aggie_Light            'turn on Aggie's spotlight
            high Gertie_Light            'turn on Gertie's spotlight
            serout Aggie,Baud,($F2,01)    'the first chant begins. The witches say this together
            pause 375                'this delay is used to sync the two tracks
            serout Gertie,Baud, ($F2,01)
            pause 2000
            do while Gertie_BZ = 0        'keeps looping while MDFly 1 is low active
            loop
            
            low Aggie_Light            'turns off Aggie's spot,leaving Gertie's spot on
            serout Gertie, Baud, ($F2,02)
            pause 2000
            do while Gertie_BZ = 0
            loop
            
            low Gertie_Light
            high Aggie_Light
            serout Aggie, Baud, ($F2,03)
            pause 2000
            do while Aggie_BZ = 0
            loop
            
            low Aggie_Light
            high Gertie_Light
            serout Gertie, Baud, ($F2,04)
            pause 2000
            do while Gertie_BZ = 0
            loop
            
            low Gertie_Light
            high Aggie_Light
            serout Aggie, Baud, ($F2,05)
            pause 2000
            do while Aggie_BZ = 0
            loop
            
            low Gertie_Light
            Low Aggie_Light
            serout Thunder, Baud, ($01)    'thunder crack for dramatic effect. Uses a color organ
            pause 2000                
            do while Thunder_BZ = 0
            loop
            
            high Aggie_Light
            serout Aggie, Baud, ($F2,06)
            pause 2000
            do while Aggie_BZ = 0
            loop
            
            low Aggie_Light
            high Gertie_Light
            serout Gertie, Baud, ($F2,07)
            pause 2000
            do while Gertie_BZ = 0
            loop
            
            low Gertie_Light
            high Aggie_Light
            serout Aggie, Baud, ($F2,08)
            pause 2000
            do while Aggie_BZ = 0
            loop
            
            high Witches_SX
            low Gertie_Light
            Low Aggie_Light
            high Thunder
            pause 300
            high Brunny_Fly            'sends logic high to trigger inputs on two Picaxe CHI030 boards.These control air solenoids 
                                '(among other things)for a flying witch
            serout Thunder, Baud, ($01)
            serout Aggie, Baud, ($F2,10)
            serout Gertie, Baud, ($F2, 09)
            pause 1000
            low Witches_SX
            low Brunny_Fly
            
            pause 21000
            
            serout Thunder, Baud, ($01)    'thunder crack for dramatic effect. Uses a color organ
            
            pause 21000
            
            serout Thunder, Baud, ($01)    'thunder crack for dramatic effect. Uses a color organ

            pause 21000
            
            serout Thunder, Baud, ($01)    'thunder crack for dramatic effect. Uses a color organ
        
        
            Do
                let Witches_RX = 0            'set Trigger as low
                If Witches_RX = 1 then 
                    goto Thunderclap    'if switch is pressed go to routine
                pause 1000
                Endif
                loop while Witches_RX = 0
        
        Thunderclap:
        
            pause 5000
        
            serout Thunder, Baud, ($01)    'thunder crack for dramatic effect. Uses a color organ
            pause 15000                
            
            serout Thunder, Baud, ($01)    'thunder crack for dramatic effect. Uses a color organ
            pause 15000                
            
            serout Thunder, Baud, ($01)    'thunder crack for dramatic effect. Uses a color organ
            pause 11000    
            
            serout Thunder, Baud, ($01)
            
            
            Do
                let Witches_RX = 0            'set Trigger as low
                If Witches_RX = 1 then 
                    goto Spellcast    'if switch is pressed go to routine
                pause 1000
                Endif
                loop while Witches_RX = 0
                                    
                                    
        Spellcast:                'randomly selects one of six chants.Chant mp3s are stored folders.  Routine calls up folder,then mp3
        
            
            let b2=w0//7+1
            if b2=1 then 
                goto Its_Halloween
            elseif b2=2 then 
                goto Tonight
            elseif b2=3 then 
                goto Early_Early
            elseif b2=4 then 
                goto MacBeth
            elseif b2=5 then
                goto Kindle
            elseif b2=6 then
                goto Riders
        
            endif
 
Top