The Raspberry Pi camera - part 1 - James Hughe

The Raspberry Pi camera - part 1 - James Hughes, Mag Pi 2013 July isses

http://www.themagpi.com/en/issue/14

A few weeks ago, the Raspberry Pi Foundation launched their first peripheral, a 5MP camera. Priced at $25, the same price as the model A, it’s a very small PCB on which is an Omnivision OV5647 camera module. It connects to either the Model A or Model B Raspberry Pi using a 15cm 15 way ribbon connector.

Over the course of this series I will take you through initial connection of the camera to your Raspberry Pi and will show you some of the basic commands used to take both still and video
imagery. At the end, some of the more sophisticated features will also be explained. Not every option will be covered (new options are being added all the time so it’s difficult to keep up) but hopefully this article will give enough information for you to be able to cover most image taking tasks. Firstly though, a description of how the camera module came to be...

History

From its first launch the Raspberry Pi has had a connector on it to attach a camera to the GPU (the VideoCore 4 Graphics Processing Unit on the Raspberry Pi). This connection uses the CSI -2 electrical protocol and is a standard used in most mobile phones. It is an extremely fast connection, which on the Raspberry Pi is capable of sending 1080p sized images (1920x1 080 x10bpp) at 30 frames per second,
or lower resolution at even higher frame rates. It had always been intended at some point to release a camera module that could use this connection, as the ability to stream high speed video data through the GPU without any interaction with the ARM processor would always make the camera much more efficient than any USB attached webcam. I t would also enable the use of the GPU’s ability to encode H264 video,or JPEG images in hardware.

It turns out that productising a tiny PCB like the camera board is not a quick task! The prototype
was re-designed to remove some unnecessary components, but more importantly, to move the
camera crystal, used for timing, to the PCB itself.

Electromagnetic compatibility (EMC) testing had shown that the 25Mhz clock provided by the GPU caused too much interference as it passed up the ribbon cable to the PCB. Adding a crystal to the PCB itself stopped this interference. A couple more board designs later, to help with production line manufacture and testing, and eventually, about a year after the first prototypes, the production board was ready.

Meanwhile, work had been ongoing to write a couple of applications to make use of the camera, to update the GPU firmware to support the camera, and to improve the camera tuning as the basic tuning already in place had a number of obvious defects.

Camera tuning is a complex task, which has been covered on the Raspberry Pi website, so I won’t repeat it here. Suffice it to say, the end results are well worth the extra effort put in by David Plowman while at Broadcom. Thanks David.

So, with the history out of the way, let’s take a look at getting your camera going.

Setting up

Firstly, it’s important to start with a warning.

Cameras like these are static sensitive. You should earth yourself prior to handling the PCB (a sink tap/faucet or similar should suffice if you don’t have an earthing strap).

There are only two connections to make, the ribbon cable needs to be attached to the camera PCB and the Raspberry Pi itself. You need to get it the right way round or the camera will not work. On the camera PCB, the blue backing on the cable should be away from the PCB, and on the Raspberry Pi it should be towards the ethernet connection (or where the ethernet connector would be if you are using a model A).

Although the connectors on the PCB and the Pi are different, they work in a similar way. On the Raspberry Pi, you need to pull up the tabs on each end of the connector.

I t should slide up easily, and be able to pivot
around slightly. Fully insert the ribbon cable into
the slot, ensuring it is straight, then gently press
down the tabs to clip it into place. The camera
PCB itself also requires you to pull the tabs away
from the board, gently insert the cable, then push
the tabs back.
The PCB connector is a little more awkward than
the one on the Pi itself. There is a video at
http://youtu.be/GImeVqHQzsE which shows the
connections being made.
So, we now have the hardware all attached, we
now need to make sure we have the correct
software installed. As explained above, there are
some command line apps to install, and a
firmware upgrade with the camera driver and
tuning to install. This process may not be
necessary in future as newer distro’s are

