Vmusic2 cockrill

Rampz

Well-known member
I have been asked if i can add a Cockrill sound to an animated display, always looking for opportunities to use the picaxe's now, it seems the store is out of Vmusic2 modules so i have ordered one from RS, Firstly what the best picaxe to control it with i have the AXE091 board and it came with a 18m2 that i have never used, is it suitable to control the Vmusic2? So far i have only used the 08m2. Is the Vmusic2 they way to go to add a single mp3 to a project? I did see the french part of the forum speak about a Vmusic3?
The cockrill will need to be quite loud so i will need an external amplifier with volume control
Not asking for help just want to discuss options really at the moment
 

AllyCat

Senior Member
Hi,

The Vmusic2 is actually marked as "No longer stocked...." in the PICaxe store, so why are you not considering the alternative PICaxe-14 Audio Project Kit? I've not used the Vmusic2, nor built or tried the newer kit yet, but I did look into constructing it in a compact modular format. I'm also quite a fan of the PAM8403 amplifier modules (with or without a hardware volume control) which have a comparable size and voltage requirement, that can drive one or two larger (8 ohm) loudspeaker(s).

Programming the complete range of PICaxes is basically very similar, with some just having a few additional commands and features. Personally I prefer the 08/14/20M2 family because they have a very similar hardware pinout, such that the smaller chips will fit into the larger sockets (obviously without connections to the additional I/O pins).

Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member
I recall the VMusic2 was fairly easy to control and there should be forum posts related to using it.. I believe it should be usable with any PICAXE but it's been a long time since I have done anything with one.

The datasheet for the product itself is here - https://picaxe.com/docs/usb030.pdf - but doesn't detail use with PICAXE.

These days the AXE171 MP3 Audio Kit is what we would recommend, which includes the SPE035 Budget Serial MP3 Player -

AXE171 - https://picaxe.com/hardware/project-kits/picaxe-14-audio-kit
SPE035 - https://picaxe.com/hardware/add-on-modules/budget-serial-mp3-player-kit
 

Rampz

Well-known member
Thank you Alan and hippy.

Seems i had better get the SPE035 too and play with both, i have seen your article Alan about the AXE171 kit i have printed it out and will refer to it, and have also printed out the pdf's of both items.

Another issue i have been thinking about i see that in some projects some people have used more than one picaxe, is this because they are trying to do things involving multiple inputs and outputs where the code would otherwise wall over itself, as a result of the picaxe only being a single core chip, what i am trying to say is there a rule of thumb of how you decide for a project how many chips is needed to the project?

In this project there will also be several motors to control i guess each in its own sequence with several input aimed at a single output, as if really each motor should have its own picaxe?

Edit Removed mention of a display, something for the future i think

I'm just wanting to get some direction and understand how people go about more complex projects, so far i haven't seen the way the current animated display works and what exactly is involved, but the more i can understand of the thought process the better if that makes sense.

Simon
 
Last edited:

hippy

Technical Support
Staff member
The main reason multiple PICAXE are used is usually because it's easier to have them all running the same simple code than try and have one PICAXE do everything, which often makes things more complicated.

It's generally a case of simplifying the software by using more PICAXE hardware.

For example, if you had a number of motors which were each turned on and off by their own single input, with each motor having a ramp up to full-speed, and ramp down to stop, it would probably be easier to have one PICAXE per motor. That avoids having potentially challenging code which has to handle multiple speed ramps in parallel.
 

AllyCat

Senior Member
Hi,

Yes the number of chips depends on your level of experience and the time available to develop the features of the required program(s) . Personally, I consider to have "failed" if I can't program everything into a single PICaxe of the appropriate size (but I have been programming microcontrollers on and off for 40+ years). :) Also remember that with multiple PICaxes it may be necessary to arrange for them all the communicate with each other, to synchronise their actions.

However, PICaxe Basic is not ideal for building "modular" programs from "Library" Subroutines or Functions. So personally, in my Code Snippets for example, I do try to always use Symbols and a standardised format, for example tempb (b1) and tempw (w1) for "temporary" or "local" variables and to pass parameters between the Program and Subroutine(s), etc..

Adding a (LCD/OLED) character display module is quite a good example: For my AXE171 project proposal linked in #2 above, I was attempting to emulate a Minidisc Player, using the single 14M2, with its I2C Bus and a small OLED display (that I have documented in another thread), but that would be a complex programming task in its entirety. However, the majority of PICaxe users will start with an AXE133{Y} or AXE134{Y} "Intelligent" display module, which actually contains an 18M2 PICaxe with a preloaded Program. That module can be used in much the same way as the Terminal Emulator, but with a limited number of character positions and the <NewLine> (CR , LF) and other actions are not directly supported.

