Over the last few months I have been preparing my project and presentation for the UK CLD Summit. Now that the CLD Summit is over, I wanted to do a quick and fun project on my Raspberry Pi that has been lying in a box for those few months.
Something that I have wanted to do for a while is get a webcam working and be able to take pictures. I don’t have the Raspberry Pi camera, so just used a normal webcam. I used the Logitech C170 connected directly to the USB port of my Raspberry Pi and it worked really well. The other USB port has a WiFi dongle connected.
I have this connected up and looking out my window so please excuse the lack of quality.
So to get started, make sure your Raspberry Pi has been updated. I have used the standard Rasbian image.
Setting up a webcam:
Then you need to install
apt-get install fswebcam
Once all the above has been installed, plug your webcam in and reboot. Make sure that your webcam is seen by the system.
Bus 001 Device 005: ID 046d:082b Logitech, Inc.
There are many switches and options available, so I will explain what I used and how to get a full list. Run this command to capture an image.
fswebcam -r 640x480 -S 10 -d /dev/video0 webcam.png
- The program that is being executed
- Setting the resolution for the image
- Skip the first 10 captures. With my webcam, if I save the first image captured, it gets corrupted. So by adding this option, the camera takes 10 images and only saves the last one.
- This sets the device name. To get yours, execute
ls /dev/and look to see what your device is called
- This is the file name of the saved image
fsweb -h, you can see all the options.
You will now have the image saved to the location of your choice. If you are running headless like I do, you have no idea if the image is correct. You could FTP into your Raspberry Pi and get the image off, or like I have done, link my Raspberry Pi to my Dropbox account.
Linking a Dropbox account:
It took me a few attempts to get my Raspberry Pi and Dropbox account linked, but got there in the end.
First you need to download the Dropbox_Uploader script from git. I then copied the script file to the folder where I am saving my pictures to. You don’t have to do this, however it saves writing full paths when executing the commands.
Once the script is in the location you want it, you need to make it executable.
chmod +x dropbox_uploader.sh
Make sure you have a Dropbox account before executing the script. Once you have an account, then you are ready to start linking the two. Run the script and follow the prompts.
The settings that I used when setting up my App were:
- Files and Datastore
- No – My app needs access to files already on Dropbox
- All file types – My app needs access to a user’s full Dropbox
- Add a unique name, you might need to try a few
Verify your app and if successful, you will notice a folder called Apps has now been created in your Dropbox account. I had to wait a few minutes for this to update.
Test if your account has been linked properly by getting a list of folders in your account.
If this works, you are ready to start uploading your images.
./dropbox_uploader.sh upload image.png /Apps/App_Name/File_Name
Wait a few seconds and the image should appear at the location you uploaded it to. Now you can see if the image you captured in the previous steps has worked.
Here is a time lapse video that I put together using Windows Movie Maker. I set up a cron job and ran a script every minute.
If you have any questions, please leave them below in the comments and I’ll try help where I can.