released which already contain the required files.
To update the firmware, libraries and
applications, execute the following instructions
on the command line.
sudo apt-get update
sudo apt-get upgrade
Now you need to enable camera support using
the raspi-config program you will have used
when you first set up your Raspberry Pi.
sudo raspi-config
Use the cursor keys to move to the camera
option and select enable. When you exit raspiconfig
it will ask to reboot. The enable option will
ensure that on reboot the correct GPU firmware
will be running (with the camera driver and
tuning), and the GPU memory split is sufficient to
allow the camera to acquire enough memory to
run correctly. Running a camera and associated
encoder does take up a big chunk of memory, as
the images are large, and there needs to be at
least two of them in memory at any time in order
to provide a double (in some cases triple) buffer
which prevents 'tearing' of images during display.
Checking it works
OK, we have connected the hardware, and
installed the software. Now we need to see if it is
all working correctly! The quickest way is just to
type in
raspistill -t 5000
This runs the stills capture program for 5
seconds (or 5000 milliseconds. Note that all
times used are in milliseconds). You should see
the whole display replaced with a moving image
of whatever the camera is looking at. I f you don’t
see the preview appear, or there are error
messages displayed, go straight to the
Troubleshooting section at the end of the article!
So, what can it do?
As with any camera, it can work in two ways. We
can capture still images, just like a camera, or we
can capture video, like a camcorder. The two
demo applications provided handle these tasks
separately. Although it would be quite possible to
combine them into one application, that makes
the code more complicated, and as demo code a
lot of effort was put in to make it as easy to
understand as possible. As an aside, the C
language source code for the applications is
publicly available from the Foundation's github
repository. Anyone is welcome to play around
with it and alter it for their particular purposes.
The code is well commented and uses the
Doxygen commenting scheme so you can
produce HTML documentation directly from the
source code.
So, on to the apps themselves. They are
command line applications, and do not need to
be run from a desktop environment since the
preview output from the apps is superimposed
over the top of any desktop or console being
used. Typing just the name of the application, or
adding --help or -? to the command line will
produce a list of all the available options. The list
is quite long, so you may want to pipe the output
into ‘less’ so you can scroll up and down to read
it.
raspistill | less
raspivid | less

Basic options
Both applications use the -t option to specify the
length of time in milliseconds they should
continue running.
So “raspistill -t 3000” will run the camera for 3
seconds.
In the stills case, and if a filename is specified,
the capture of the still will take place at the end of
the time period. In the video case, and again if a
filename is specified, the capture starts straight
away and will be as long as the time period.
To specify the filename of the output file, you use
the -o option. The following command runs the
camera for 2 seconds and at the end of the
period will take a still image, saving it to the file
image.jpg.
raspistill -o image.jpg -t 2000
This command will do the same but will save a 2
second H264 video file called video.h264
raspivid -o video.h264 -t 2000
You don’t need to specify a filename for the
output - if you don’t then no capture is done, but
the preview will still be run for the specified time.
I f you don’t specify a time, then 5 seconds is
used as a default.
The following will take a picture after 5 seconds.
raspistill -o image.jpg
So we have made some files, but how do we see
what they look like? Well, to view JPG images,
the FBI program is quite useful. You can install it
quickly using:
sudo apt-get install fbi
Then you can easily display your JPG images,
zoom in and out (use - and +) etc.
fbi image.jpg

To view video, you can use the already installed
omxplayer.
omxplayer video.h264
Preview options
You can specify whether you want the preview
disabled (-n), or whether it is to appear full
screen (-f) or in a window (-p). You can also
specify what opacity (-op) the preview window is
to have (so you can see the desktop underneath
if necessary).
To display the preview in a window at position
1 00,1 00, width 500, height 400 and at 50%
opacity (0-transparent to 255 -opaque), enter:
raspistill -p 100,100,500,400 -op 128 -o
image.jpg
To disable preview completely, enter:
raspistill -n -o image.jpg
Join us in issue 1 5 of The MagPi where some of
the more advanced features will be discussed!
Troubleshooting
I f your camera is not working, there are a number
of things to check to ensure it is set up correctly.
1 ) Are the ribbon connectors all firmly seated and
the right way round? 2) Is the camera module
connector firmly attached to the camera PCB?
3) Have you run sudo apt-get update, sudo aptget
upgrade? 4) Have you run raspi-config and
enabled the camera?
So, if things are still not working, try the following:
Error : raspistill/raspivid not found. This
probably means your update/upgrade failed in
some way. Try it again.
Error : ENOMEM displayed. Camera is not
starting up. Check all connections again.
Error : ENOSPC displayed. Camera is
probably running out of GPU memory. Check
config.txt in the /boot/ folder. The gpu_mem
option should be at least 1 28.



LPC1114 

http://tech.munts.com/MCU/Frameworks/RaspberryPi/expansion/LPC1114/
...

I/O Processor


An I/O Processor is simply a separate computer
dedicated to I/O operations, usually acting as a slave
to the “main” or “real” processor. The I/O processor
runs its own software, separate from the main
processor. Depending on the implementation, the I/O
processor software may or may not be alterable from
the main processor.

The I/O processor idea is not new. The IBM 7094
mainframe computer of 1962 could use a 7044
computer for all I/O. Processing was performed on
the 7094 and I/O done on the 7044. Even the original
IBM PC, released in 1981, had an 8048 8-bit
microcontroller in the keyboard to handle key press
timing. Today, the I/O processor idea has been
pushed all the way down to single chip systems: The
NXP LPC4300, itself a single chip ARM Cortex-M4
microcontroller, includes a separate ARM Cortex-M0
microcontroller, for real time processing, on the same
chip.

...


Make a low cost GPIO expander - Derek Campbell, Guest Writer, MagPi

