mp3 playback module

1968neil

Senior Member
Code:
servo B.6, 75
main:
readadc B.2, b0
b0=b0 *10/17+75 
servopos 1,b0
pause 25
debug
goto main

Try the code above as a real basic test to see if the adc and servo are actually functioing.
Adjustment of the 10k pot should make the servo move in proportion to the wiper position.
Using the debug command also allows you to see the value changes on your pc if you leave the programming lead connected.

Regards
Neil
 

Pat13

Senior Member
Ok, I ran this
Code:
init: servo B.6,75 ; initialise servo
main: servopos B.6,75 ; move servo to one end
pause 2000 ; wait 2 seconds
servopos B.6,225 ; move servo to other end
pause 2000 ; wait 2 seconds
servopos B.6, 150 ; move servo to other end
pause 2000
goto main ; loop back to start
and the servo functions accordingly.
I ran your code, Neil and while I could clearly see that the wiper was giving the appropriate readings, nothing was happening with the servo. I moved the servo pins around (B.7, B.4, B.5) but no response from the servo.
 
Last edited:

1968neil

Senior Member
Code:
servo b.3, 75
main:
readadc C.2, b0
b0=b0 *10/17+75 
servopos b.3,b0
pause 25
debug
goto main
try this, forgot to re-label servopos pin, tried on my set up and works fine.

Regards
Neil
 

Pat13

Senior Member
That works! Servo is responding. So where do I go from here? The problems I'm having must be related to either the soldering of the circuit or incorrect components, namely that 1K pot (incidently the markings on it are "W 102","034C0" and on the face "3302" or "3362") and or the 1N4148 diode. Like a complete newb, I didn't breadboard it before I assembled it. Live and learn.

Fritz, I am using a computer power supply to run everything.
 
Last edited:

1968neil

Senior Member
Just tried the pebble layout thingy, quite inpressive !

1) The busy line on the Tenda needs a 10k pulldown, you have a 330 Ohm
2) for better triggering, id use the attached tried and tested circuit the ADC can be used to drive the servo directly and much more responsive.

3) You WILL need and external amplifier circuit for the tenda module or it will only produce enough output to drive a small pair of headphones.

I'll have a better look tomorrow as i've only just got in from work after a 13hr day mostly driving so im a bit craggy to say the least !

Hope this helps a bit.

Regards
Neil

Audio-ADC.jpg
 

Pat13

Senior Member
Thanks Neil, i'm a bit of a newb when it comes to reading circuits (hence why pebble is so great!) but will do my best to decipher. I too am away for a couple of days on business and will work on this once I get home. What I am building is an animated talking witch. I am including part of the code that I want to use to trigger the Tenda. It does not include the code for driving the servo (talking jaw) or any of the code for the motors that move her arms.
The idea is to have a looped verse while the trigger is being checked. Once triggered, one verse is played, then another, then a random selection of one of the remaining 7 verses.Then a re trigger delay and the loop starts over. I have run it and there are some glitches (not triggering) which may be related to not having a 10K on pulldown on the busy line but are more likely errors in code.
Code:
 'Picaxe 18M2
'PIR Trigger for Witch chants





symbol PIR= B.7      `PIR sensor
symbol TENDA_OUT=B.3 `Tenda RXD  `
symbol VERSE=b6
symbol Debounce=b8
symbol Retrigger_Delay=b9
symbol BAUD=T4800
symbol Wait_If_Busy=pinB.1 `Tenda Busy Line


Init:                                                               'Staring point to setup all inputs, outputs and set variables
 
                                serout TENDA_OUT,BAUD, ($EF);       'STOP MP3 module 
                                pause 500
                                serout TENDA_OUT,BAUD, ($E8)        `set Tenda Volume
                                pause 500
            
                                ;
Start:	
            Do      Loop   Until debounce=10
            Do
            serout TENDA_OUT, Baud, ($01)     `play Track 1
		pause 1000       
		readadc PIR, debounce
		if debounce<1 then exit		     'if PIR Trigger not detected then loop opening mp3 
		pause 1000
		Debounce = Debounce +1 
		if Debounce>9 then Open_Chant	'if triggered go to opening chant
		loop
	
		
