Tuesday, May 21, 2013

Camera module not happy on overclocked Raspberry Pi

I got my camera module from Farnell last week.
Notification and delivery went very smoothly.
On Sunday (12/05/2013) I indicated my interest in the camera module on the Farnell website.
The next day, they sent me an email telling me the camera was now available for purchase.
And, just two days later, it was delivered right to my door.
If only, things were always like that.

The documentation for this module is excellent and provides in a very lucid way all you need to get started.

Connecting the camera ribbon cable is very easy although take note that about 3mm on metal contact wires still protrude above the connector even with a good contact.

However, operation didn't at first go smoothly for me.

First, running as my user the command

raspistill -o photo1.jpg
gave this error
failed to open vchiq instance
The command ran without error when I used sudo, however.
This error is referred to in this guide for installing Quake3 in Raspbian.
Interestingly, after I installed Quake3, sudo was no longer required to run the raspistill command.
Nevertheless, the first of the suggested solutions didn't work for me.
The second, which is the following
# chmod a+rw /dev/vchiq
did but apparently this is only a temporary fix until the next reboot.

The biggest problem, however, was that this command did NOT produce any file named photo1.jpg.
raspistill -o photo1.jpg
In general, a screen opened on my monitor showing the object to be photographed. However, it didn't close and acted like a CCTV system.
At other times, the screen froze and the only way out was to pull the plug.
Sometimes, the screen remained live but the Desktop underneath froze (the clock stopped, the CPU monitor stopped, and that's as much as I could see.

However, if I reduced the wait time by something like
raspistill -t 5 -o photo1.jpg
(just 5 milliseconds delay until taking the shot), now I got a photo.

The video command
raspivid -o video1.h264
was even more temperamental.
The only way I could get and video at all was to severely limit the length of the video. And we're talking of half-second videos which are unlikely to be in much demand.
The command I used was
raspivid -t 500 -o video1.h264
I had seen some forum posts about the high power consumption of the camera module (nearly 300 mA for the camera alone).
So, I tried all of the four PSU's that I have for my Pi.
None gave me any significant improvement.

Now, I run all of my OSes on the Pi overclocked.
Generally I use cpu_freq=875 with force_turbo=1
So, I commented out these lines in my /boot/config.txt and now the camera worked absolutely perfectly.

Now that it's working fine, I can do some experimentation.
There is a wonderful blog post on how to use the Pi camera to do time-lapse photography.
And, everything works perfectly.

While the time-lapse script in the post works perfectly, I used an abbreviated script for my own meagre attempts at time lapse.
This is my script which is shamelessly taken from the post:

#!/bin/bash

while [ true ]; do

sudo raspistill -t 10 -o /media/stills/$(date +"%d_%m_%Y_%H_%M_%S").jpg

sleep 16

done;
The /media/stills/ directory is where I mounted a 16GB usb key (plugged into one Pi's USB ports) to hold the huge number of photos that can result from time-lapse.
And the 'sleep 16' merely ensures that shots are taken about every 20 seconds.

For €25, this is a powerful addition to my RPi.











2 comments:

  1. Did you get a fix to this? I can't figure out why my Raspberry Pi is doing this.

    ReplyDelete