Webcams on Raspberry Pi

Webcams on Raspberry Pi is like salsa and chips – they just belong together.  But sometimes making that happen isn’t straight forward.  I’ve done it two ways and figured I would share with anyone else wanting an easy way to run a webcam on Raspberry Pi.  The first way is for a standard USB webcam, the second way is for any of the “Raspberry Pi Cameras.”  To automate any of these processes, use crontab and call the command every minute, hour, or whenever you want.  For me I make a shell file with the command(s) in it, then call that in crontab.  This makes like easier, especially when using multiple commands like with ImageMagick, so that things happen in the right order.  Also, if you need to make changes to the script you are only editing that one shell file rather than every line in crontab!


Make USB webcam work on Pi:

First install fswebcam: sudo apt-get install fswebcam

Then you can run a command to take a picture from the camera.  In my case I wanted to save it in the “html” folder so I could share it with the world.  This directory could be changed to wherever you want it saved.  Here is the command I was using: fswebcam –jpeg 95 –save /var/www/html/current.jpg -S 20 -r 1280×720

If you would like to scale the image down you can add the –scale flag like this: fswebcam –jpeg 25 -S 20 -r 1280×720 –scale 640×360 –save /var/www/html/current.jpg

If you would like to change the default banner (or remove it), as well as many other options, check out the fswebcam manual.

To get the files to host using Apache you will need to fix permissions so “pi” can write to those folders (directions from raspberrypi.org):

On normal situation, http daemon run as some user and group, www-data on debian (raspbian).
Standard html files are stored on /var/www/, owned by root:root, with permissive permission, all can read, but only root can write.
To ordinary user write to /var/www need to takeover it. Supposed the use is pi.
sudo chown -R pi:www-data /var/www
Also, need to set user and group permission:
sudo chmod u+rxw,g+rx-w,o-rwx /var/www
Now, /var/www can be read,write and chdir by user pi, group www-data can chdir and read. Other not have access.
sudo chmod g+s /var/www
Any new file created on /var/www belong to group www-data.
If have files on /var/www, change user and group, and allow to group www-data read.
For file chmod u+rw,g+r-xw,o-rwx
For directory chmod u+rwx,g+rx-w,o-rxw
Now, user pi can manipulate files on /var/www and httpd can read, but not write.

If you would like to make an archive of your webcam images, we can do that too!

First you will need to make a shell file that you will be executable, sudo chmod +x shellfilename.sh

Then open the new shell file in nano (or other editor) and put in your code.  This shell file code below will copy the current.jpg file to an archive folder with $DATE in the filename.

#!/bin/bash

DATE=$(date +”%Y-%m-%d_%H%M”)

cp /var/www/html/current.jpg /home/pi/webcam/$DATE.jpg


Make Raspberry Pi Camera function as webcam:

For the Raspberry Pi camera to work you will need to use Raspistill.  This is pre-installed with Rasbian, but if you want text on your image (like the default banner in fswebcam) you will need to install ImageMagick, sudo apt-get install imagemagick

Now run the terminal command to take a picture, for us we used: raspistill -w 640 -h 480 -hf -vf -o /var/www/html/buffer.jpg

For more commands, check out the Raspberry Pi Camera Manual.

Now we want to take the new image and add our banner.  This code will take the buffer.jpg image and add the label, timestamp, and banner color behind the text, then save the file as current.jpg.

/usr/bin/convert /var/www/html/buffer.jpg -fill ‘#0008’ -draw ‘rectangle 0,455,640,474’ -pointsize 14 -fill white -annotate +5+470 “TITLE OF WEBCAM” -annotate +505+470 %[exif:DateTimeOriginal] /var/www/html/current.jpg

When drawing the banner box, the coordinates are a,b,c,d where a is the left edge of the box, b is the top of the box, c is the right edge of the box, and d is the bottom of the box.

For more information on ImageMagick, check out the terminal commands in the ImageMagick manual.


Now you want to display this new image in a web page, right?  But isn’t it cooler if it auto-refreshes?  I think so.  Here is the very simple, but very effective, code that I like to use:

<html>
<head>
<script>
var webcamimage;
var imgBase=”current.jpg?”
var c = 0;
function count()
{
webcamimage.src=imgBase+(++c);
}
function init()
{
webcamimage = document.getElementById(“webcamimage”);
if( webcamimage )
{
setInterval(“count()”,10000);
}
}
window.onload = init;
</script>
<title>Current Weather in Skowhegan, ME</title>
</head>

<body>

<img alt=”Web Camera Image” id=”webcamimage” src=”current.jpg” />
</body>
</html>

Posted in Computers and Hardware, Technology, Web/Internet | Leave a comment

32 a big year

It seems I always hear about people turning 30 or 40 and how big of a deal it is.  For me when I turned 30, I didn’t think anything of it.  However, turning 32 this year seemed to resonate more.  Not a bad thing, but I just noticed.  For instance, no longer am I able to register my age in 5 bits, I am now into a 6 bit register!  (31 in binary is 11111, 32 in binary is 100000).

I’m curious how many other tech-minded folks have thought about this.

Posted in Ponderings | Comments Off on 32 a big year

Digital security more important now than ever

There has been an enormous up-tick in hacking attempts, at least on web space that I manage as well as the servers at my day job.  This means that more than ever, people need to be diligent about running all security updates on their OS as well as application updates (especially plugins like Java and Flash).  It also means that for web devs like myself, it’s time to bite the bullet and buy SSL certs for any websites containing multiple logins and user data.  For me, this means SSGuitar.com.  As of January 20th 2017 SSGuitar is completely SSL’d.  I love encryption.

