Yes, I believe it uses '1st', '2nd', '3rd' etc for finding folders and files and the numeric naming of things matters not one jot if the folders and files aren't added to the file system in the right order, if Drive Sort hasn't reordered them to be in numeric order.From what i remember there was an indexing issue with the FAT which meant you'd have to use Drive Sort or the card read wouldn't always work correctly.
Thanks for the confirmation.I have always used the MP3 and 0001.mp3 format without a problem. Im sure this was a work around at the time.
I like that idea, but I don't know how to implement that at this stage, would love to learn more, the idea of a LED to show which is active at the time I think is rather important.Totally do-able as 1968neil says. I would say it falls into the category of "what a PICAXE is perfect for".
You can have a 5 x 4 button matrix or larger which is easy enough with the right PICAXE and you could even hack a PS/2 keyboard. Then you just need to scan for a button push or wait for a key press, play the track and ignore any new pushes until it has finished.
If it's a button matrix I believe that can also be used to light a LED in the button or next to it so it's more obvious which the track is for. It's a slightly more complicated matrix but might well be worth the effort.
It was easier and quicker to do that at the time than find a version of Drive Sort for Windows 10.
The TP4056 input voltage is 4-8v which may need some careful consideration when choosing a solar panel as the voltages vary wildly.I am still waiting for the DFPlayers to arrive, it takes so long to get from overseas and I haven't been able to find them locally. (South Australia)
While waiting, I have thought of another project to try and I think I can work it out, but to make sure I thought I should pose the questions here.
This is a simple project using just a 08M2, a DFPlayer, a lithium 3.6v battery, an LDR, and a solar cell and a cheap balance charger TP4056 for charging the battery.
The idea is to have the battery charged by the solar cell to power everything. The LDR to determine night or day because I don't want this working at night. The DFPlayer to play a single file of birds calling.
What I am not sure about is the length of an MP3 file that can be played and also how to get the file to repeat after playing.
The idea behind this project is to have some bird calls playing in the garden but only during the daytime.
The length of the file I have is about 1 hour in length.
#no_data ; Optional to speed downloading program modifications
setfreq m8 ; increase frequecy
#terminal 9600
hsersetup B9600_16,%10
pause 2000 ; Recommended to give the terminal time to start up
Symbol Busy_Pin = PinC.1
Symbol Busy_Delay = 200
Symbol TX = B.4
Symbol BAUD_FREQ = M8
Symbol BAUD = T9600_8
Symbol LDR = C.2
Symbol cmd = b0
Symbol arg = w1 ; b3:b2
Symbol arg.lsb = b2
Symbol arg.msb = b3
;XL = $08 : YW = $01 ; repeat play FAT file number 01 (valid 01...255)
start:
readadc LDR,b10 ; read LDR for night or day into variable b0
if b10 > 105 then Day
if b10 < 95 then nighttime
if b10 > 96 and b0 < 104 then waiting
goto done
Day:
SerTxd("DAYTIME birds are singing", CR, LF )
High TX ; set TX pin high for idle high serial
Pause 500
SerTxd("Play MP3 folder song 0001.mp3", CR, LF )
cmd = $08 : arg = 0001 : Gosub Send ;$12 play tracks from the default \MP3 folder - 0001 = track 1 $08 repeat track
Pause 500
sleep 1500 ; put 08M2 in sleep mode for about 1 hour
goto start
nighttime:
SerTxd("NIGHTTIME birds are sleeping", CR, LF )
check:
readadc LDR,b10 ; read LDR for night or day into variable b0
if b10 > 105 then Day
;sleep 3000
goto check
Send:
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )
gosub Check_Busy
SetFreq MDEFAULT
Return
Check_Busy:
Do
pause Busy_Delay
loop while Busy_Pin=0
Return
waiting:
wait 6
done:
goto start
I have a dog that would welcome any cat to venture inThe only issue i see might be from the "Green" perspective in that by playing bird calls during the daytime you may attract a lot of cats and that may have its own problems
The SLEEP and NAP commands are not guaranteed to be particularly accurate, have -50%/+100% tolerance and that can vary with temperature.. The nominal SLEEP unit is 2.3 seconds so SLEEP 1500 should be about an hour.then put the 08M2 to sleep for about an hour by using sleep 1500, is that correct?
I am very lucky in that way, I have a cochlear implant and I remove the processor at night and don't hear anything, it is good too if the wife starts to nag too much.I'm actually in the unenviable position of wanting to get rid of real life birdsong since this year has attracted some critter who emits a fine "badda-bing-badda-boom' at four in the morning which is impossible to ignore once you have latched on to it after being woken by it.
Using '$08' does seem to be correct looking at SPE035.PDF.What I am not sure about is if I have got the repeat code right.
I don't think you need to split the track if it works. You should be able to set the track repeating forever, PAUSE or SLEEP for a shorter period of time, check the LDR, sleep again, or issue a '$16' stop command., reissue a '$08' repeat command when you want theMaybe I should split the MP3 file up into smaller pieces and play them as separate files and that way I can check the day or night better so as not to have an extended play into the evening by using a long playing file that might start just before dusk?
MainLoop:
Do
Gosub WaitForDawn
Gosub SetVolumeToFull
Gosub PlayTrackWithRepeat
Gosub WaitForDusk
Gosub FadeDownVolume
Gosub StopTrack
Loop
WaitForDawn:
Do
Pause 1000
ReadAdc LDR, b0
Loop Until b0 > 105
Return
WaitForDusk:
Do
Pause 1000
ReadAdc LDR, b0
Loop Until b0 < 95
Return
Thanks once again Hippy, you have my grey matter working overtime, can't get old while in this state of mind.Rather than jumping to 'start' and deciding what to do I would have something more akin to a 'state machine' where you simply progress through doing things, let various subroutines check LDR and return or not. Perhaps something like -
; *******************************
; Written by:
; Function:
; Target PICAXE:
; *******************************
#picaxe 08m2 ; Optional for verification
#no_data ; Optional to speed downloading program modifications
setfreq m8 ; increase frequecy
#terminal 9600
hsersetup B9600_16,%10
pause 2000 ; Recommended to give the terminal time to start up
Symbol Busy_Pin = PinC.1
Symbol Busy_Delay = 200
Symbol TX = B.4
Symbol BAUD_FREQ = M8
Symbol BAUD = T9600_8
Symbol LDR = C.2
Symbol cmd = b0
Symbol arg = w1 ; b3:b2
Symbol arg.lsb = b2
Symbol arg.msb = b3
SYMBOL XW = W2
SYMBOL XL = B4
SYMBOL XH = B5
SYMBOL YW = W3
SYMBOL YL = B6
SYMBOL YH = B7
SYMBOL ZW = W4
SYMBOL ZL = B8
SYMBOL ZH = B9
MainLoop:
Do
Gosub WaitForDawn
Gosub SetVolumeToFull
Gosub PlayTrackWithRepeat
Gosub WaitForDusk
Gosub FadeDownVolume
Gosub StopTrack
Loop
WaitForDawn:
Do
Pause 1000
ReadAdc LDR, b10
Loop Until b10 > 105
Return
SetVolumeToFull:
cmd = $06 : arg = 0001 : Gosub Send ; set volume
Pause 500
Gosub PlayTrackWithRepeat
Return
PlayTrackWithRepeat:
Do
cmd = $08 : arg = 0001 : Gosub Send ;play tracks from the default \MP3 folder - 0001 = track 1 $08 repeat track
Pause 500
loop
Return
WaitForDusk:
Do
Pause 1000
ReadAdc LDR, b10
Loop Until b10 < 95
Return
FadeDownVolume:
Do
cmd = $05 : arg = 0001 : Gosub Send ;Decrease volume track one
loop
Return
StopTrack:
Do
cmd = $16 : arg = 0001 : Gosub Send ;stop playing track one
loop
Return
SleepForSomeTime:
Do
sleep 500 ; NOT SUREHOW TO USETHIS
loop
Return
Send:
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )
gosub Check_Busy
SetFreq MDEFAULT
Return
Check_Busy:
Do
pause Busy_Delay
loop while Busy_Pin=0
Return
I'm not surprised. I doubt anyone on the forum will agree with me, but for me, too many symbols make a program unreadable. Especially symbols you don't use!I tried but I have lost the plot, got lost on the way. Don't know what I am doing.
No the code is made up from what I have been learning (or trying to learn) here on the forum in this thread.PS
It looks like you're using the same code I used (ages ago). Do you have a link to the original?
No the code is made up from what I have been learning (or trying to learn) here on the forum in this thread.
The night and day is important for this project as I don't want it playing at night and getting the neighbours upset.
;*****************************************************************************
;* Input Output pin Definitions *
;*****************************************************************************
Symbol Busy_Pin = PinC.1 ; DF Player Busy Pin to 08M2 Pin
Symbol LDR = C.2 ; LDR to 08M2 Pin
Symbol TX = C.4 ; Picaxe Data Out to DF Player Data in Pin
;*****************************************************************************
;* Variable Definitions *
;*****************************************************************************
Symbol cmd = b0
Symbol arg = w1 ; b3:b2
Symbol arg.lsb = b2
Symbol arg.msb = b3
Symbol Light_Level = b10 ; Variable for LDR ADC Read value
;*****************************************************************************
;* Timing & ADC Value Preset Definitions *
;*****************************************************************************
Symbol BAUD_FREQ = M8
Symbol BAUD = T9600_8
Symbol Busy_Delay = 200 ; Change Busy delay value here
Symbol Dark = 105 ; Change Darkness trigger level value here
Symbol Light = 95 ; Chanhe Daylight Trigger Level value Here
;*****************************************************************************
;* THE MAIN PROGRAM *
;*****************************************************************************
MAIN:
Gosub Check_If_Dawn_Or_Dusk ; Goto sub routine and check if its Light or Dark
; Sleep 10 ; adding the ; symbol before a command removes it from the program flow
; the sleep command works in multiples of 2.3 seconds (1-65525)
Goto Main
Check_If_Dawn_Or_Dusk:
ReadAdc LDR, Light_Level
if light_Level > 105 then Gosub Dawn
if light_Level < 95 then Gosub Dusk
Return
;******************************************************************************
;* Routine that Run when it becomes Light (Dawn) *
;******************************************************************************
Dawn:
cmd = $06 : arg = 0001 : Gosub Send ; SetVolumeToFull:
Pause 500
cmd = $08 : arg = 0001 : Gosub Send ;play tracks from the default \MP3 folder - 0001 = track 1 $08 repeat track
Return
;******************************************************************************
;* Routine that Run when it becomes Dark (Dusk) *
;******************************************************************************
Dusk:
cmd = $05 : arg = 0001 : Gosub Send ;Decrease volume track one
Pause 500
cmd = $16 : arg = 0001 : Gosub Send ;stop playing track one
Return
;*************************************************************************************
;* Routine that Sends the commands to the DF Player and Checks if DF Player is Busy *
;*************************************************************************************
Send:
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )
gosub Check_Busy
SetFreq MDEFAULT
Return
Check_Busy:
Do
pause Busy_Delay
loop while Busy_Pin=0
Return
Thanks for that Neil, it does make it easier to understand and is certainly a lot cleaner and simplified.Try this i have slimmed it down a bit to be easier on the eye and removed all the unused odds and ends and added comments to help you understand the code, Have fun
#Picaxe 08M2
#No_Data
; Circuit
; .----__----.
; -| V+ 0V |-
; -| SI SO |-
; .---| X4 X1 |-
; | -| I3 X2 |<--- LDR Input
; | `----------'
; `------------------> DFPlayer RX
; Define hardware
Symbol LDR = C.2
Symbol TX = C.4
Symbol LDR_LEVEL_AT_DAWN = 105 ; LDR reads higher than this during the day
Symbol LDR_LEVEL_AT_DUSK = 95 ; LDR reads less than this at night
Symbol BAUD_FREQ = M8
Symbol BAUD = T9600_8
Symbol MP3_REPEAT_PLAY = $08 ; Repeat play a track
Symbol MP3_STOP = $16 ; Stop track playing
Symbol MP3_SET_VOLUME = $06 ; Set the volume
Symbol MAX_VOLUME = $1E ; Max volume level, $1E = 30
; Variables
Symbol cmd = b0
Symbol arg = w1 ; b3:b2
Symbol arg.lsb = b2
Symbol arg.msb = b3
Symbol ldrLevel = b4
; Main program
PowerOnReset:
High TX
MainLoop:
Do
Gosub WaitForDawn
Gosub SetVolumeToFull
Gosub PlayTrackWithRepeat
Gosub WaitForDusk
Gosub FadeDownVolume
Gosub StopTrack
Loop
; Day and night handling
WaitForDawn:
Do
Gosub SleepForSomeTime
Gosub ReadTheLdrLevel
Loop Until ldrLevel > LDR_LEVEL_AT_DAWN
Return
WaitForDusk:
Do
Gosub SleepForSomeTime
Gosub ReadTheLdrLevel
Loop Until ldrLevel < LDR_LEVEL_AT_DUSK
Return
SleepForSomeTime:
Sleep 1 ; Doesn't really matter how long we sleep for at this stage
Return
ReadTheLdrLevel:
ReadAdc LDR, ldrLevel
Return
; Handle track playing
PlayTrackWithRepeat:
cmd = MP3_REPEAT_PLAY : arg = 0001 : Gosub Send ; Repeat track '/MP3/0001.mp3'
Return
StopTrack:
cmd = MP3_STOP : arg = 0 : Gosub Send ; Stop playing track
Return
; Handle volume control
SetVolumeToFull:
cmd = MP3_SET_VOLUME : arg = MAX_VOLUME : Gosub Send ; Set volume
Return
FadeDownVolume:
For arg = MAX_VOLUME To 0 Step -1
cmd = MP3_SET_VOLUME : Gosub Send ; Set volume, 'arg' set by outer FOR-NEXT
Pause 1000
Next
Return
; Communication with DFPlayer
Send:
SetFreq BAUD_FREQ
Pause 10
SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )
SetFreq MDEFAULT
Return
I will be away for a few days, but I am going to try by myself to use this code and play two files, one that starts off in the morning playing Australian magpies followed by a second and repeating file of little birds for the rest of the day.Please feel free to ask any questions you have.
That should be possible. That will need to use the BUSY pin to detect when the first has ended but it should be easy enough to modify the main loop which I proposed -will be away for a few days, but I am going to try by myself to use this code and play two files, one that starts off in the morning playing Australian magpies followed by a second and repeating file of little birds for the rest of the day.
Do
Gosub WaitForDawn
Gosub SetVolumeToFull
Gosub PlayFirstTrack
Gosub WaitForTrackToEnd
Gosub PlaySecondTrackWithRepeat
Gosub WaitForDusk
Gosub FadeDownVolume
Gosub StopTrack
Loop
; *******************************
; Written by:
; Function:
; Target PICAXE:
; *******************************
#No_Data
; Circuit
' .----__----.
; -| V+ 0V |
; -| SI SO |-
; .---| X4 X1 |-
; | -| I3 X2 |<--- LDR Input
; | `----------'
; `------------------> DFPlayer RX
; Define hardware
Symbol LDR = C.2
Symbol TX = C.4
Symbol Busy_Pin = PinC.1
Symbol LDR_LEVEL_AT_DAWN = 105 ; LDR reads higher than this during the day
Symbol LDR_LEVEL_AT_DUSK = 95 ; LDR reads less than this at night
Symbol BAUD_FREQ = M8
Symbol BAUD = T9600_8
Symbol MP3_PLAY = $12 ; play track
Symbol MP3_REPEAT_PLAY = $08 ; Repeat play a track
Symbol MP3_STOP = $16 ; Stop track playing
Symbol MP3_SET_VOLUME = $06 ; Set the volume
Symbol MAX_VOLUME = $1E ; Max volume level, $1E = 30
; Variables
Symbol cmd = b0
Symbol arg = w1 ; b3:b2
Symbol arg.lsb = b2
Symbol arg.msb = b3
Symbol ldrLevel = b4
Symbol Busy_Delay = 200 ; Change Busy delay value here
; Main program
PowerOnReset:
High TX
Do
Gosub WaitForDawn
Gosub SetVolumeToFull
Gosub PlayFirstTrack
Gosub WaitForTrackToEnd
Gosub PlaySecondTrackWithRepeat
Gosub WaitForDusk
Gosub FadeDownVolume
Gosub StopTrack
Loop
; Day and night handling
WaitForDawn:
Do
Gosub SleepForSomeTime
Gosub ReadTheLdrLevel
Loop Until ldrLevel > LDR_LEVEL_AT_DAWN
Return
WaitForDusk:
Do
Gosub SleepForSomeTime
Gosub ReadTheLdrLevel
Loop Until ldrLevel < LDR_LEVEL_AT_DUSK
Return
SleepForSomeTime:
Sleep 1 ; Doesn't really matter how long we sleep for at this stage
Return
ReadTheLdrLevel:
ReadAdc LDR, ldrLevel
Return
PlayFirstTrack: ; Handle track playing
cmd = MP3_PLAY : arg = 0001 : Gosub Send ;
gosub WaitForTrackToEnd
Return
WaitForTrackToEnd:
gosub Check_Busy ; ???????????? Don't know what I am doing here
Return
PlaySecondTrackWithRepeat:
cmd = MP3_REPEAT_PLAY : arg = 0002 : Gosub Send ; Repeat track '/MP3/0002.mp3'
Return
StopTrack:
cmd = MP3_STOP : arg = 0 : Gosub Send ; Stop playing track
Return
; Handle volume control
SetVolumeToFull:
cmd = MP3_SET_VOLUME : arg = MAX_VOLUME : Gosub Send ; Set volume
Return
FadeDownVolume:
For arg = MAX_VOLUME To 0 Step - 1
cmd = MP3_SET_VOLUME : Gosub Send ; Set volume, 'arg' set by outer FOR-NEXT
Pause 2000
Next
Return
; Communication with DFPlayer
Send:
SetFreq BAUD_FREQ
Pause 1000
SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )
gosub Check_Busy
SetFreq MDEFAULT
Return
Check_Busy:
Do
pause Busy_Delay
loop while Busy_Pin=0
Return
You should be OK as long as you tell the neighbours to switch off their headlights when they drive past your house.The night and day is important for this project as I don't want it playing at night and getting the neighbours upset.
I would suggest running the LDR on its own and reading the value back to see where they actually sit, it sounds to me like the ADC values are probably incorrect.I got back early, bad weather.
I have tried a few things, got the DFPlayers today when I got back and made up a circuit to test.
Made a few changes as suggested, but not all is working correctly.
The LDR doesn't seem to work player is playing in the dark as well as the light, and the first file keeps repeating, even if I don't select that file at all.
When I first ran the unmodified version of Hippy's the sound was almost non existent, I increased the pauses a lot and the sound increased to a loud level and was clear.
Code:; ******************************* ; Written by: ; Function: ; Target PICAXE: ; ******************************* #No_Data ; Circuit ' .----__----. ; -| V+ 0V | ; -| SI SO |- ; .---| X4 X1 |- ; | -| I3 X2 |<--- LDR Input ; | `----------' ; `------------------> DFPlayer RX ; Define hardware Symbol LDR = C.2 Symbol TX = C.4 Symbol Busy_Pin = PinC.1 Symbol LDR_LEVEL_AT_DAWN = 105 ; LDR reads higher than this during the day Symbol LDR_LEVEL_AT_DUSK = 95 ; LDR reads less than this at night Symbol BAUD_FREQ = M8 Symbol BAUD = T9600_8 Symbol MP3_PLAY = $12 ; play track Symbol MP3_REPEAT_PLAY = $08 ; Repeat play a track Symbol MP3_STOP = $16 ; Stop track playing Symbol MP3_SET_VOLUME = $06 ; Set the volume Symbol MAX_VOLUME = $1E ; Max volume level, $1E = 30 ; Variables Symbol cmd = b0 Symbol arg = w1 ; b3:b2 Symbol arg.lsb = b2 Symbol arg.msb = b3 Symbol ldrLevel = b4 Symbol Busy_Delay = 200 ; Change Busy delay value here ; Main program PowerOnReset: High TX Do Gosub WaitForDawn Gosub SetVolumeToFull Gosub PlayFirstTrack Gosub WaitForTrackToEnd Gosub PlaySecondTrackWithRepeat Gosub WaitForDusk Gosub FadeDownVolume Gosub StopTrack Loop ; Day and night handling WaitForDawn: Do Gosub SleepForSomeTime Gosub ReadTheLdrLevel Loop Until ldrLevel > LDR_LEVEL_AT_DAWN Return WaitForDusk: Do Gosub SleepForSomeTime Gosub ReadTheLdrLevel Loop Until ldrLevel < LDR_LEVEL_AT_DUSK Return SleepForSomeTime: Sleep 1 ; Doesn't really matter how long we sleep for at this stage Return ReadTheLdrLevel: ReadAdc LDR, ldrLevel Return PlayFirstTrack: ; Handle track playing cmd = MP3_PLAY : arg = 0001 : Gosub Send ; gosub WaitForTrackToEnd Return WaitForTrackToEnd: gosub Check_Busy ; ???????????? Don't know what I am doing here Return PlaySecondTrackWithRepeat: cmd = MP3_REPEAT_PLAY : arg = 0002 : Gosub Send ; Repeat track '/MP3/0002.mp3' Return StopTrack: cmd = MP3_STOP : arg = 0 : Gosub Send ; Stop playing track Return ; Handle volume control SetVolumeToFull: cmd = MP3_SET_VOLUME : arg = MAX_VOLUME : Gosub Send ; Set volume Return FadeDownVolume: For arg = MAX_VOLUME To 0 Step - 1 cmd = MP3_SET_VOLUME : Gosub Send ; Set volume, 'arg' set by outer FOR-NEXT Pause 2000 Next Return ; Communication with DFPlayer Send: SetFreq BAUD_FREQ Pause 1000 SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF ) gosub Check_Busy SetFreq MDEFAULT Return Check_Busy: Do pause Busy_Delay loop while Busy_Pin=0 Return
Symbol LDR = C.2
main:
readadc LDR, b1 ; read the value
sertxd ("LDR Value = ",#b1,cr,lf) ; show the value read
pause 500 ; wait a short while
goto main ; repeat
I tried that out and used a torch in a darkened room to do the test and this is what I got backOnce you have the values then you can update the your program with known values and go from there.
Good luck
[98]`0[18]3[00][F8]x3[06]<[E0][9E]f?f<[00][F8][E6][F8][00][F8][18][0F]f[0F]f[0F][E6][80][98][80][E0][98]`0[18]3[00][F8]x3[06]<[E0][9E]f?f<[00][F8][E6][F8][00][F8][18][0F]f[0F]f[0F][E6][80][98][80][E0][98]`0[18]3[00][F8]x3[06]<[E0][9E]f?f<[00][F8][E6][F8][00][F8][18][0F]f[0F]f[0F][E6][80][98][80][E0][98]`0[18]3[00][F8]x3[06]<[E0][9E]f?f<[00][F8][E6][F8][00][F8][18][0F]f[0F]f[0F][E6][80][98][80][E0][98]`0[18]3[00][F8]x3[06]<[E0][9E]f?f<[00][F8][E6][F8][00][F8][18][0F]f[0F]f[0F][E6][80][98][80][E0][98]`0[18]3[00][F8]x3[06]<[E0][9E]f?f<[00][F8][E6][F8][00][F8][18][0F]f[0F]f[0F][E6][80][98][80][E0][98]`0[18]3[00][F8]x3[06]<[E0][9E]f?f<[00][F8][E6][F8][00][F8][18][0F]f[0F]f[0F][E6][80][98][80][E0][98]`0[18]3[00][F8]x3[06]<[E0][9E]f?f<[00][F8][E6][F8][00][F8][18][0F]f[0F]f[0F][E6][80][98][80][E0][98]`0[18]3[00][F8]x3[06]<[E0][9E]f?f<[00][F8][E6][F8][00][F8][18][0F]f[0F]f[0F][E6][80][98][80][00][00][FF][00][00][FF][00][00][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][00][00][00][00][FF][00]f[E6][98][98][00][FF][00][00][00][FF][00][00][00][00][00][FF][00][00][FF][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00]f[E6][98][98][00][00][00][00][00][FF][00][00][00][FF][00][00][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00]f[E6][98][98][00][00][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00]f[E6][98][98][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][00][00][FF][00][00][FF][00][00][00][00][00][FF][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][00][00][00][00][FF][00][00][FF][00][00][00][FF]f[E6][98][98][00][00][00][00][00][FF][00][00][FF][00][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][00][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][00]f[CC][98][98][00][00][FF][00][00][FF][00][00][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00][00][FF][00][00][00][00][00][00][00][00][00]f[E6][98][98][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][00][00][00][FF][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00]f[E6][98][98][00][00][00][FF][00][00][00][00][00][FF][00][00][00][00][FF][00][00][00][00][00][FF][00][00][00][FF][00][00][00][00][00][FF][00][00][FF][00][00][00][00][FF][00][00][00][00][FF][00][00][00][00][FF][00][00][FF][00][00][00][00][FF][00][00][FF][00][00][00][00][FF][00][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][00][FF]f[E6][98][98][00][00][FF][00][00][FF][00][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][00][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF][00][00][FF][00][00][00][00][00][FF][00][00][FF][00][00][00][FF][00][00][00][FF][00][00][FF][00][00][FF][00][00][00][FF]f[E6][98][98][00][00][00][00][FF][00][00][FF][00][00][00][00][FF][
Try commenting out the check busy line in the code with. ;SOLVED the file order system.
I used a free program FAT32Sorter on the SD card and now it is playing as it should, the first file plays and stops followed by the second file.
Now only have to work out why the LDR part is not turning the system off when in the dark. On first start-up while in subdued light the player doesn't start, but if I shine a light on the LDR it will come alive and start playing. If I leave it in the dark it continues to play but should slowly fade in volume and stop playing.
Okay I am trying that, have to wait now a few hours to see what happensTry commenting out the check busy line in the code with. ;
Need you help Hippy, I've got stuck now, works well one way and not another, notes at bottom of code.Please feel free to ask any questions you have.
#No_Data
; Circuit
' .----__----.
; -| V+ 0V |
; -| SI SO |-
; .---| X4 X1 |-
; | -| I3 X2 |<--- LDR Input
; | `----------'
; `------------------> DFPlayer RX
; Define hardware
Symbol LDR = C.2
Symbol TX = C.4
Symbol Busy_Pin = PinC.1
Symbol LDR_LEVEL_AT_DAWN = 105 ; LDR reads higher than this during the day
Symbol LDR_LEVEL_AT_DUSK = 95 ; LDR reads less than this at night
Symbol BAUD_FREQ = M8
Symbol BAUD = T9600_8
Symbol MP3_PLAY = $12 ; play track
Symbol MP3_REPEAT_PLAY = $08 ; Repeat play a track
Symbol MP3_STOP = $16 ; Stop track playing
Symbol MP3_SET_VOLUME = $06 ; Set the volume
Symbol MAX_VOLUME = $1E ; Max volume level, $1E = 30
; Variables
Symbol cmd = b0
Symbol arg = w1 ; b3:b2
Symbol arg.lsb = b2
Symbol arg.msb = b3
Symbol ldrLevel = b4
Symbol Busy_Delay = 2000 ; Change Busy delay value here
; Main program
PowerOnReset:
High TX
Do
Gosub WaitForDawn
Gosub SetVolumeToFull
Gosub PlayFirstTrack
Gosub WaitForTrackToEnd
Gosub PlaySecondTrackWithRepeat
Gosub WaitForDusk
Gosub FadeDownVolume
Gosub StopTrack
Loop
; Day and night handling
WaitForDawn:
Do
Gosub SleepForSomeTime
Gosub ReadTheLdrLevel
Loop Until ldrLevel > LDR_LEVEL_AT_DAWN
Return
WaitForDusk:
Do
Gosub SleepForSomeTime
Gosub ReadTheLdrLevel
Loop Until ldrLevel < LDR_LEVEL_AT_DUSK
Return
SleepForSomeTime:
Sleep 1 ; Doesn't really matter how long we sleep for at this stage
Return
ReadTheLdrLevel:
ReadAdc LDR, ldrLevel
Return
PlayFirstTrack: ; Handle track playing
cmd = MP3_PLAY : arg = 0001 : Gosub Send ;
gosub WaitForTrackToEnd
Return
WaitForTrackToEnd:
gosub Check_Busy ; ????????????
Return
PlaySecondTrackWithRepeat:
cmd = MP3_REPEAT_PLAY : arg = 0002 : Gosub Send ; Repeat track '/MP3/0002.mp3'
Return
StopTrack:
cmd = MP3_STOP : arg = 0 : Gosub Send ; Stop playing track
Return
; Handle volume control
SetVolumeToFull:
cmd = MP3_SET_VOLUME : arg = MAX_VOLUME : Gosub Send ; Set volume
Return
FadeDownVolume:
For arg = MAX_VOLUME To 0 Step - 1
cmd = MP3_SET_VOLUME : Gosub Send ; Set volume, 'arg' set by outer FOR-NEXT
Pause 2000
Next
Return
; Communication with DFPlayer
Send:
SetFreq BAUD_FREQ
Pause 1000
SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )
gosub Check_Busy
SetFreq MDEFAULT
Return
Check_Busy:
Do
pause Busy_Delay
loop while Busy_Pin=0
;While this is in the code the files work properly but the LDR,fading and stop playing don't work. Take this code out and the first file starts when there is light, runs fora few seconds and then the second file will start. Take the light away and the audio will fade out and the file will stop playing.
Return
Check_Busy:
Do
pause Busy_Delay
ReadAdc LDR, Light_Level ; Read LDR Whilst waiting for busy signal to change
if light_Level < 95 then exit ; if the light level changes to the opposite LDR level exit the loop
loop while Busy_Pin=0
Return
We can revisit night and day detection once we have it working with a torch. It should be possible to add code which will filter out 'false daylight' when headlights are detected and 'false night time' when the storm clouds gather. And that should be possible without changing the main DO-LOOP.u should be OK as long as you tell the neighbours to switch off their headlights when they drive past your house.
This looks very promising a combination of both Hippy and 1968Neil fixes, seems to work with the torch on and off, I will check again in daylight tomorrow.Try changing the busy loop to this as a temp measure you can then play with the light levels without having to wait. Remember to change it back for the finished article.
WaitForTrackToEnd:
Do
pause Busy_Delay
ReadAdc LDR, ldrLevel
if ldrLevel <95 then exit
loop while Busy_Pin=0
Return
SUCCESS, tested it today in day light and left it going all day and the birds went to bed at dusk, slowly quietening down before stopping their racket altogether. The magpies only make a racket early in the morning for about 12 minutes followed by little birds twitting all day until dusk. I couldn't tell the difference from real birds in the neighbourhood which are sometimes very quiet.This looks very promising a combination of both Hippy and 1968Neil fixes, seems to work with the torch on and off, I will check again in daylight tomorrow.
1) Remove the Gosub CheckBusyPin' from the 'Send' routine DONE
2) Rename 'CheckBusyPin:' as 'WaitForTrackToEnd:'. DONE
This has been a very interesting exercise
Code:WaitForTrackToEnd: Do pause Busy_Delay ReadAdc LDR, ldrLevel if ldrLevel <95 then exit loop while Busy_Pin=0 Return
bedtime:
ReadAdc LDR, ldrLevel
if ldrLevel <95 then sleep 10900
endif
Return
I would have edited the main loop and added some more routines ...To give the second file a fade in, I altered the file itself using Audacity software, Hippy's code gave the fade out perfectly.
Do
Gosub WaitForDawn
Gosub SetVolumeToFull
Gosub PlayFirstTrack
Gosub WaitForTrackToEnd
Gosub SetVolumeToOff
Gosub PlaySecondTrackWithRepeat
Gosub FadeUpVolume
Gosub WaitForDusk
Gosub FadeDownVolume
Gosub StopTrack
Loop
SetVolumeToOff:
cmd = MP3_SET_VOLUME : arg = 0 : Gosub Send ; Set volume to off (zero)
Return
FadeUpVolume:
For arg = 0 To MAX_VOLUME
cmd = MP3_SET_VOLUME : Gosub Send ; Set volume, 'arg' set by outer FOR-NEXT
Pause 1000
Next
Return
That's one way though I would recommend not sleeping for so long just in case you get a 'false night' if a cloud passes over or some insect or dragon alights on the sensor. If that happens it won't recover and get back into sync for however many hours you are sleeping. Sleeping for minutes and checking the LDR should not drain the battery significantly more than sleeping for hours.I would like to be able to put the system to sleep during the night and I guess that I could do that by adding a couple of sleep commands after the LDR has a reading of <95.