The AXE133/4 gives a standardised interface to add to an existing project, which may be all that most users require, but there are many other possibilities. The (small) program inside the 18M2 could be modified to add other features, or even a complete User Program might be combined with the existing code (but the available number of "spare" pins is quite limited). Alternatively, a standard LCD/OLED display module (without the 18M2), perhaps with an I2C Bus interface, could be used with all the display-control program code incorporated into the User's main program.

Cheers, Alan.
 

Rampz

Well-known member
Thank you hippy and alan, two opposing views, I can see what your saying alan regards getting one larger pic to do the whole job, I will find out what's required for this possible project and break it down into a sequence and try and determine what I think cam happen code wise.
Regards a screen I have ordered a AXE134Y I did see I can program several short phrases and then I assume I can call them at different points in a program, am I limited to the predefined list of phrases or can I define a longer list if required, this display comes with its own picaxe like you say, I assume I can add all its code to the main code if I'm adventurous and not use the attached pic.
I can see other issues if I am using a few picaxe and need them to work as a whole that I will have to connect and output to another input to get several to work together whereas it will be a code issue if all done in a single picaxe
Interesting headaches ahead.
 

Rampz

Well-known member
Ok so the advice was to forget the Vmusic2 and go for the SPE035 as the way forward, i didn end up with both modules, today played with the AXE171, as we do i didn't build the kit up i worked out the connections and plugged the DF module into my AXE091 board to play with, no fun having direct volume buttons when i can try and do it with buttons on the 14m2.

Below is my attempt at code for this and it works really well, after the 10th track there is a lump of noise for a second till it returns to the start, really pleased for my first attempt to code something myself. The instructions were the basis and a developed from there.

Code:
#picaxe 14m2
#no_data
#terminal 4800

Symbol TX = B.4
Symbol RX = C.3
Symbol BUSY_PIN = pinC.2
Symbol BAUD_FREQ = M8
Symbol BAUD = T9600_8
Symbol cmd = b0
Symbol arg = w1 ; b3:b2
Symbol arg.lsb = b2
Symbol arg.msb = b3
Symbol varA = w2
symbol varB = w3
Symbol BTN = PinB.5
Symbol BTN1 = PinB.3
Symbol BTN2 = PinB.2
Symbol Pressed = 1

init:
varB = 8

High TX ; set TX pin high for idle high serial
Pause 2000
SerTxd("Get ready to Rock", CR, LF )

cmd = 0x06 : arg = 08 : Gosub Send    'Volume set at 8 of 30

SerTxd("Selected microSD Card", CR, LF )
cmd = $09 : arg = $0002 : Gosub Send '0001 for usb

cmd = 0x07 : arg = 0000 : Gosub Send ' EQ normal
SerTxd("Equlizer set to normal", CR, LF )

Pause 4000
Gosub playsong


playsong:
    For varA = 1 To 10
    SerTxd("Playing song 000", #varA, CR, LF )
    cmd = $12 : arg = varA : Gosub Send
    Pause 1000
    Do While BUSY_PIN = 0
    Pause 100
    IF BTN = Pressed then
    pause 200  Gosub volumeup
    endif
    IF BTN1 = Pressed then
    pause 200 Gosub volumedown
    endif
    IF BTN2 = Pressed then
    pause 200 Gosub playnext
    endif
    Loop
    next
    Pause 1000
return

Send:
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )
SetFreq MDEFAULT
Return