Open_chant:
		Gosub Clear_Debounce			'clear Trigger
		 Pause 1000
		 serout TENDA_OUT,BAUD,($02)		'play cackle,Track 2
		 do
		 if Wait_If_Busy=1 then serout TENDA_OUT,BAUD,($03) endif''watch for chant to end,play opening chant Track3
		 if Wait_If_Busy=1 then gosub Spellcast  
		 loop
		 
Spellcast:
		random VERSE						'begin random selection of verses
            VERSE=VERSE//$03-$09				'modulus to generate random mp3
            serout TENDA_OUT,BAUD,(VERSE)
		pause 1000
            do
            if Wait_If_Busy=1 then exit'watch for spellcast to end
            loop
            for Retrigger_Delay=1 to 75
            pause 5000
            next Retrigger_Delay
            goto Start
		
Clear_Debounce:
		Debounce=0
		return
 

1968neil

Senior Member
@ pat13

Just had a look over your code and noticed that you read your PIR using the Readadc command.
This wont work, PIR's use a standard format basically on or off (triggered or not triggerd)

You would be better off using an IF PIR = 1 then xxxxx command
You will need a pull up or pull down depending on the output format of your PIR (Normally closed or Normally Open contacts)
In the meantime you could substitute the PIR with a push button switch to prove things are working correctly.

Alternatively you could use a Sharp infrared distance sensor to detect how close the human is to the prop before triggering ?
This method would probably be better suited to your project if its realism your looking for ?
Using a standard PIR will work ok but youll spend a fair bit of time masking the lens to get a suitable trigger angle/direction IMHO.

Regards
Neil
 

1968neil

Senior Member
Hi Pat,

Try this as an experiment, might simplify what your trying to do.


Code:
Start:	
            
            Do
            serout TENDA_OUT, Baud, ($01)     `play Track 1
		pause 1000       
		if PIR = 1 then Open_Chant	 'if triggered go to opening chant
		gosub Test_Busy_Line          'check busy line before doing anything else
		loop while PIR=0                  'if not triggered sit in this loop
	
Test_Busy_Line:
            Do
            if Wait_If_Busy = 1 then exit
            Loop
            return
I'll have a look at your code further tonight, at work at the moment, this is an addition to what you have but will simplify your own code. Using a subroutine can save lines and lines of code and also noticed that the pir input will need to be changed to pinb.7 rather than just b.7 so the chip sees your using it as an input (not required using adc)

Regards
Neil
 

fritz42_male

Senior Member
Neil, pat's circuit is identical to one created by Halstaff (possible wiring issues excepted) and the use of readadc to sense the pir trigger has proven to be quite reliable and eliminate spurious triggers.

I suspect the issue is either power related or down to a wiring error. On halstaff's version, I believe he ended up using 3 separate power sources after extensive testing.
 
Last edited:

Pat13

Senior Member
Fritz, do you think using a computer power supply (5V rail supplying picaxe, 12V rail supplying tenda) is enough seperation, or should I use a completly different power source? If I have to use a seperate source, I know I have to tie the grounds together. I have gone over my wiring, resoldered what may have been cold solders and have checked for continuity and the circuit checks out. I have re ordered the 1k and 5k trimpots from my local supplier and will ensure they verify these components are the proper ones (we only have one electronic parts supplier in town and they are not always on the ball).
Thanks Neil, will add that into my code and give it a run tonight if I don't get in too late.
 

1968neil

Senior Member
tenda-psu-circuit-diag.jpg@ fritz, wasnt aware of another example, can you link me too it ?

@ Pat, as soon as i view the original article i will be in a better position to advise acordingly.
even so using the switch instead of the pir to test the basic operation would be advisable, start simple and work forward.

The regulator for the tenda i have found to be ideally 9v for reliable operation but 12v shouldnt be a problem, however it should really have a good stable and well decoupled supply.
Pops and crackles on the audio can be eliminated by ac couipling to the amplifier with a non polarised 10uf capacitor at the expense of a little low frequency roll off, this will probably not be an issue as your not expecting a HIFI quality. This issue is well documented in this thread by myself and a few other members.
It may be worth spending an hour or so re-reading the thread thru as other members have experienced similar.

With this in mind the power supply and audio out sections can be put to bed and you can then move on with the knowledge that the problems are not in that section.
Circuit of ideal psu attached.

I may at some point in the near future write up a how to article for this module, as good as it is in use and cost effective it does have a few issues for the inexperienced user.

Regards
Neil
 

fritz42_male

Senior Member
Good idea on the HOWTO - save trawling through this thread (as useful as this thread is).

Halstaff came up with the PIR trigger routine - up until then I'd only used a simple test loop that checked the PIR HIGH 5 times in a loop with a small delay and if all 5 were high then this counted as a true trigger.
 

1968neil

Senior Member
will make a start on the how to over this coming weekend, time permitting.

Managed to find the halstaff thread and for others to view it can be found here,

http://www.picaxeforum.co.uk/showthread.php?19117-PIR-triggering-issues&highlight=Halstaff+pir

@pat13, as i stated in an earlier answer try the simple switch method to prove your circuit before trying the read adc version at least you can find your circuit error before moving on to the next stage. adding the debug command into your code would also allow you to see whats going on with your inputs in real time.

Regards

Neil
 

Pat13

Senior Member
will make a start on the how to over this coming weekend, time permitting.

Managed to find the halstaff thread and for others to view it can be found here,

http://www.picaxeforum.co.uk/showthread.php?19117-PIR-triggering-issues&highlight=Halstaff+pir

@pat13, as i stated in an earlier answer try the simple switch method to prove your circuit before trying the read adc version at least you can find your circuit error before moving on to the next stage. adding the debug command into your code would also allow you to see whats going on with your inputs in real time.

Regards

Neil
Thanks for finding that, immensely helpful.
Where Halstaff was is exactly where I am. Last year, the most I had soldered was guitar cables and now I'm attempting circuits. Steve O helped me to understand the basics of code and I always reference manual 2. I too borrow parts of code. And thru the help of the internet, this forum and online friends, Halstaff being one of them, I'm slowly gaining knowledge and skills. Although, at times it feels painfully slow to me!
 
Last edited:

Pat13

Senior Member
I have been having some problems with the 18M2 http://www.picaxeforum.co.uk/showthread.php?19590-Problems-with-18M2-download/page1 so I haven't been able to really focus on this until now.
I have followed suggestions and placed 0.1uf decoupling caps on both picaxe and tenda. I have placed a 10k pulldown resistor on the Tenda Busy line, and I have hooked up a momentary switch as per page 26 of manual 3 (1K resistor, 10K pulldown resistor). I contacted MDFly about the correct code for the folders and was told ($F2) for folder 2. In root folder is A003 through A009, and in folder 2 is A001 and A002. Once downloaded to freshly formatted (FAT32) SD card, I used Drivesort. I am trying to take advantage of the Tenda's ability to randomly select mp3's from the root directory ($00) Here is my code so far
Code:
'Picaxe 18M2
'Switch Trigger for Witch chants



symbol Trigger=pinB.7 'momentary switch on input B.7
symbol TENDA_OUT=B.3 `Tenda RXD  `
symbol Retrigger_Delay=b9
symbol BAUD=T4800
symbol Wait_If_Busy=pinB.1 `Tenda Busy Line


