While the Espruino board doesn't have enough memory to take proper pictures, nothing stops it from controlling other devices. In many cases this is a cheaper and more power efficient way to get the same result!
Here, we'll show you how to make a time lapse camera using a cheap keyring camera and an Espruino board.
The Espruino board will fake the keypresses needed to turn the camera on, put it into picture mode, take a picture, and then turn it off.
Wire | Function | Espruino |
---|---|---|
Red | Battery + | Vin / JST Battery |
Green | Battery - | GND |
Yellow | Shutter | A7 |
Orange | Power | A5 and A6 |
The image above shows an Espruino Pico prototype, but you can also use a 'classic' Espruino board for this.
The manual says the following:
So (while Espruino can't check the SD card!), we need to follow the steps given which we'll do using timeouts and callbacks.
The one slight 'gotcha' is that the camera requires quite a lot of power across the 'power' button to be able to turn itself on. In order to get this from Espruino without any external components we're just going to join two outputs together (A5 and A6).
Load the code below into Espruino, type save()
, and you're sorted! Espruino will run off the keyring camera's battery and take a picture every 60 seconds.
Just edit the last few lines of code below to change the time period that the camera is active for...
var PWR = [A5,A6];
// PWR active high - we need a lot of current to force the camera on, so use 2 pins
var SHUTTER = A7;
// SHUTTER active low
// Pulse the power pin(s) high for the given time period, wait, and call the callback
function pulsePWR(time, callbackDelay, callback) {
digitalWrite(PWR,255);
setTimeout(function() {
digitalRead(PWR); // set to open circuit
if (callback) setTimeout(callback,callbackDelay);
},time);
}
// Turn power on
function powerOn(callback) {
pulsePWR(2000, 2000, callback);
}
// Turn power off
function powerOff(callback) {
pulsePWR(3000, 2000, callback);
}
// Short-press power to switch modes
function toggleMode(callback) {
pulsePWR(100, 1000, callback);
}
// Short-press shutter to take picture
function shutter(callback) {
digitalWrite(SHUTTER,0);
setTimeout(function() {
digitalRead(SHUTTER); // set to open circuit
if (callback) setTimeout(callback,1000);
},100);
}
// Glue all the commands together to turn the camera on and take a picture
function takePicture() {
powerOn(function() {
toggleMode(function() {
shutter(function() {
powerOff();
});
});
});
}
// Flash every 15s to show we're alive
setInterval(function() {
digitalPulse(LED1,1,20);
}, 15000);
// Take a picture every 60s
setInterval(function() {
takePicture();
}, 60*1000);
// Go into power save mode
setDeepSleep(1);
Now you have this framework, you could easily use it to record a few seconds of video every few minutes, or when a Pyroelectric sensor detected motion!
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.