volumeup:
       varB = VarB + 1
       SerTxd("volume ", #varB, CR, LF )
       cmd = $04 : arg = $0000 : Gosub Send
return

Volumedown:
        varB = VarB - 1
        SerTxd("volume ", #varB, CR, LF )
        cmd = $05 : arg = $0000 : Gosub Send
return

playnext:
       varA = varA + 1
       SerTxd("Playing song 000", #varA, CR, LF )
       cmd = $01 : arg = $0000 : Gosub Send
return

'cmd = 0x08 : arg = 0001 : Gosub Send 'repeatably play song 0001
'cmd = $12 : arg = 0001 : Gosub Send 'play song 0001
Next play to add the 4 line picaxe oled display to act as a terminal, looks like its possible, I do have it to hand, Christmas head scratching ahead

Edit
Thought I would connect it to the house music system, sounds pretty good, after removing some phonos from some old kit.

Just added a USB A socket to the module and altered the initialization from SD card to USB 0002-0001
Loaded 115 song and yep that works great too.
 

Attachments

Last edited:

Rampz

Well-known member
Slight issue, I set up the volume to display its setting in the terminal in the editor, seems you can go down to zero, unfortunatly its possible to go below zero well in my coding anyway, I guess in real it just stays at zero, but my counting carries on meaning it goes out of sync when I then turn the volume up again, somehow i need to get it to stop at zero and in the other direction stop at 30 being the maximum?
 

AllyCat

Senior Member
Hi,

That can be done with the MAX and MIN operators. The MAX is easy, but MIN can be tricky because decrementing from zero wraps to a large positive number (255 or 65535) which isn't caught by the MIN test. The trick is to test the value before decrementing, for example:
Code:
volumeup:
       varB = VarB + 1 MAX 30
;.....
volumedown:
        varB = VarB MIN 1 - 1
;....
Cheers, Alan.
 

lbenson

Senior Member
It's a good trick if you've gotten a PICAXE variable to have a negative value, since in PICAXELAND, 0-1 yields 255 for byte variables, and 65535 for word variables. Of course, how you interpret it makes a difference.
 

Rampz

Well-known member
Hi,

That can be done with the MAX and MIN operators. The MAX is easy, but MIN can be tricky because decrementing from zero wraps to a large positive number (255 or 65535) which isn't caught by the MIN test. The trick is to test the value before decrementing, for example:
Code:
volumeup:
       varB = VarB + 1 MAX 30
;.....
volumedown:
        varB = VarB MIN 1 - 1
;....
Cheers, Alan.
Thank you Alan

I had searched under LET and found MIN and MAX but I tried to make "varB = varB Max 30" on the volume up and the opposite on volume down
It didn't work, I never thought to add them to the end of the line.

Merry Christmas Everyone
 

Rampz

Well-known member
It's a good trick if you've gotten a PICAXE variable to have a negative value, since in PICAXELAND, 0-1 yields 255 for byte variables, and 65535 for word variables. Of course, how you interpret it makes a difference.
Thanks Ibenson, that explains the results I was getting below 0 it was 65535 and decreasing because I am using a word I guess for what I'm doing with volume I could have used a byte with only needing to go 0-30?
 

AllyCat

Senior Member
Hi,

varB = varB Max 30 is a perfectly valid command, but it doesn't include the reqired INCrementing function. It's valid to write the two separate instructions and in fact it's the only way to do it when using the INC and DEC functions (so the +/- 1 operation is more practical):
Code:
INC varB
varB = varB MAX 30
;....
varB = varB MIN 1
DEC varB
;....
Cheers, Alan.
 

Rampz

Well-known member
Ok i thought i would add writing volume setting to eeprom and then recalled at power up, seemed ok on initial program but after power fail, getting strange effects, seems display that volume is at previous setting but when music starts playing its much higher than previous, i tried playing with initial set up by sending volume 0 before it read the eeprom value, which it seems to then do and displays it which is correct, but its way louder than required someting is a miss.
Also it seems to select song 1 then instantly goes and starts at song 2, earlier it did the same while playing with code but went to song 3 instead, maybe the module is a little confused at start up?

code so far

Code:
#picaxe 14m2
#no_data
#terminal 4800

Symbol TX = B.4
Symbol RX = C.3
Symbol BUSY_PIN = pinC.2
Symbol BAUD_FREQ = M8
Symbol BAUD = T9600_8
Symbol cmd = b0
Symbol arg = w1 ; b3:b2
Symbol arg.lsb = b2
Symbol arg.msb = b3
Symbol varA = w2
symbol varB = w3
Symbol BTN = PinB.5
Symbol BTN1 = PinB.3
Symbol BTN2 = PinB.2
Symbol Pressed = 1

init:
varB = 0 'initial volume setting
cmd = 0x06 : arg = varB : Gosub Send
pause 2000

read 0,WORD varB 'added to read previous volume from eeprom position 0




High TX ; set TX pin high for idle high serial
Pause 2000
SerTxd("Get ready to Rock", CR, LF )

cmd = 0x06 : arg = varB : Gosub Send   'Volume set at 8 of 30, altered to read varB
    SerTxd("volume set to", #varB, CR, LF ) 'display volume setting from eeprom hopefully

SerTxd("Selected microSD Card", CR, LF )
cmd = $09 : arg = $0001 : Gosub Send '0001 for usb, 0002 for sd card

cmd = 0x07 : arg = 0002 : Gosub Send ' EQ rock
SerTxd("Equlizer set to rock", CR, LF )

Pause 4000
Gosub playsong


playsong:
    For varA = 1 To 114
    SerTxd("Playing song 000", #varA, CR, LF )
    cmd = $12 : arg = varA : Gosub Send
    Pause 1000
    Do While BUSY_PIN = 0
    Pause 100
    IF BTN = Pressed then
    pause 200  Gosub volumeup
    endif
    IF BTN1 = Pressed then
    pause 200 Gosub volumedown
    endif
    IF BTN2 = Pressed then
    pause 200 Gosub playnext
    endif
    Loop
    next
    Pause 1000
return

Send:
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )
SetFreq MDEFAULT
Return

volumeup:
       varB = VarB + 1 max 30
       write 0,WORD varB 'write value to eeprom positiom 0
       SerTxd("volume ", #varB, CR, LF )
       cmd = $04 : arg = $0000 : Gosub Send
return

Volumedown:
        varB = VarB min 1 - 1
        write 0,WORD varB 'write value to eeprom position 0
        SerTxd("volume ", #varB, CR, LF )
        cmd = $05 : arg = $0000 : Gosub Send
return

playnext:
       varA = varA + 1
       SerTxd("Playing song 000", #varA, CR, LF )
       cmd = $01 : arg = $0000 : Gosub Send
return

'cmd = 0x08 : arg = 0001 : Gosub Send 'repeatably play song 0001
'cmd = $12 : arg = 0001 : Gosub Send 'play song 0001
Edit

just moved

Code:
High TX ; set TX pin high for idle high serial
Pause 2000
SerTxd("Get ready to Rock", CR, LF )
To start of code in case module wasn't ready for settings etc, seems to have sorted selecting the first song, well it did on first try, but volume still coming back as it liked

i would say volume is coming back at maybe 30, when i press the down volume it does go down to zero, but still blasting, i keep pressing the button although display stays at zero the volume keeps decreasing with each press

tried again

I just put volume to 1 in code and uploaded, song 1 started at volume 1, i cycled the power it started again at song 1 but volume 30 no idea why yet
it displayed volume as 1 on the terminal both times, but second time started at full volume

Added more terminal info allways reads back correctly, but the module isn't being set to volume set in "varB" after a cycle of the power

Edit 1

Ok added a 4 second pause at the start and now it works correctly, i guess sending commands when the module isn't ready doesn't work, 1 can maybe reduce that delay a bit, anyone else got any alternatives? But hay it works Yah

Ok volume now works, but after a power fails it goes "playing song 0001" then instantly goes to "playing song 0002" seems strange, if i do a download from editor it starts fine from song 0001, any ideas?

Seems it might be my fault, i had added several commands to the module and looking at the paperwork there is a pause used after every command, so i have added pauses to the code and now it starts as expected and plays first song even after a power cycle, i guess i was confusing the module
 
Last edited:

Rampz

Well-known member
The AXE133/4 gives a standardised interface to add to an existing project, which may be all that most users require, but there are many other possibilities.
Hello Alan

I have got the AXE134Y 4 line oled display with the backpack, i originally thought to use it with the mp3 player, i see there are 12 messages i can preprogram, for volume control as an example will i be able to display current value for volume on a line? i mean can i have a message that has a varible in it? so it can update as i increase or decrease volume
Then there is playback can it show the current track number playing the 0025 for example would be fine ?

So will want to try and write "volume" followed by the value in varB
Or
"Song playing" followed by the value of the counter

Is this possible?

I will build the display up and see if i can get the basics working etc
 
Last edited:

AllyCat

Senior Member
Hi,

The 18M2 (in the AXE134) also has 512 bytes of TABLE memory, so its program could be modified to give up to 36 x 20 character messages. Also, there has been some discussion about extending the interface protocol to allow the Host PICaxe up add to or change the messages. Perhaps an assortment of 16 , 8 and 4 byte messages to give greatest flexibility with 16 and 20 character displays.

However, for this application neither seems appropriate or necessary. Normally, the Host program would just write the message(s) directly to a "normal" AXE134 in much the same way as to the Terminal Emulator. Untested, but for example:
Code:
Symbol AXE134pin = B.3
Symbol VarB = b2                                              ; Volume setting
  SEROUT AXE134pin , N2400_4 , ( 254 , 128 )                  ; Position the cursor (at start of top line)
  SEROUT AXE134pin , N2400_4 , ( "Volume=" , #VarB ," " )     ; Send to AXE134
Note the additional " " at the end of the line, to "delete" a previous second digit, if #VarB is diplayed as a single digit (e.g. 0).

Cheers, Alan.
 

tmfkam

Senior Member
One thing you need to be wary of with these modules is that the "busy" pin can sometimes take a little time to correctly indicate the playing state. For some tracks this can be significantly larger than others. It can also sometimes flag as "playing" momentarily, when in fact, it is still loading (or not).

I discovered that with large numbers of tracks, on large uSD cards the "busy" pin and track load times could be misaligned by an order of seconds, more so on high numbered tracks. I found that polling the busy pin a number of times and waiting for a number of consecutive affirmative (or negative) replies was the only reliable way of determining whether a track had loaded, and was indeed playing.

Saying all of that, I think these are superb modules, and have used them in multiple designs for my work and for myself, including a small mp3 jukebox which had 9999 tracks set to play in random sequence that ran 24hrs a day for over two years non stop.
 

Rampz

Well-known member
Ok i have it working thank you Alan for your input, but stuggling to find the rest of the commands to write to the other lines, i can see 254,128 writes to the first line, whereas 254,192 writes to the second line i think, i can't find www.picaxe.com/docs/led008.pdf which i understand should tell me commands to write to line 3 and 4?

Edit

I have worked it out, noting that the lines don't follow down 1,2,3,4 and its more like 1,3,2,4 or something so i added 128+20 took the volume message to the start of the 3rd line, then adding a few more took it to the centre of the 3rd line
 
Last edited:

Rampz

Well-known member
Thank you neiltechspec, in the end i came to that conclusion, just wondering if i want to write a message longer than 20 letters can it wrap around so a longer message can be displayed? Just a thought.
Really happy what can be done with an oled display, great I can send messages other than the 12 that are pre saved in the backpack.
 

Attachments

Rampz

Well-known member
I found that polling the busy pin a number of times and waiting for a number of consecutive affirmative (or negative) replies was the only reliable way of determining whether a track had loaded, and was indeed playing.
Hello tmfkam, thank you for your input, wondering how you went about doing this regards coding for the module, I had weird effect while programming, maybe due to what you describe
 

erco

Senior Member
I've used the Catalex MP3 modules in many Picaxe projects. Cheap and widely available, but it does need an amplifier & speaker added.

 

Rampz

Well-known member
I've used the Catalex MP3 modules in many Picaxe projects. Cheap and widely available, but it does need an amplifier & speaker added.

Thank you Erco, I will find one to play with, do you have an example of code and connections?
I do like the DFplayer mini because a USB can be added, I like that a user could change the music easily, I would normally look to use an external amp.
 

erco

Senior Member
See my article at https://servo.texterity.com/servo/201710/MobilePagedReplica.action?pm=2&folio=9#pg9 and

Best to view those in incognito mode since they limit views.

Edit: the user manual at http://geekmatic.in.ua/pdf/Catalex_MP3_board.pdf says the module uses MP3 and WAV files, but at least 2 of the cheap (possibly knockoffs) modules I used would only play MP3 files off the uSD card, not WAV. Easy enough to convert using https://online-audio-converter.com/ or equivalent.
 
Last edited:

Rampz

Well-known member
After using my set up for a few days, updating code from time to time, cycling power to try the code, often leaving the dfplayer on zero volume so it can carry on playing to make sure its reliable etc, display was showing tack 114, last track I have after which it loops, I found this morning it stuck on song 114 none of the buttons linked to the picaxe 18m2 armed to work, display didn't change with button press and no music, can only conclude picaxe had stopped or crashed or something, cycling power sorted it.
Anyone had similar issues? Anyone have experience of picaxe's running for several years? Any ideas or extra code I should add to stop it happening, only happen this once
 

hippy

Technical Support
Staff member
Anyone have experience of picaxe's running for several years?
There was a PICAXE up in space for a year or more and there was an adventure to see how long a PICAXE could keep flashing a LED until the batteries ran down that ran for a number of years.

Things can sometimes stop working if there is a power glitch but it is most likely an issue with the code, not catching some odd or unexpected behaviour with external hardware.

That it stopped on the last track seems significant. It could be that the hardware does something peculiar so the PICAXE code is waiting for something which isn't happening, or it has gone off to do something which has it stuck in a loop or unable to complete. Adding SERTXD commands throughout the code helps track where things have got to which helps identify where the problem is, and hopefully why, what's causing that.
 

Rampz

Well-known member
Far more likely to be a software issue than a hardware issue--at least a PICAXE hardware issue. How about posting your full current code.
Code:
#picaxe 14m2
#no_data
#terminal 4800

Symbol TX = B.4
Symbol RX = C.3
Symbol BUSY_PIN = pinC.2
Symbol BAUD_FREQ = M8
Symbol BAUD = T9600_8
Symbol cmd = b0
Symbol arg = w1 ; b3:b2
Symbol arg.lsb = b2
Symbol arg.msb = b3
Symbol varA = w2
symbol varB = w3
Symbol BTN = PinB.5 'volume up
Symbol BTN1 = PinB.3 'volume down
Symbol BTN2 = PinB.2 'next song
Symbol AXE134pin = C.1 'connected to screen input
Symbol Pressed = 1

init:


High TX ; set TX pin high for idle high serial
SerTxd("Get ready to Rock", CR, LF )
Pause 2000



'varB = 8 'initial volume setting
'cmd = 0x06 : arg = varB : Gosub Send
'SerTxd("init volume set to ", #varB, CR, LF ) ' added to display its value at this time
'pause 2000 ' added pause to see if it helped

read 0,WORD varB 'added to read previous volume from eeprom position 0
'SerTxd("eeprom volume set to ", #varB, CR, LF )

         SEROUT AXE134pin , N2400_4 , ( 254 , 128 ); Position the cursor (at start of top line)128 top line
             SEROUT AXE134pin , N2400_4 , ( "Programming by Rampz")     ; Send to AXE134

SerTxd("Selected USB", CR, LF )
cmd = $09 : arg = $0001 : Gosub Send '0001 for usb, 0002 for sd card
pause 4000

cmd = 0x07 : arg = 0002 : Gosub Send ' EQ rock
SerTxd("Equlizer set to rock", CR, LF )
pause 1000

         SEROUT AXE134pin , N2400_4 , ( 254 , 192 ); Position the cursor (at start of top line)128 top line
             SEROUT AXE134pin , N2400_4 , ( "Equ to Rock, Set USB")     ; Send to AXE134

cmd = 0x06 : arg = varB : Gosub Send   'Volume set at 8 of 30, altered to read varB
    SerTxd("volume set to ", #varB, CR, LF ) 'display volume setting from eeprom hopefully
  
      SEROUT AXE134pin , N2400_4 , ( 254 , 154 ); Position the cursor (at start of top line)128 top line
        SEROUT AXE134pin , N2400_4 , ( "Volume=" , #VarB ," " )     ; Send to AXE134

Pause 1000
Gosub playsong


playsong:
    For varA = 1 To 114  
    SerTxd("Playing song 000", #varA, CR, LF )
  
      SEROUT AXE134pin , N2400_4 , ( 254 , 215 ); Position the cursor (at start of top line)128 top line
        SEROUT AXE134pin , N2400_4 , ( "Playing Song " , #VarA ,"  " )     ; Send to AXE134
  
    cmd = $12 : arg = varA : Gosub Send
    Pause 1000
    Do While BUSY_PIN = 0
    Pause 100
    IF BTN = Pressed then
    pause 200  Gosub volumeup
    endif
    IF BTN1 = Pressed then
    pause 200 Gosub volumedown
    endif
    IF BTN2 = Pressed then
    pause 200 Gosub playnext
    endif
    Loop
    next
    Pause 1000
return

Send:
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )
SetFreq MDEFAULT
Return

volumeup:
       varB = VarB + 1 max 30
       write 0,WORD varB 'write value to eeprom positiom 0
          SEROUT AXE134pin , N2400_4 , ( 254 , 154 ) ; Position the cursor (at start of top line)128 top line
            SEROUT AXE134pin , N2400_4 , ( "Volume=" , #VarB ," " )     ; Send to AXE134
       SerTxd("volume ", #varB, CR, LF )
       cmd = $04 : arg = $0000 : Gosub Send
return

Volumedown:
        varB = VarB min 1 - 1
        write 0,WORD varB 'write value to eeprom position 0
           SEROUT AXE134pin , N2400_4 , ( 254 , 154 ); Position the cursor (at start of top line)128 top line
             SEROUT AXE134pin , N2400_4 , ( "Volume=" , #VarB ," " )     ; Send to AXE134
        SerTxd("volume ", #varB, CR, LF )
        cmd = $05 : arg = $0000 : Gosub Send
return

playnext:
       varA = varA + 1
     
       SEROUT AXE134pin , N2400_4 , ( 254 , 215 ); Position the cursor (at start of top line)128 top line
         SEROUT AXE134pin , N2400_4 , ( "Playing Song " , #VarA ," " )     ; Send to AXE134
    
       SerTxd("Playing song 000", #varA, CR, LF )
       cmd = $01 : arg = $0000 : Gosub Send
return

'cmd = 0x08 : arg = 0001 : Gosub Send 'repeatably play song 0001
'cmd = $12 : arg = 0001 : Gosub Send 'play song 0001
Sorry its a bit of a mess its slightly better looking in the editor, its ran though all songs several times without problem, the picaxe is plugged into the AXE development board, power from the supplied plug in mains adaptor
 

lbenson

Senior Member
Anyone have experience of picaxe's running for several years?
Here's the thread on the 08M which ran for over 11 years on the same 3 AA batteries: low-power reference design

As I recall, papaof2 has had a picaxe running for even longer as a water detector in his daughter's basement entranceway.

Also, I have had multiple picaxes running for years as temperature sensors, powered from USB ports on little linux-running routers.
 
Last edited:

lbenson

Senior Member
To me, after a brief glance, this looks like your problem:
Code:
Gosub playsong

playsong:
  For varA = 1 To 114
    . . .
  next
  Pause 1000
  return
After the FOR loop finishes and returns, you drop into playsong, and if that finishes, you RETURN again--to where? Maybe try:

do: Gosub playsong: loop
 
Last edited:

Rampz

Well-known member
Thank You Ibenson, i have ammended code and will let it run through for a while, Another thing that happens, i have a button to skip to next track and often it will skip 2 songs not 1, code for that bit below

Code:
IF BTN2 = Pressed then
    pause 200
    Gosub playnext
    endif
I don't think its contact bounce, altering the pause doesn't seem to help much, sometimes when the power is cycled it will do them same at the start, will go to song 1 then instantly go to song 2

I wonder if the post from Tmfkam has any bearing on the issue
One thing you need to be wary of with these modules is that the "busy" pin can sometimes take a little time to correctly indicate the playing state. For some tracks this can be significantly larger than others. It can also sometimes flag as "playing" momentarily, when in fact, it is still loading (or not).
 
Last edited:

papaof2

Senior Member
Here's the thread on the 08M which ran for over 11 years on the same 3 AA batteries: low-power reference design

As I recall, papaof2 has had a picaxe running for even longer as a water detector in his daughter's basement entranceway.

Also, I have had multiple picaxes running for years as temperature sensors, powered from USB ports on little linux-running routers.
I've had an 08 running since 2006 to control a fan in an A/V cabinet (everything was moved to a new cabinet in 2016 but the only PICAXE change was to the temperature limits). The PICAXE reads a DS18B20 and turns the fan ON if the temperature is above 100F (38C) or turns it OFF if the temperature is below 97F (36C). No power switch, just the wall wart plugged into a port on the UPS so the PICAXE runs continuously. The only indicator is a green LED that lights when reading the DS18B20 and does a double flash when between the ON and OFF temperatures - the "waiting" indicator.
 

lbenson

Senior Member
i have a button to skip to next track and often it will skip 2 songs not 1
One thing to try is to not proceed after detecting a button press until you also see a release:
Code:
IF BTN2 = Pressed then
  do until BTN2 <> Pressed: loop  ' ,-- add this
    pause 200
    Gosub playnext
    endif
 

Rampz

Well-known member
do until BTN2 <> Pressed: loop ' ,-- add this
I just tried the extra line, it still moves on 1 or 2 songs when the button is released, but also now you can't hold the button down to skip through several tracks as before.
Guess its not so much related to the button press as the module not showing busy correctly and skipping to the next track or something?
 

lbenson

Senior Member
Maybe a logic analyzer would help solve this problem. Or maybe even an LED indicator on the BUSY signal.
 

Rampz

Well-known member
Maybe a logic analyzer would help solve this problem
Thanks Ibenson, i would have no idea where to start with that sort of thing.

What i am thinking is happening, when i push BTN2 and Gosub "playnext" the command gets sent to the player and instantly returns to the main code, where either the button is still pressed or its in the debounce pause maybe, so anyway i have added a pause 500 after the command is sent in Gosub "playnext" on the idea it would give me time to get my finger off the button when i have realised the track has changed. It seems to work quite well, although holding BTN2 down means it skips through many tracks rather slowly, but its ok
Code:
playnext:
       varA = varA + 1
      
       SEROUT AXE134pin , N2400_4 , ( 254 , 215 ); Position the cursor (at start of top line)128 top line
         SEROUT AXE134pin , N2400_4 , ( "Playing Song " , #VarA ," " )     ; Send to AXE134
     
       SerTxd("Playing song 000", #varA, CR, LF )
       cmd = $01 : arg = $0000 : Gosub Send
       pause 500 ;;;;; added to stop double song issue, but slowed skipping songs down
return
The other issue i was having was after a power fail often it would all come back on and go to song 1 then instantly song 2 and start from there, i increased the delay at start up and that seems to be much more reliable too
 
Last edited:

tmfkam

Senior Member
Hello tmfkam, thank you for your input, wondering how you went about doing this regards coding for the module, I had weird effect while programming, maybe due to what you describe
It's taken me a while to locate this code snippet as I've been away from my 'PC'. Bear in mind that not long after I started building my mp3 jukebox, I switched to use a compiled basic, this code was written for that and would need adjusting for PicAxe BASIC.

Code:
'
'Don't be tempted to change this! If the delays here are not long enough
'all manner of odd effects occur. Change at the risk of losing more hair!



'Initially, the 'Busy' flag shows as playing, even if no track is found,
'equally, it sometimes takes a moment or two to load the actual track.
'The idea is to count how long the busy flag has remained at either
'"Play" or "Stop" and only count consecutive states.

    Let Blink = 0
    Do
       If PlayerBusy = Busy_Play Then
          Let Blink = Blink + 1
          Wait 10 mS  'If track playing, assume it will continue to play
          Locate 0, 14
          LCDWriteChar(6)
       Else
          Let Blink = Blink - 1
          Wait 100 mS 'Wait longer for tracks that are slow to load
          Locate 0, 14
          LCDWriteChar(7)
       End If
    Loop Until Blink = 127
    Let Blink = 0
    'This loop gives a delay of either 1.27 seconds (Track playing)
    'or 12.7 seconds if not playing (assuming constantly play or stop)
My later code sets a variable delay time, based on the number of the track (high numbered tracks took longer to load) this proved a little more reliable.

Code:
    Let Wait_Time = Wait_Time + 95 'Can't be more than 95
                                   'if we're at track 9999 we could
                                   'be passed a value of 156.
                                   '156 + 95 = 251 , any more
                                   'and we'll overflow

    'Minimum Time Delay for stopped tracks is 95 mS * 127 = 12 seconds

    Let Blink = 0
    Do
       If PlayerBusy = Busy_Play Then
          Let Blink = Blink + 1
          Wait 8 mS  'If track playing, assume it will continue to play
          Locate 0, 14
          LCDWriteChar(6)
       Else
          Let Blink = Blink - 1
          Wait Wait_Time mS 'Wait for a little longer if not playing
          Locate 0, 14
          LCDWriteChar(7)
       End If
    Loop Until Blink = 127
    Let Blink = 0
    'This loop gives a delay of either 1 second (playing) or a delay
    'that varies depending on the Wait_Time variable passed in the
    'parameters (not playing) with a minimum of 12.7 seconds

    'It is important that this is set to a minimum value or no tracks
    'will ever be played.
 

Rampz

Well-known member
Another thought i notice while listening to recorded music some tracks are recorded louder than others, has anyone looked at ways to automatically adjust volume to try and keep the output level about the same? Or maybe data can be added to the track to specify volume, or maybe there is something else on the mp3 player that can be adjusted, just my thoughts
 

AllyCat

Senior Member
Hi,

The MP3 file format is quite complex so you probably need to use an "App" of some kind. The most common "free" software is "Audacity", but I haven't used it much myself, and couldn't see an "Automatic Gain Control" mode as such. Personally, I've used a freeware program called "MP3DirectCut" for many, many (20+) years which does have an option to : Edit > Normalise , that quickly sets the peak amplitude to just below clipping (or any other value you select). Only for MP3 files and I recall it may need a few other software resources to be installed, but IMHO worth a try if you find Audacity too overwhelming.

Or of course you could create a simple PICaxe lookup table to relate a volume control level to each track.

Cheers, Alan.
 
Top