Init:                                                               'Staring point to setup all inputs, outputs and set variables
 
                                serout TENDA_OUT,BAUD, ($EF);       'STOP MP3 module 
                                pause 500
                                serout TENDA_OUT,BAUD, ($E8)        `set Tenda Volume
                                pause 500
            
                                ;
Start:	
            
            Do
            serout TENDA_OUT, Baud, ($F2,$01)     `play track 1, folder 2
		pause 1000       
		if Trigger=1 then Open_Chant	 'if triggered go to opening chant
		gosub Test_Busy_Line          'check busy line before doing anything else
		loop while Trigger=0                  'if not triggered sit in this loop
	
Test_Busy_Line:
            Do
            if Wait_If_Busy = 1 then exit
            Loop
            return
	
		
Open_chant:
	
		 Pause 1000
		 serout TENDA_OUT,BAUD,($F2,$02)		'play cackle,Track 2, Folder 2
		 do
		 if Wait_If_Busy=1 then gosub Spellcast 'wait unti track ends  
		 loop
		 
Spellcast:					
          				
            serout TENDA_OUT,BAUD,($00) ' use Tenda random play from Root folder to select A003-A009
		pause 1000
            do
            if Wait_If_Busy=1 then exit'watch for spellcast to end
            loop
            for Retrigger_Delay=1 to 75 'wait 90 seconds to retrigger
            pause 5000
            next Retrigger_Delay
            goto Start
What actually plays is A003, and then once complete, it goes to $F2 and loops A001 but it will not respond to the trigger.
 
Top