Posted in Computers and Hardware, Technology, Web/Internet | Comments Off on Digital security more important now than ever

Repair Manifesto

iFixit.com has posted their “Repair Manifesto” and it just so happens to be everything that I believe in. Why waste by throwing things out when it could just be fixed?  I repair everything I can from electronics, cars, plumbing, lawn mowers, computers, musical instruments, furniture, toys…basically anything!

iFixit.com Repair Manifesto

iFixit.com Repair Manifesto

Posted in Community, Computers and Hardware, Environmentalism, Hobbies, Home and Homestead, Made in the USA, Personal, Projects, Upgrade | Comments Off on Repair Manifesto

Review: Lit soothing on new country single ‘Fast’ (Includes first-hand account)

Digital Journal review link

I am so excited, I had to share. Lit, my favorite band from the time I was about 15, is back. And they’re country. Their new song “Fast” actually just made it to #1 on CMT’s 12 pack count down!

Posted in Music, News, Personal, Upgrade | Comments Off on Review: Lit soothing on new country single ‘Fast’ (Includes first-hand account)

Skowhegan Wooden Rule Company

I love wooden rulers, and even more so, wooden yard sticks.  I just found out about a local company that makes them, and they even do the brass end plates that I love so much on the end of the yard sticks.  I haven’t purchased one from them yet, but from the pictures on the site, they look exquisite!  Check them out for yourself: skowheganwoodenrule.com

Posted in Made in the USA | Comments Off on Skowhegan Wooden Rule Company

Pex vs Copper

This seems to come up every now and then in conversation.  I use copper pipes.  Almost everyone I know is switching to running PEX due to low cost and easy installation.  Here is my take on the situation.

Copper
Copper pipes have been used for hundreds of years and typically have a lifespan of 50-100 working years in domestic water situations.  The only thing that brings this lifespan down is acidic water, and frozen pipes.  A split copper pipe can be easily repaired though, so freezing isn’t all that bad.  Plus, unfreezing copper is easy – heat it with a torch!  On the downside, copper is twice as expensive as PEX.  Installation of copper pipe requires a basic propane torch, solder, and flux.

PEX
PEX piping is relatively new (a few decades) and has an unknown lifespan.  PEX is plastic and all plastics leach some chemical into the water.  If this is a safe amount or not, I’m not sure, but I feel unsafe using it in my home.  PEX is cheap, flexible, and when it freezes it typically doesn’t burst (though it can).  On the downside, PEX can be chewed through by mice and rats and it can’t deal with high temperatures or UV rays (no outdoor exposure).  PEX requires special tools to install.

Conclusion
I will gladly pay more for the copper and sweat it in myself.  I like the fact it doesn’t leach chemical.  I like that it looks nicer when exposed (PEX is ugly).  I like that it is safe around rodents (mice and rats are commonplace on the homestead at times).  And I also like that I can heat it with a torch if it freezes.

Posted in Home and Homestead, Ideas | Comments Off on Pex vs Copper

I’m famous!

I helped design a watch with MWC, and they are now on their website for sale in black and olive!

mwc-1966-on-wrist

MWC’s production version of my redesign of their “vietnam” watch.

To be fair, I only redesigned an existing watch dial.  The rest is all MWC.  It all started with me asking a bunch of questions about their “vietnam” watch.  They were very responsive and even gave me manufacturing details as far as movement type (Miyota 2035), and manufacturing location (Japan).  I wasn’t sure on the 24hr design, but it was such a handsome watch that I ordered one anyway.  After getting it in, I decided to do a little photoshopping to adjust it more to my liking and then shared the results with MWC.  I specifically removed the 24 hour numbers, reshaped the hour indices and changed their color.  They liked it so much that they decided to make it.  MWC then added a pheon, making the design officially theirs, not mine.  They have recognized me officially on the website though and will be sending along an official letter stating my help in the design of this watch as well.  Way cool!  They also sent me a couple of the watches and two of their nice zulu straps as well.  What a great company.  Right from the get-go they’ve been very fun talking to back and forth and a real joy to work with.

 

watch-versions

Left: MWC “vietnam” watch. Right: My photoshopped redesign of the “vietnam” into a 12hr dial.

Screen Shot 2016-07-15 at 9.33.53 PM

Screenshot showing where they mention my name on the website.

Posted in Hobbies, Personal, Projects, Web/Internet | Comments Off on I’m famous!

Series telecaster wiring, stock 3 way switch

Top: stock telecaster wiring. Bottom: Joseph Raymond version of series wiring scheme

Posted in Circuits and Electronics, Hobbies, Music, Upgrade | Comments Off on Series telecaster wiring, stock 3 way switch

New counter weight

A while ago I added about 1 ounce of BB’s to the output jack of the telecaster to help offset the neck dive. I just upgraded to a 2.25 ounce weight by using washers! They are steel washers, 5/32″ ID, 7/8″ OD. 14 of them plus two similar size rubber washers, one on each end of the stack. They are rubber cemented together into a column and the cable for the output jack runs right through. I should have taken a picture or three, but I was so excited to get it together I forgot.  I still have a little dive, but it’s better. I think a lighter neck and tuners will be the only real fix.

image

Posted in Hobbies, Music, Projects | Comments Off on New counter weight