'SS camera controller code for 08M Picaxe chip...revised 5-4-09 'This program will control several cameras, including the Sony P41, P32 'and most other Sony cameras that are typically used for trail cameras. 'Notice that all lines that begin with ' are green. These lines are what 'are called comments. They have no affect on the program at all, but are 'a very useful way to keep notes in your picaxe code to easily remind you 'what a particular area of code is for. So, by each line of code, you will 'see comments to explain what they are for. 'I will put some explanation of what these most used commands mean, and you 'can find good examples in the Picaxe manuals also. The manuals should be 'included when you download your free copy of the Picaxe Program Editor. 'At the top, click help, and you can see your choices.... 'disablebod...Disable brownout detection. see manual 2 for more details. '.............This lets the chip run using less power for better battery life. 'high.........When you see this, it tells the editor we want the pin number '.............that follows, to be an output pin, and we want it to be "on" 'low 0........This command tells the editor that we want this pin...pin 0 '.............to become an output, and we want it "off" 'pause........The lines below use the "pause" command. This is a command '............ that you will use a lot. It simply tells the program to pause '.............for a set amount of time. It is measured in thousands of a second. '.............so, the "pause 1000 command below tells the program to pause for '.............one second. If you want it to pause for say 1/10th of a second, '.............then you would use "pause 100", '.............1/2 second would be "pause 500", '.............1 minute would be "pause 60000" etc. '.............You can use a number up to 65535 with the pause command; '.............which would amount to 65.535 seconds. 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'These next few lines are just initially setting the pins how we want them. low 0 'set the pin that controls the camera shutter to low low 1 'set the pin that controls the camera power to low input 2 'let the picaxe chip know that pin2 (for the switch) will need' 'to be an input so we'll be able to see if the switch is set to' 'trail or feeder. input 3 'Pin 3 is kind of special and can only be used as an input, 'The picaxe chip knows that, so we don't really need to set it up, 'but we will anyway, just to help new guys know what is going on. low 4 'set the LED pin to low to make sure the LED is OFF. disablebod 'remember, this lets the chip run using less power (see above) pause 3000 'wait for 3 seconds 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'Here we want time for the motion sensor to warm up, and we will turn the 'camera on too, so the flash can be pre-charged or "refreshed" 'We will use the opto on the SS board to "push" the buttons on the camera. 'When we do this, we need to think of how we would do this manually... 'We will push the button for a time, then release it, to turn the camera on 'then do it again, to turn the camera back off. warmup: high 4 'turn on LED to indicate warm-up mode pause 1000 high 1 'turn on camera power opto pin to "push" camera power button pause 300 'holding power button low 1 'release power button pause 10000 'pause 10 seconds for camera to charge the flash high 1 'again, turn on camera power opto pin to "push" camera power button pause 300 low 1 'turn the camera power opto back off pause 1000 low 4 'turn LED off indicating warm-up has timed out 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'This part of the code is for the walk test part of the board operation. 'You see w0 = 300 here, this is what is called a variable. A variable is 'just that...variable, meaning you can change the number to suit the need. 'We are using this variable as a timer for the walk test mode, and you can 'adjust the time to suit your needs, or make w0 = 0, and the walk test will 'not happen at all. This walk test resets the timer every time motion is 'seen, so don't forget to make changes to "re-start timer from beginning if 'motion detected" as well as the first w0 = ___ walk_test: w0 = 300 '30 seconds..' How many 100ms - 300 x 100 = 30,000ms = 30s Do While w0 > 0 'walk test lasts till timer is timed out If pin3 = 0 Then 'pin3 goes to the PIR, when PIR detects motion...then... high 4 'light walk test LED to show detection pause 1000 'keep LED on for a 1 second pause low 4 'turn walk test LED off pause 100 w0 = 300 'restart timer from beginning if motion detected pause 3000 'wait for PIR to settle Else 'if no motion is seen this time, still count down the timer anyway low 4 End If 'when you use an "if" you also need to tell the chip where it ends Pause 100 w0 = w0 - 1 'deducting from walk test time Loop 'this just says to keep the walk test running till timed out pause 100 high 4 'turn on walk test LED to show walk test over pause 3000 'LED on time low 4 'turn LED off pause 1000 'wait 'Walk test finished, now go to regular camera mode 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'This is the part of the program where the SS is armed and ready to 'take a picture when motion is seen. You see another variable here 'This variable..w1...is going to be the refresh interval timer 'We are using a "do loop" (see manual 2) with a low power command 'called a "nap" The SS will check for a motion detection...take a short '"nap to save power, then deduct 1 from the variable. This loop 'will keep looping till the timer runs out, then the SS will "goto" 'the refresh, which keeps the cameras flash charged. 'You can change how often the camera is refreshed by changing "w1" 'Be sure to also change the "w1" in the refresh part of the code below 'as the refresh interval timer is re-set after the camera refreshes. standby: W1 = 10000 'refresh interval...10,000 is 50 minutes Do While W1 > 0 if pin3 = 0 then goto take_picture 'pin3 is motion detector triggered Nap 4 W1 = W1 - 1 Loop goto refresh 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'This is where the camera will turn on for a few seconds to refresh the flash 'so the camera will be ready to take a picture quickly. Most cameras should be 'able to top the flash charge off within a few seconds. When changing things in 'this section, be sure to make similar changes where they relate to other parts. 'In other words...if you change w1, which is the refresh interval, be sure to 'change it in standby too. refresh: high 1 'push power button pause 300 'hold power button low 1 'release power button pause 3000 'camera on for 3 seconds...remember 1000 is one second high 1 'push power button to turn off camera pause 300 'hold power button low 1 'release power button W1 = 10000 'refresh interval...10,000 is 50 minutes pause 1000 goto standby 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'Here we are, this is where the sensor has seen motion and we want to 'take a picture of what set it off. This code is written to include 'activity mode, which is where the camera will stay powered on after 'picture, so additional detection will result in an almost instant shutter. 'There is a switch on the board that lets you choose between activity 'mode and feeder mode. Feeder mode will take one picture, then the camera 'will save the picture, charge the flash, then shut off. take_picture: high 1 'push power button pause 300 'hold power button low 1 'release power button pause 1500 'This is your shutter delay time. Different cameras need different 'amounts of time between when you hit the power button to when you 'hit the shutter button. A few cameras will let you hit the shutter 'right away, as long as you hold it till the picture is taken. high 0 'Now that we have had the pause, we will push the shutter button pause 3000 'holding the shutter button down low 0 'releasing the shutter button W1 = 10000 'resetting the refresh timer 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'This is important for you to understand. Remember from the beginning 'we said high is on and low is off...well now we need to expand on that. 'The switch on the board will connect pin2, which is an input here, to either 'positive or negative. We say 1 (one) if the pin is positive, meaning it is 'connecting to the positive voltage, and we call it 0 (zero) if it is grounded. 'We are telling the Picaxe that if this pin2 has positive going to it that 'means we want the camera to be in activity mode. 'What is assumed here, is if pin2 is 0, we don't want activity mode, so 'the picaxe will skip the activity mode and keep going down the page. You 'can use the switch for other things instead of activity mode if you want 'to...for example, you could have two different delays instead. if pin2 = 1 then activity_mode 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'If pin2 = 0 meaning you have it set to feeder mode, then this part of the 'code will run instead of it jumping past to activity mode. 'The picture has been taken, and now we need a pause for the camera to save 'the picture and charge the flash up, if it was used. I chose pause 15000 'which is 15 seconds, because in the worst case, with the batteries getting 'low, and the flash used to the fullest, it can take this long to recharge. 'If you turn the camera off before the flash is fully charged, it will 'have to finish charging before it can take another picture. This delay 'will likely cause a missed picture...and we don't want that to happen. pause 15000 '1000 is one second, so this is 15 seconds high 1 'push the power button to turn camera off pause 300 'holding power button down low 1 'release power button 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'This next line is your picture to picture delay when not using activity 'Sleep is a low power mode, and each sleep 1 is equal to about 2.3 seconds. 'I timed this with a stopwatch, and sleep 43 turned out to be right about '2 minutes, because you also have the time where the camera stays on after 'the picture taken. It's up to you to make this delay what you want it to 'be. You can go from 0 to 65535.By my calculations sleep 65535 is too long. sleep 43 'This should be about 2 minutes goto standby 'from here the code will goto and wait for another detection 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'Here is the activity mode instructions. You see it is almost the same as 'the walk test. We can even re-use the variable w0 to set the time it keeps 'the camera on and waiting for another detection. activity_mode: w0 = 300 '30 seconds..' How many 100ms - 300 x 100 = 30,000ms = 30s Do While w0 > 0 'activity mode lasts till timer is timed out If pin3 = 0 Then 'pin3 goes to the PIR, when PIR detects motion...then... high 0 'press the shutter button pause 300 'hold shutter button down low 0 'release shutter button w0 = 300 're-start timer from beginning because motion was detected pause 3000 'wait for PIR to settle End If Pause 100 w0 = w0 - 1 'deducting from camera on time Loop 'this just says to keep running till timed out 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'Now that there has been no more motion seen for the time you choose 'which is about 30 seconds in this example, it is time to turn the camera 'off and go back to watching for another event. high 1 'remember from the start that 1 is the power button...push it pause 300 'holding the power button down low 1 'release the power button and the camera should be off now w1 = 10000 'we are resetting the refresh timer 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 'You have a decision to make here. 'THIS IS ONLY CHANGING THE DELAY IN ACTIVITY MODE, It is separate 'from the delay in feeder mode. This time will be for after the activity mode 'has timed out, and maybe you want to have a delay before it can start 'popping off pictures again. If you are going to use a delay longer than 'a second or so, I would use sleep, to save board battery power. pause 1000 goto standby