Articles Hierarchy

Articles Home » RPI » RASPBERRY PI: with CAMERA ++


after i found a local online shop with reasonable prices / and low transport costs /
i order some small gadgets for my RPI.

- 1 - a camera
- 2 - a housing
- 3 - a WIFY USB stick
- 4 - a USB to GPIO adapter

- 1m - motion-mmal
- 1p - python with camera ( and even motion)
- 1w - camera tool MJPEG for webcam

- + - also learn some tricks linux and desktop GUI

but as usual start with all new software, newest berryboot on a 8GB uSD card,
hook RPI up to HDMI TV ( and keyboard and mouse ) for setup
and download the debian wheezy raspbian.
enable SSH and CAMERA
and install it in the plastic box with the camera.
now back only with powersupply and ethernet cable connected start work via SSH.

The "advanced IP scanner" finds the RPI at
and "PUTTY" logs me in with
user: pi pw: raspberry
making some updates..
sudo apt-get update
sudo apt-get upgrade

and use the following hour to read some RPI info.
test the camera: raspistill -o image.jpg
using add to the PUTTY the WINSCP, login RPI again
find the image.jpg under /home/pi/
and copy to PC, looks good!
when on the HDMI / TV you see the preview camera picture, in putty or VNC NOT.
there seems to be 2 problems,
the camera software is not up to date ? like the -k option show error
and calling the sudo raspi-config again to check if camera is set? gives error.

Changing the PC i needed a new PUTTY.. and find BitVise SSH client
login to RPI and get 2 windows, the XTERM and the SFTP, looks very good.
add some more tools to the RPI:
sudo apt-get install mc
sudo apt-get install tightvncserver
vncserver :1 ( password piremote, piremote, n )

with the linux File Manager find the image.jpg file and with netsurf or image viewer see it.
following is required if you do not want to start that service manually every time
by putty with vncserver :1
use this code
sudo nano /etc/init.d/vncserver
sudo chmod 755 /etc/init.d/vncserver
sudo update-rc.d vncserver defaults
sudo reboot

to make a static IP, use this code
sudo nano /etc/network/interfaces
what i will need for router and dyndns config if i use RPI as webserver.