Do you want to connect electronics to your
Raspberry Pi but are worried about overloading
or damaging the GPIO (General Purpose Input
Output) pins? Say "Hello! " to the GuzuntyPI -SB.
Guzunty is an Open Source, Open Hardware
addon you can easily build yourself. This tiny
little board will protect your Raspberry Pi while
you learn, but it can do so much more.
The Guzunty is programmable using ‘cores’.
These files can handle repetitive tasks that slow
down the Raspberry Pi's CPU and they can
provide access to 25 more input/output pins than
on the GPIO alone. Take it to the next level and
learn to program a core to do new tasks yourself.
Protecting your Raspberry Pi
As standard, no Raspberry Pi signals are directly
brought out to the pins on the top side of the
Guzunty, so it is almost impossible to feed
damaging voltages into your Raspberry Pi.
Instead, all signals pass though the chip at the
heart of this design, a Xilinx XC9572XL.
The XC9572XL is a Complex Programmable
Logic Device or CPLD for short. Don’t worry
about the word ‘Complex’ in the name, the
Guzunty makes it easy. The CPLD is tolerant of 5
volt signals which would damage your Raspberry
Pi, so you can interface with more kinds of
external devices, including Arduino.
NOTE: The CPLD will be damaged by voltages
greater than 5.5 volts. You should be especially
aware that mains voltages are dangerous and
need special isolation circuitry. However, if you
should make a mistake and fry the CPLD, a
replacement chip can be purchased
inexpensively and swapped into the socket.
Input / Output expansion
The CPLD is programmable, but unlike a
computer program, a CPLD program defines
hardware logic. To provide I /O (Input / Output)
expansion, we program the CPLD to provide a
Serial Peripheral Interface (SPI ) on four of its
general purpose I /O pins.
The System On Chip (SOC) of the Raspberry Pi
has SPI , on GPIOs 8, 9, 1 0 and 1 1 . We can thus
easily make the Raspberry Pi send data to the
...

Please visit https://github.com/Guzunty/Pi/wiki to
find example cores and the code to drive them.



Raspberry Pi operating systems: 5 reviewed and rated By David Hayward from Linux Format Issue 169  May 9th 2013

ROUNDUP A sweet selection of tasty Raspberry Pi distros

By David Hayward from Linux Format Issue 169  May 9th

http://www.techradar.com/news/software/operating-systems/raspberry-pi-operating-systems-5-reviewed-and-rated-1147941

...

The Raspberry Pi phenomenon appears to go from strength to strength; like a runaway train, it's ploughing ahead and forging itself a place in the record

books.

It's hardly surprising - the hardware alone is developed perfectly for the goals of the Raspberry Pi Foundation, the pricing is pitched perfectly, and

having the unique versatility of Linux as the operating system seals the deal nicely.

Most buyers, once they get their hands on their new RPi, make a move towards the official Raspberry Pi site and follow the getting started instructions

therein; the end result is the user running Raspbian "Wheezy", the Foundation's recommended operating system, creating, learning and programming, and

strapping the poor wee beast onto a weather balloon and sending it to the outer edge of the atmosphere.

Raspberry Pi tutorial: how to do more

What many RPi users don't realise, though, is that there's a wealth of other operating systems available for their beloved Pi. We thought, therefore, that

those users who aren't aware of these other sweet toppings for the Raspberry Pi need to be informed, and what's more, they need to have a chocolate box

selection presented to them.

How we tested...

The Raspberry Pi comes in two major flavours these days: the original 'B' model version 1, which has 256MB of memory, and the much newer model 'B' version

2, which now comes with 512MB. Therefore, to get a true all-round perspective, we took the time to install the operating systems on a 4GB SD card on both

the new 512MB, and the older 256MB model Bs.
The areas we're looking at are installation, default software, media playback (out-of-the-box), looks and usability, the community behind the OS and their

respective attitudes toward software freedom. Basically, the very stuff that makes a Linux user decide on what system to use.
We also want to gauge this from the point of view of someone who's not as familiar with Linux as others are, so they can jump into the project without too

much hassle, and not end up leaving it feeling disheartened.

Our selection

Raspbian
Risc OS
Plan 9
Android
Arch
...

How user-friendly are they?

The Raspberry Pi has, as we all know, endeared itself to the next generation of computing wizards, but how usable are our selection of operating systems?

It's all fine and well offering the next generation the tools to become more experimental with computing, but if the task of getting the hardware talking to

the user in a human way becomes too difficult, then those users could well leave the project and never return.

In this instance, we're targeting the younger generation, and how they will cope with the OSes on test. For this, we recruited an 11-year-old and a 10-year old, Daniel and Hannah, to set up the operating systems for us.

Raspbian and Risc OS came out on top, being easy to get up and running and use. Android left a bad taste in their mouths, as did poor old Plan 9. Arch drew blank looks that brightened up after a bit of work.

In the words of Daniel, "Raspbian rules!", whereas Hannah enjoyed the look and feel of Risc OS, "Risc OS looks much nicer." There we have it. The youth of today hath spoken!

Verdict

Raspbian - 5/5

Risc OS - 5/5

Plan 9 - 2/5

Android - 2/5

Arch - 3/5

.END


No comments:

Post a Comment