Introduction: Camera Trap Upload Twitter With Intel Edison
Camera traps are specially designed cameras to capture images of animals in a wildlife. It is aimed to study the ecosystem of those animals in the forest. This camera is equipped by motion cencors that use censor pir. If there is a movement from the spot that the cameras set, the camera will automatically capture it. After that, the image will be sent to twitter as an information. In this project , the controller that will be used is Intel Edison.
Step 1: Things You'll Need:
You can buy these stuff from online shop like amazon or other:
And for packing You can buy these from your local hardware store:
- Screw 4x
- Nut 4x
- Spacer 4x
- BOX
- Glue gunGlueGun
Step 2: Set Up and Install Intel Edison on PC
- Updating las firmware edison:
Donwload the latest firmware and driver software on the official website of intel edison. In this project, I use windows 64-bit.
Connect micro usb cables to intel arduino breakout board as the picture.
Instal Driver sofware. If you have not installed java, please download in here
Extract the files that have been downloaded into the edison folder.
After extracting the files, enter the root via SSH byusing putty.software. You can download it in here :
Set PuTTY
Next, write "reboot ota" so that files that have been extracted will be uploded automatically into edison board.
Step 3: Designing Wifi Connection on Intel Edison
- Open PuTTY
- In ssh root , write “configure_edison–setup”. Blank it if you do not need to change the password and the
username. Press enter until it shows set up wifi, and type Y, then enter.
Next choose wifi connection that is available and type the password if it is needed. From the picture shows that the connection has been successful and You will get the IP in intel edison. To make sure that intel edison has conected to the internet, please ping google.
Step 4: Accessing Root by Using WinSCP
- Download and run the freeware WinSCP. You can download it in here
- Input the IP, write username and password. Use the same username and password as you log in ssh. And click login.
Step 5: Updating Information to Twitter
- Install twitter javascript package from
- In SSH write npm install twitter
- Next open notepad. Write the code below and save as twitter.js
var Twitter = require('twitter');
var client = new Twitter({
consumer_key: 'your consumer_key',
consumer_secret: ' your consumer_secret ',
access_token_key: ' your token_key ', access_token_secret: ' your token_secret '
});
client.post('statuses/update', {status: 'I am a tweet'}, function(error, tweet, response){
if (!error) {
console.log(tweet);
}
});
- To get the consumer / key token, you can open here, and then create new apps.
- Upload twitter.js file that has been created in notepad to intel edison root by using WinSCP.
- Run twitter.js in ssh by typing "node twitter" . Then you will see stattus in your twitter.
Note : To show the newest one, you have to change the latest
postings. Because twitter can’t post your stattus if you write same satattus in one day.
client.post('statuses/update', {status: 'I am a tweet'}, function(error, tweet, response
){
if (!error) {
console.log(tweet);
Attachments
Step 6: Using PIR Motion Censor
Test the censor by the movement. If there is a movement, the LED will be on for 5 seconds, then it will be off after that.
Video Demo Censor
Here are the listing programs that will be entered into edison :
- Open the notepad and write this code and save as testmotion.js.
//Set up our GPIO input for pin 8
var mraa = require('mraa');
var motionSensor = new mraa.Gpio(8);
var led = new mraa.Gpio(13);
motionSensor.dir(mraa.DIR_IN);
led.dir(mraa.DIR_OUT);
periodicActivity();
function periodicActivity()
{
//Read our sensor
var motionSensorTriggered = motionSensor.read();
//Do stuff if our sensor is read HIGH
if(motionSensorTriggered){
led.write(1);
setTimeout(periodicActivity, 5000);
}else{
led.write(0);
setTimeout(periodicActivity, 100);
}
- Next Upload the files to edison board. And run in ssh typing “node testmotion” if you close to program hold Ctrl+C
Attachments
Step 7: Installing Camera
We have to choose a camera that support UVC. You can see in Here , I use a usb camera genius F100
Here are the Next processes:
- Use an external supply
- Set the switch towards usb
In software PuTTY, write lsusb to check if the usb camera has already conneced to the device. in the first line, it shows that the camera has already connected.
Next, install the camera driver that support UVC so that it can be compatible with Linux UVC driver.
Install unofficial OPKG repo in Here
Open the command in PuTTY and write : vi /etc/opkg/base-feeds.conf
After that, write
src/gz all http://repo.opkg.net/edison/repo/all
src/gz edison http://repo.opkg.net/edison/repo/edison
src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32
To save it, hold ESC and “shift
:” next write wq Enter
- Then, install uvc driver
Write:
Opkg install kernel-module-uvcvideo
- Unplug usb camera. Reconnect, and write dmesg –c
Make sure the uvc camera is detected as UVCvideo as shown this picture
- To make sure, write ls -1 /dev/video0
If Root shows
" v/dev/video0: No such file or directory", it means the device is not connected or is not installed.
- Install ffmpeg
To install ffmpeg navigate to bin by typing:
Cd edi-cambin
And write:
./install_ffmpeg.sh
Wait the process until it is done.
Next, write Cd to close it to go the next step
- Install node.js package
direct to web/server by typing:
Cd edi-cam/web/server
Next write "Npm install" to install node.js package
The command will form the bin folder and its contents.
- Test Capture
To try to capture some pictures from the USB camera, you can do by writing listing program as below: And
save as testcapture.js and upload to edison.
console.log("Start capture");
function run_cmd(cmd, args, callBack ) {
var spawn = require('child_process').spawn;
var child = spawn(cmd, args);
var resp = "";
child.stdout.on('data', function (buffer) { resp += buffer.toString() });
child.stdout.on('end', function() { callBack (resp) });
}
//delete file gambar.jpg in same folder
run_cmd( "rm", ['-f', '/home/root/gambar.jpg'], function(text) { console.log (text) });
console.log("Remove last capture");
run_cmd( "/home/root/bin/ffmpeg/ffmpeg", ['-s', '800x600', '-f', 'video4linux2', '-i', '/dev/video0', '-vframes', '1', 'gambar.jpg'], function(text) { console.log (text) });
console.log("capture done");
Next,run the node testcaptur in PuTTY
You can see the result in edison folder and you can directly download it.
The results of the image depends on the quality of the usb camera itself.
Attachments
Step 8: Finally to Combining the Three Programs That Have Been Tested to Become a Camera Trap That Can Be Directly Uploded to Social Medias Like Twitter.
Finally Video
Write this Program and Save as Combine.js:
//Set up our GPIO input for pin 8
var Twitter = require('twitter');
var client = new Twitter({
consumer_key: 'PZSlqMDYLx00qYi9RhW7yoI0r',
consumer_secret: 'NFM6ydkdJ5cM4SB8cNR0YU2hraROzZTUrMD6F8xSxM8xkYn5gb',
access_token_key: '3838434318-lOfl9zj8gaNxxYXupIrVm5eOhEA0Tjs0Z4oYVyJ',
access_token_secret: 'cqmYv4LRABph3LL2dO1ROJi9teN5HZqldq9GHWryVlx1e'
});
var mraa = require('mraa');
var motionSensor = new mraa.Gpio(8);
var led = new mraa.Gpio(13);
motionSensor.dir(mraa.DIR_IN);
led.dir(mraa.DIR_OUT);
console.log("Start capture");
function run_cmd(cmd, args, callBack ) {
var spawn = require('child_process').spawn;
var child = spawn(cmd, args);
var resp = "";
child.stdout.on('data', function (buffer) { resp += buffer.toString() });
child.stdout.on('end', function() { callBack (resp) });
}
periodicActivity();
function periodicActivity()
{
//Read our sensor
var motionSensorTriggered = motionSensor.read();
//Do stuff if our sensor is read HIGH
if(motionSensorTriggered){
var data = require('fs').readFileSync('/home/root/picture.jpg');
client.post('media/upload', {media: data}, function(error, media, response){
if (!error) {
// If successful, a media object will be returned.
console.log(media);
// Lets tweet it
var status = {
status: 'New image from #intelEdison #IOT ',
media_ids: media.media_id_string // Pass the media id string }
client.post('statuses/update', status, function(error, tweet, response){
if (!error) {
console.log(tweet);
}
});
}
});
//capture
run_cmd( "rm", ['-f', '/home/root/picture.jpg'], function(text) { console.log (text) });
console.log("Remove last capture");
run_cmd( "/home/root/bin/ffmpeg/ffmpeg", ['-s', '800x600', '-f', 'video4linux2', '-i', '/dev/video0', '-vframes', '1', 'picture.jpg'], function(text) { console.log (text) });
console.log("capture done");
led.write(1);
setTimeout(periodicActivity, 5000);
}else{
led.write(0);
setTimeout(periodicActivity, 100);
}
}
Attachments
Step 9: Packing Camera Trap
- Adjusting the position of censor, intel edison and camera
- Make a hole with a drill to position Intel Edison
- Cut the Box With Cuter to position USB Port and Power Supply
- Make Hole to Camera Position
- Create a square-shaped hole to PIS Censor.
- Sticking sensors and cameras on the hole by using a glue gun
Thank you for visiting
:)