to check if some problems are related to the berryboot, try all again with the new NOOBS v1.3
( 2 hours download time / the lite one only 3min (no OS's ) / over all 4h to have same situation )
and i see that there is a change / the repeated call of raspi-config / enable camere / now not show a error about firmware now /
but i can not say if it is solved by some update or it was a berryboot bug?

the not update of the camera tools to 1.3.3 ( -k option ) still same.

the new WLAN adapter for RPI,
hmm power requirement? when i plug it into USB the RPI rebooted??
on the desktop is the WIFI config (WPA GUI) tool:


For the console cable ( from here )

i found some info at adafruit esp. about the connection and warning
NOT TO USE power adapter AND USB 5V same time!
for the drivers see prolific
i installed the v1.8.19 on a win7 PC and put in the USB adapter
and got "Prolific USB-to_Serial Comm Port (COM11)"
remove and connect 3 wires to RPI: (3) black, (4) white, (5) green
start RPI, connect USB to PC

there was a [ENTER] required but then i could login

at TTY AMA 0

so, that was the "hardware" test from the new gadgets i got for my RPI:
housing, WIFY, camera and console cable

but the real work starts now, to bring that new camera to some use, like

but first more about hardware and power requirement,
i think camera and wifi and RPI on the 0.7A LG charger is on the limit.
so now use the powered USB HUB to drive the WIFY and a USB stick ( for the pictures and movies )
like from terminal use
sudo raspistill -o /media/KINGSTON/camera/test2.jpg
and here some more info about camera commands.

if you want to shoot some photos fast or frequently,
SDcard and USB flashdisk are not the right media,
in case you want always a actual photo stored, like for use in a webpage,
i think the temp fs (180MB RAM ) is the right place.
as i not know who / what program use it at all i will use the /run/shm/ directory (75MB RAM )
at shut down the files are lost.

and also about filesize, test it using options -w , -h, ( pixel of the photo ) and jpg quality -q option
what does that do to the filesize:

want the RPI to be a webserver: in article 1 and 2 already tested apache and nginx, now test the Lighttpd

sudo apt-get -y install lighttpd
sudo apt-get -y install php5-common php5-cgi php5
sudo lighty-enable-mod fastcgi-php
sudo service lighttpd force-reload
sudo chown www-data:www-data /var/www
sudo chmod 775 /var/www
sudo usermod -a -G www-data pi
sudo reboot

and find in browser the placeholder page. Source location is: /var/www/index.lighttpd.html
sudo nano /etc/lighttpd/lighttpd.conf
server.port = 40045
sudo /etc/init.d/lighttpd restart

for call in browser:

now, whats the actual status? hmm everything works a little bit, OR nothing works.
- as i don't know how to update to the newest camera software i miss options
-l lastpicture.jpg, -t 0 run forever, -k keyboard input
what does work now is autostart,
use this code
sudo nano /etc/init.d/RPICAMsnap
and it starts the camera, runs one day, stores every 5sec a picture to RAM disk
and there is a webpage using this code
means i can copy the picture to the web space path on web request and show.
-bad- i was not able to show the picture from the RAM disk path
-bad- i was not able to start the camera from there ( php exec or system )
-very bad- the system incl web server works but sometimes the main user ( HDTV ) is dead
because the camera start blocks all??
what means that i have no idea about linux privileges and how to spawn camera as a background service.
checks show:
ls -l /run/shm/
ls -l /var/www/

cat /etc/group
cat /etc/passwd

and i even can not show it to you, because i don't know how to set my new router,
with the old one i used DMZ, and i see local IP, but could never see my dyndns page, only by using a proxy.
with the new router and DMZ i can see my dyndns page but nobody else???
and how to set page forward i still don't know.
or is it because DYNDNS changed something? ( not free subdomain anymore? )
Now work on the process start and on the webserver on a different port and the router port forwarding
as you see in the installation section above there is a line in /etc/lighttpd/lighttpd.conf
server.port = 80
there i adjust a new port 4000.
in the router i adjust a port forward

and in my old DYNDNS account i still have the (sub) domain name, i call with that port

now with the camera service i see that there is a
kill -USR1 :process id of raspistill:
signal for stop, but how to build it in the service.
ps -ef | grep raspistill show me
root 2077 2075 0 06:10 ? 00:00:00 su pi sh -c raspistill -t 86400000 -tl 5000 -o /run/s hm/RPICAM.jpg -w 1024 -h 768 -q 50 -n
pi 2079 2077 0 06:10 ? 00:00:26 raspistill -t 86400000 -tl 5000 -o /run/shm/ g -w 1024 -h 768 -q 50 -n
pi 5867 5369 0 10:17 pts/1 00:00:00 grep --color=auto raspistill

anyhow for this need a more professional autostart code in:

sudo nano /etc/init.d/RPICAMservice
sudo chmod 755 /etc/init.d/RPICAMservice
sudo update-rc.d RPICAMservice defaults
// enable autostart
sudo update-rc.d -f RPICAMservice remove
// disable autostart

sudo /etc/init.d/RPICAMservice start
sudo /etc/init.d/RPICAMservice stop
sudo reboot

and learn about start stop of service and here

for the webpage some small modifications, need to show local time
( date time in picture function not available )
and a user password ( session related ) login function in php, pls find at downloads

but right after that i got a info from forum
that i need a firmeware revision to get that new raspi-still -vid functions
sudo rpi-update
many times i did the
sudo apt-get update
sudo apt-get upgrade

but i did not know about that firmware upgrade. And it worked!

this looks already usable. digging more what other work on i see
the MOTION projects. This i want to try next.

( after disable above service )
follow Link
sudo apt-get install -y libjpeg62 libjpeg62-dev libavformat53 libavformat-dev libavcodec53 libavcodec-dev libavutil51 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev
here better: cd /usr/bin/
tar zxvf motion-mmal.tar.gz

test: ./motion -n -c motion-mmalcam.conf

ok, something is happening:
with some ctrlC i get it stopped.
in dir /home/pi/
i see files:
and 2 *.avi ( each minute )
and many ipg files ( 2 for each second )

read this
and using this code pls find inside zip subdirs and files

/etc/motion/motion.conf did not work bc it was not found by motion program, it searches only in /etc/
sudo nano /etc/motion.conf

sudo nano /etc/default/motion
sudo chmod 755 /etc/default/motion

sudo nano /etc/init.d/motion
sudo chmod 755 /etc/init.d/motion
sudo update-rc.d motion defaults

test: sudo /etc/init.d/motion start
or reboot ( and wait 30sec )
ls -la /run/shm/motion/
or to see it in a webbrowser:
( in above config user / password not enabled )

now to check settings in /etc/motion.conf and filesize,
motion avi 1 .. 3MB for a person walk through camera angle.
OPTIONAL:and snapshot jpg picture ( every min) with 50k each.
with image width 1024, height 576, framerate 2, pre / post capture 2
image jpg quality75, snapshot_interval 60

with df -h i see tmpfs 25M only ( for /run ... ) after 30min half full
forum confirmed that /run/shm/ ( 50MB) is RAMdisk for user programs.
so this ( higher ) quality setting is only usable with a harddisk as storage.
anyhow, without a cleaning / further file handling .. that temp fs use will run into ERROR.
the default picture size ( smallest?) is 352 * 288, but i think its also a reduced view ( angle )? and the AVI runs too fast??

800* 600, 640 * 480, 512*360 give me all timeouts/restart??
1024*576 works and test "output_picture off" get only the AVI file.
how to disable this ( and with it the whole motion thing ) and just use it as IP cam ??
in the browser its a 300kbps stream, little bit jumpy,

Next i try to use the USB stick as storage.
here i disable the storage path TARGET DIR
sudo nano /etc/motion.conf
because now the default should be the current dir,
but the avi shows up in root.
sudo nano /etc/init.d/motion
cd to path ( prior to start-stop-daemon) not work
--chdir to path ( in start-stop-daemon) not work
bad luck, must have TARGET DIR in motion.conf?

now i see lots of avi files on usb, and when i check closer i see many megabyte avi film what just show ONE picture, ( ONE second ), that must be a bug in motion program when there is NO MOTION?
lets also stop this one
sudo /etc/init.d/motion stop
sudo update-rc.d -f motion remove

as i build up the motion system by copy files and write new ones, i must make sure
that the problems with that have nothing to do with installation,
because in other posts i now see a good installation, but all used for USB webcams??
sudo apt-get install motion

sudo chmod -R 777 /etc/motion/motion.conf
sudo chmod -R 777 /tmp/motion

sudo nano /etc/motion/motion.conf
sudo /etc/init.d/motion restart

raspberry pi .ORG web server also down
try later again, first doing
sudo apt-get update
sudo apt-get upgrade

was a bigger job and still some connection problems
6MB for the motion??
warning/question that the etc/default/motion and etc/init.d/motion
could be overwritten, i want that.
sudo nano etc/default/motion
change to yes,
sudo nano /etc/motion/motion.conf
the default target dir is now /tmp/motion ( SD card!)
and videodevice /dev/video0 ( i had it disabled )
and mmalcam_name ( this section missing )

after a reboot i check on files in that directory and if camera is on network.NO, so some more missing: the
sudo nano /etc/init.d/motion
looks like the one i started with last time.
sudo chmod 755 /etc/init.d/motion
sudo update-rc.d motion defaults
sudo /etc/init.d/motion restart
but still under /tmp/ see nothing.

stop that too, just to test with webcam could be interesting but waste of time now.
sudo update-rc.d -f motion remove

possibly should try again following this

and try something for programmers, a PYTHON version
now, how to start?
working environment:
- putty
- VNC window
- totalcommander secure FTP connections for file transfer

on Desktop ( in VNC window ) select
IDLE icon, thats the python2.7
under options configure IDLE - editor font - freeMONO 12 bold ( or i can not read small text in VNC window )

test PYTHON 1:
use raspistill from python

cd /home/pi/Desktop/
sudo python

with that i get 6 pictures, but with the first 3 a warning "RaspiStill: Unknown exposure mode: off"
check the program:
"#!/usr/bin/python" == python in above command line call, == a symbolic link to python2.7
test via PUTTY:
pi@RPICAM ~ $ raspistill -t 1000 -ex off -awb off
RaspiStill: Unknown exposure mode: off
pi@RPICAM ~ $

if that tool was made 23.6.2013 by Matt Hawkins why i have a different raspistill ? by the rpi-update?
so i do update again, and read the newest documentation ( correct, there is no -ex mode "off" )
and update that code... ( the delete old file don't work, but the overwrite does anyhow. )

test PYTHON 2:
play with the Dave Hughes RPI CAM LIB
pls see here or here
To perform the Python 2.7+ Installation ( type: system) :

sudo apt-get install python-pip
sudo pip install picamera

To upgrade your installation when new releases are made:
sudo pip install -U picamera

If you ever need to remove your installation:
sudo pip uninstall picamera

here i play with various examples, and i noticed something what is obvious,
but also could be a nice trick somebody wants to use.
if you make continuously many pictures, lets say every second ( to temp fs pls)
but you give it a name "PIC_year_month_day_hour_min.jpg", you end up with a directory full of
one minute pictures, only the latest one is "CURRENT (-1sec)" means very fresh.
you could call this a kind of data reduction, and you don't need code for it, OS is doing it
by overwriting files when they have same name,
60 pictures always have same name, then the name changes.
In summary you have the latest picture ( lets say for use in a web server page )
and a 1 min time lapse temporary file storage.
here my play code
in his BASIC RECIPES is a interesting section about STILL versus PREVIEW resolution

test PYTHON 3:
Sean Ashton picam lib
install failed but with sudo OK
sudo pip install

import picam
import time
i = picam.takePhoto()'/tmp/test.jpg')

give error:
pi@RPICAM ~ $ sudo python /home/pi/Desktop/
Traceback (most recent call last):
File "/home/pi/Desktop/", line 5, in
import picam
File "/usr/local/lib/python2.7/dist-packages/picam/", line 5, in
from PIL import Image
ImportError: No module named PIL
pi@RPICAM ~ $

i try:
sudo aptitude install python-imaging-tk ! removes 5 other libs?? !
but now above mini program runs. clean up $ sudo rm /tmp/test.jpg
and add in
sudo nano /boot/config.txt
sudo reboot
and that code works fine in "spy" mode, NO RED LED.

test a video by that code and play it:
sudo apt-get install xterm
in filemanager right click one of your movie files and
select open with, then click custom command line tool, type in:
xterm [-fullscreen -fg black -bg black] -e omxplayer -o hdmi %f
and check the box saying always do this,
so you only have to double click on any file of that type in the future and it will do the same thing.
repeat for other types too.

on the win7 PC i play it in the VLCmedia player ( where it runs forever ??)

i have a question regarding picture file size and jpg resolution, same pixel resolution 640 * 480 give a
180kB with raspistill and the library Dave Hughes
with this library 20kB 85% jpg quality
and even with 1280*720 and 100% jpg its only 40kB big??
i try check the detail properties of the files, and see a difference, resolution 96dpi, no info for color representation and resolution unit, while the BIG files show
resolution 72dpi and color representation sRGB and resolution unit 2
so, if the bad color quality is ok with you, and small file size is always needed with RPI SDcard!
that tool is good for you.

test PYTHON 4:
a python raspistill code with motion detect!

later in the thread there is a improved version,
but both not run for me!

Traceback (most recent call last):
File "/home/pi/python_cam/", line 76, in
image1, buffer1 = captureTestImage()
File "/home/pi/python_cam/", line 40, in captureTe
imageData.write(subprocess.check_output(command, shell=True))
File "/usr/lib/python2.7/", line 538, in check_output
output, unused_err = process.communicate()
File "/usr/lib/python2.7/", line 746, in communicate
stdout = _eintr_retry_call(
File "/usr/lib/python2.7/", line 478, in _eintr_retry_c
return func(*args)

try a :
sudo chmod 777 /dev/vchiq
i found a second and a third version and suddenly
the last one did work ( but making a 110 .. 140kB jpg every second??)
something to work on.
change to:
threshold = 100 ( from10 ) ( read 10 is ok )
sensitivity = 200 (from 20 ) ( read 140 should be good )
test manually
raspistill -t 1000 -w 1296 -h 972 -q 15 -n -o /run/shm/image.jpg 116kB
test again, not bad.

test PYTHON 4: b
come back for this:
build up new berryboot system, make it up todate and remote usable, and make backup of it.
now start with the python motion detect program ( no webserver, no motion program ... )
pls find all steps and code in here
so, that is my starting point to go on.

in the following cheatsheet you will find that i try/did some small changes
wifi and host name
and a interesting thing with a file hoster dropbox
first you need a account there and optional also install the dropbox software on your PC.
the script on RPI uses a api, what is a lengthy procedure so it must be safe! LOL
but after it is initialized / connected you only need a command

/home/pi/python_cam/ upload /run/shm/last.jpg /RPICAM1/

and a some second upload is performed, a sec later the file is also in the corresponding
folder on your PC.
i think you could do that with all file hoster, but i only find info about google+ and dropbox.
( the "last.jpg' thing comes from the link my python program generates )
from i start it as a
also i test a FTP transfer of the picture
sudo apt-get install wput
! must walk to the directory the picture is in, to start wput !
what i actually did is i buy a 16GB USB stick ( PNY for 360THB )
and put it in my router, where i enable the FTP server.
means i keep the pictures locally / private but accessible from all PC on the LAN
and a email,
but run with 4 different python email codes into the same error: ( using python 2.7.3 )
smtpserver = smtplib.SMTP('')
AttributeError: 'module' object has no attribute 'SMTP'

GRRRR my problem, the filename of my tests was and that caused a conflict! rename file and ok

i not try to email a picture, good way might be to send a link where that picture is.
and again do the lighttpd webserver thing
with a small change, for file copy look at the last.jpg link file,
and in motion detect i force a picture every minute for this webpage

i have to check deeper on 2 issues,

- there are too many pictures with normal background ( no motion )
must test the provided debug mode.
i worry 2 possibilities:
* there is a motion detected and a picture taken, but too late
** after the "motion" has gone out of the camera field there is a other motion detected ( motion object missing )
and so directly after every real motion ( in ) one more picture is taken with the background.

- some hours after start the file storing stops? need detail check on file cleanup procedure and directory free space check.
this part should work also!
* looks like in that code that a walk to the directory is required for that delete.
( because the directory read back give file names without path )
* it starts to delete the oldest file? ( GOOD, but sort by what ? )
each time it makes a new one.
In my case the dir is 100MB, i adjust 10MB to keep free for other programs.

pls get that version here

only for documentation i install a screenshot utility on the RPI
sudo apt-get install scrot

here a little excurs to Desktop, Icons, operate service with GUI
when you make a python program to a service ( even as auto start )...
that is operational from terminal window only ( like start stop restart status ).
but at the python game example i found a good way to start from a desktop icon ...
using the ZENITY tool
the problem was i could operate the service with it, but i not get the system feedback shown,
unless run in terminal and to give operator time to read system output need to force it to wait.

here the desktop icon:
path: /home/pi/Desktop/
name: picam4_service.desktop

the gui bash:
path: /home/pi/python_cam/

the service:
path: /etc/init.d/
name: picam4

the program:
path: /home/pi/python_cam/

and that looks like:
after double click on ICON

after selection see result in terminal window

RPI CAM as webcam:
from here using his MJPEG
it comes with a installation tool too!

well new setup last night:
berryboot, update, upgarde, rpi-update,
test camera and run into error, no idea what i do wrong
additionally the PUTTY SSH is broken too.

i rebooted in my old RPICAM2 ( python motion ++ ) version
and camera and webserver still worked ( means i did not damage the camera )
but i can not run his install script here, because i have a different webserver (lighttpd) running.

doing a new setup for verify, and after rpi-update same happen again.
( but there was a image.jpg file! ) 4um
a later test just to copy the missing config.txt to /boot/ did not work

now what i do? other SD card, mini NOOBS, new setup
download install raspbian ( 30min / similar to berryboot )
desktop, SSH, camera enable, reboot
camera ok, update, camera ok, upgrade, same camera error! reboot: camera NO error
( there is a difference in the upgrade with berryboot and noobs,
in berryboot the boothack is hold back! with upgrade, but not with rpi-update!
changed: ARM/GPU split is now defined in /boot/config.txt using the gpu_mem option! )
rpi-update, reboot, camera OK!
now can do that installation

in the post he indicates:
Warning: The installer will replace /etc/rc.local, so if you changed this file, you need to backup it.
possibly you should do this anyhow

here i try the installation on the above updated wheezy
chmod u+x

system reboots at the end.
as in the 3. run under noobs it is working,
i test in TOP and see raspimjpeg with 45% cpu usage

he is using apache2 and php,
and sets up:
index.html ( using a script.js )

after installing in NOOBSlight

very good job
using FIREFOX 25.0.1 and 26.0, Google Chrome 31,
in IE 9.0... i see all, update works, but IE operation hangs, must stop with task manager.
other devices,
ODYS SPACE android tablet works ( but rotation 180 not shown??)
mobile NOKIA ASHA 210 browser not work.

in ls /etc/rc.local ( at boot )
a new dir in temp fs is made
ls /run/shm/mjpeg/
and a program started:
raspimjpeg -w 640 -h 360 -d 1 -q 25 -of /dev/shm/mjpeg/cam.jpg -cf /var/www/FIFO -sf /var/www
what you find here
ls /opt/vc/bin/raspimjpeg

the resulting pictures and videos find here:
ls /var/www/media/
but that is empty even the picture in webpage updated, very good,
i have to find out how he did that:
in cam_pic.php he read the file from temp fs
header("Content-Type: image/jpeg");

and in the script he calls it (? with a timestamp? future? )

if press [record image] i find it with 2.3MB in /var/www/media/image_0000.jpg

from forum:
If you want to free the camera just temporarily, run "sudo killall raspimjpeg" and to restart the service, run "sudo /etc/rc.local".
sudo killall raspimjpeg definitely works
restart does not work for me:
pi@RPICAM3 ~ $ sudo /etc/rc.local
My IP address is
mkdir: cannot create directory `/dev/shm/mjpeg': File exists

for my understanding, that program not uses raspistill and raspivid?,
but the camera is in use all the time, so they are not available while that process is running.
i think that tools does all you need.
( new info )
now, a day later, he changed on many requests,
just rerun the installer,
and on the webpage is a new button [release camera]
( ? but cpu still on 45% !)
and a help text edit /etc/rc.local and add the parameter -pa to the raspimjpeg-command
( from docu: -pa start RaspiMJPEG in idle state )
( ? but again cpu still on 45% !)
a start is possible from the website [restart/release camera ] button
i needed a pageupdate on firefox to see the picture.

as i like that all very much, i want to go the full way!
sudo apt-get install cmake
git clone
cd userland
and where to find his new stuff?
ls /home/pi/userland/host_applications/linux/apps/raspicam/RaspiMJPEG.c
cat /home/pi/userland/host_applications/linux/apps/raspicam/

if change something:
that makes all userland programs, incl raspistill, vid, mjpeg again and takes 20min ( first time use and then need additionally )
sudo ln -s /opt/vc/bin/raspimjpeg /usr/bin/raspimjpeg
( if had not installed raspimjpeg b4 )

i checked also for the memory, pls see

for streaming video pls
go through all that stuff

update 11/2016 here