Category Archives: Linux

Dynamic webcam control using (py)ephem

Time-dependent webcam control

For taking still images with a webcam looking outside my sleeping room window, I’ve attached a Logitech C510 to my RasPi. At first, I used the fswebcam program to acquire still images, which can be easily configured using a fswebcam.conf file as follows:

quiet device v4l2:/dev/video0
input 0
skip 50
palette MJPEG
background
resolution 1600x1200
set "White Balance Temperature, Auto"=1
set "Exposure, Auto"=3
set "Backlight Compensation"=1
#set "sharpness"=100
#set "gain"=0{c7f7cb1468c0d02af358b3ce02b96b7aadc0ce32ccb53258bc8958c0e25c05c4}
#set "exposure"=1
#set "brightness"=35{c7f7cb1468c0d02af358b3ce02b96b7aadc0ce32ccb53258bc8958c0e25c05c4}
#set "contrast"=10{c7f7cb1468c0d02af358b3ce02b96b7aadc0ce32ccb53258bc8958c0e25c05c4}
#set "saturation"=60
#set hue=10
#top-banner
#font /usr/share/fonts/truetype/msttcorefonts/arial.ttf
title "RasPi-Cam"
timestamp "{c7f7cb1468c0d02af358b3ce02b96b7aadc0ce32ccb53258bc8958c0e25c05c4}d-{c7f7cb1468c0d02af358b3ce02b96b7aadc0ce32ccb53258bc8958c0e25c05c4}m-{c7f7cb1468c0d02af358b3ce02b96b7aadc0ce32ccb53258bc8958c0e25c05c4}Y {c7f7cb1468c0d02af358b3ce02b96b7aadc0ce32ccb53258bc8958c0e25c05c4}H:{c7f7cb1468c0d02af358b3ce02b96b7aadc0ce32ccb53258bc8958c0e25c05c4}M:{c7f7cb1468c0d02af358b3ce02b96b7aadc0ce32ccb53258bc8958c0e25c05c4}S ({c7f7cb1468c0d02af358b3ce02b96b7aadc0ce32ccb53258bc8958c0e25c05c4}Z)"
jpeg 50
save /var/www/data/snaps/snap.jpg

Some settings required careful tweaking, since most webcams are optimized for indoor use. Although the settings above resulted in pictures of reasonable quality, I noticed that they were pretty much overexposed on bright sunny days. And they were far too dark at night. It turned out that the auto exposure function of my webcam is unable to deal with changing light conditions.

Therefore I did some research on how to change the settings dynamically, depending on time of day. It turned out to be a simple task using some python scripting.

Overclocking a Raspberry Pi

As you probably know, one can overclock the RasPi to 1 GHz without losing its warranty given that the temperature of the device does not reach more than 80 °C. My RasPi runs at 950 GHz, since it crashed with the highest possible settings. To do so, I’ve changed my /boot/config.txt as follows:

#uncomment to overclock the arm. 700 MHz is the default.
arm_freq=950
force_turbo=0

# for more options see http://elinux.org/RPi_config.txt
gpu_mem=128
gpu_mem_256=160
gpu_mem_512=316
cma_lwm=16
cma_hwm=32
core_freq=250
sdram_freq=450
over_voltage=6
avoid_safe_mode=1

A complete list of configuration options for the /boot/config.txt can be found on elinux.org.

Since more heat is generated by overclocking, I placed my RasPi into an enclosure lacking a lid. For better heat dissipation, I glued heatsinks to the ARM processor. You can check the CPU temperature with:

$ cat /sys/class/thermal/thermal_zone0/temp

Under idle conditions, the temperature on the overclocked Pi is about 36 °C, whereas my Pi within the Pibow without heatsink and default settings is running at 48 °C.

IMG_6077
RasPi in LEGO enclosure with heat sink.

The settings above also activate dynamic memory sharing for RAM and GPU. More RAM for the GPU will be automatically assigned when you’re starting the Xserver.

If you want to free more RAM, you can disable kernel modules if you don’t need them. For example, if you’re not going to use sound, blacklist the corresponding snd* modules in /etc/modprobe.d/raspi-blacklist.conf.

# blacklist spi and i2c by default (many users don't need them)

#blacklist spi-bcm2708
#blacklist i2c-bcm2708
blacklist leds_gpio
blacklist led_class
blacklist snd_bcm2835
blacklist snd_pcm
blacklist snd
blacklist snd_timer
blacklist snd_page_alloc
blacklist snd_rawmidi
blacklist snd_seq_device
blacklist snd_usb_audio
blacklist snd_hwdep
blacklist snd_usbmidi_lib

If you want to run your Pi 24/7, you may want to add watchdog support, which automatically resets your Pi on system errors. For installation of the watchdog do:

$ sudo modprobe bcm2708_wdog
$ echo "bcm2708_wdog" | sudo tee -a /etc/modules
$ sudo apt-get install watchdog

and edit few lines in /etc/watchdog.conf to

watchdog-device        = /dev/watchdog
max-load-1             = 24
temperature-device     = /sys/class/thermal/thermal_zone0/temp
max-temperature        = 75

The watchdog will be activated on next reboot.

Music Player Daemon (MPD) Workaround for the Firefox Minion Plugin

There are a lot of tutorials out there on how to install the music player daemon (MPD) on a Raspberry Pi. Therefore, I’ll not describe it here in detail. On a freshly installed Debian Wheezy it should work out-of-the-box. An “apt-get install mpd” and editing /etc/mpd.conf should do the trick.

However, if you wish to control MPD with your browser using the FireFox Minion Plugin, you’ll certainly face the problem that it’s configuration dialog for the server’s IP-address/ port number appears to be broken.

minion

Whatever you enter into the dialog will be ignored, and Minion will stay disconnected. It’s a bug, not a feature!

In order to set the IP-address and port number you have to type about:config into Firefox’ address bar and search for the string extensions.mpm.server.

minion1
Then, double-click on the entry and enter the desired IP:Portnumber.

Furthermore, depending on where you store your audio files (I keep them on a USB stick), file permissions can be an issue, if MPD is unable to see your files. Make sure that the folder containing the audiofiles is readable for the desired users.