0% found this document useful (0 votes)
3 views16 pages

Tutorial

Uploaded by

anplixfz1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

Tutorial

Uploaded by

anplixfz1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

█ [Link].

com Welcome 1

Welcome
Thank you for choosing Freenove products!

Get Started

Please follow this tutorial to set up the camera.

Get Support

Encounter problems? Don't worry! Refer to “[Link]” or contact us.

When there are packaging damage, quality problems, questions encountering in use, etc., just send us an
email. We will reply to you within one working day and provide a solution.

support@[Link]

About

Freenove provides open source electronic products and services.

Freenove is committed to helping customers learn programming and electronic knowledge, quickly
implement product prototypes, realize their creativity and launch innovative products. Our services include:

⚫ Kits for learning programming and electronics


⚫ Kits compatible with Arduino®, Raspberry Pi®, micro:bit®, etc.
⚫ Kits for robots, smart cars, drones, etc.
⚫ Components, modules and tools
⚫ Design and customization

To learn more about us or get our latest information, please visit our website:

[Link]

█ Need help? Contact support@[Link]


2 Welcome [Link] █

Copyright

All the files provided in the ZIP file are released under Creative Commons Attribution-NonCommercial-
ShareAlike 3.0 Unported License. You can find a copy of the license in the ZIP file.

It means you can use these files on your own derived works, in part or completely. But not for commercial
use.
Freenove® brand and logo are trademarks of Freenove Creative Technology Co., Ltd. Must not be used
without permission.

TM

Other registered trademarks and their owners appearing in this document:

Arduino® is a trademark of Arduino LLC ([Link]


Raspberry Pi® is a trademark of Raspberry Pi Foundation ([Link]
micro:bit® is a trademark of Micro:bit Educational Foundation ([Link]

Need help? Contact support@[Link] █


█ [Link] Get Started 3

Get Started

Note (Important)

Please note that our FNK0056 prodcut, which comes with the camera model OV5647, is only compatible with
Raspberry Pi; while the product FNK0056B, with camera model IMX219, can work with both Raspberry Pi and
Jetson Nano.

This tutorial introduces the use of product FNK0056(B) on Raspberry Pi.


Product SKU Camera Model Work with Raspberry Pi Wrok with Jetson Nano
FNK0056 OV5647 Yes(this tutorial) No
FNK0056B IMX219 Yes(this tutorial) Yes

Step 1 What you will need

Raspberry Pi computer with a Camera Module port


All current models of Raspberry Pi have a port for connecting the Camera Module.

█ Need help? Contact support@[Link]


4 Get Started [Link] █

A Raspberry Pi Camera Module (Included in this kit)


FNK0056 OV5647 Camera Module FNK0056B IMX219 Camera Module

A Camera cable (Included in this kit)


Ribbon cable (15cm) for RaspberryPi 4B/3B+/3B/3A+/2B/1B+/1A+

Ribbon cable (15cm) for Raspberry Pi 5 /Zero 2 W/Zero W/Zero

Step 2 Assembly and Wiring

Wiring

Camera Side
1. Gently pull down the plastic clip.

Need help? Contact support@[Link] █


█ [Link] Get Started 5

2. Insert the cable and press back the click.


OV5647 IMX219
with Raspberry Pi 4B /3B+/3B
/3A+ /2B/1B+/1A+

with Raspberry Pi 5/Zero 2 W/


Zero W/Zero

█ Need help? Contact support@[Link]


6 Get Started [Link] █

Raspberry Pi Side
Ensure your Raspberry Pi is turned off.
1. Locate the Camera Module port.

2. Gently pull up on the edges of the port’s plastic clip.

3. Insert the Camera Module ribbon cable; make sure the connectors at the bottom of the ribbon cable are
facing the contacts in the port.

Need help? Contact support@[Link] █


█ [Link] Get Started 7

4. Push the plastic clip back into place.

Physical pictures with Raspberry Pi 4 and 5 as examples.


Raspberry Pi 4

Raspberry Pi 5

█ Need help? Contact support@[Link]


8 Get Started [Link] █

Assemble the camera support

M2*10
Screw

M2 Nut

Camera

M3*30
Standoff

M3*6
Screw

Need help? Contact support@[Link] █


█ [Link] Get Started 9

Step 3 How to control the Camera Module via the command line

To have the camera be detected successfully, you need to modify the configuration file to add the designated
camera driver.

Take the ov5647 camera as an example.


1. Open the [Link] file.
sudo nano /boot/firmware/[Link]

2. Disable the automatic camera detection function.


camera_auto_detect=0

3. Add the following instruction at the very bottom.


If your board is not Raspberry Pi 5, add the following content:
dtoverlay=ov5647

If it is Raspberry PI 5, add the following command.


dtoverlay=ov5647,cam0

Note:
1. if your camera is imx219, please change ov5647 to imx219.
2. If you actually connect the camera to cam1 instead of cam0, change cam0 to cam1.

█ Need help? Contact support@[Link]


10 Get Started [Link] █

4. Save the file and exit.


5. Reboot your raspberry pi.
sudo reboot

Before testing the camera, run the following command to see if the camera can be detected.
ls /dev/video*

/dev/video0 indicates the camera is connected.

If the camera cannot be detected with the above two commands, please check the camera wiring. You may
try reconnecting it to ensure good contact.
Always ensure that your Raspberry Pi is not powered before operating the camera wiring to avoid burning
them.

You can check that libcamera is working by opening a command window and typing:
rpicam-hello
You should see a camera preview window for about five seconds.

You can also enter the following command to capture an image with a resolution of 800 by 600. The image
is saved in the current directory path by default.
rpicam-jpeg –o [Link] –t 2000 --width 800 --height 600

If you have any concerns, please contact us via email: support@[Link]

Need help? Contact support@[Link] █


█ [Link] Get Started 11

Step 4 How to control the Camera Module with Python code

The Python picamera library allows you to control your Camera Module and create amazing projects.
Open a Python 3 editor, such as Thonny Python IDE:

Open a new file and save it as [Link].


Note: it’s important that you never save the file as [Link].
Enter the following code:
1 from picamera2 import Picamera2, Preview
2 import time
3 picam2 = Picamera2()
4 camera_config = picam2.create_preview_configuration()
5 [Link](camera_config)
6 picam2.start_preview([Link])
7 [Link]()
8 [Link](2)
9 picam2.capture_file("[Link]")
10 [Link]()
Or you can Open Terminal,
1. Download tutorial and code with the command:
git clone [Link]

2. Enter Raspberry_Pi folder with cd command.


cd ~/Freenove_Camera_Module_for_Raspberry_Pi/Raspberry_Pi

█ Need help? Contact support@[Link]


12 Get Started [Link] █

3. Run the code


python [Link]

The following script will:


1. Open the camera system
2. Generate a camera configuration suitable for preview
3. Configure the camera system with that preview configuration
4. Start the preview window
5. Start the camera running
6. Wait for two seconds and capture a JPEG file (still in the preview resolution)

In addition, you can set Preview window parameters,


The preview implementation takes exactly the same parameters:
•x - the x-offset of the preview window
•y - the y-offset of the preview window
•width - the width of the preview window
•height - the height of the preview window
•transform - a transform that allows the camera image to be horizontally and/or vertically flipped on the
display
All the parameters are optional, and default values will be chosen if omitted. The following example will place
an 800x600 pixel preview window at (100, 200) on the display, and will horizontally mirror the camera preview
image:
Open Terminal,
1. Enter Raspberry_Pi folder with cd command.
cd ~/Freenove_Camera_Module_for_Raspberry_Pi/Raspberry_Pi
2. Run the code
python camera_transform.py
Enter the following code:
1 from picamera2 import Picamera2, Preview
2 from libcamera import Transform
3 picam2 = Picamera2()
4 picam2.start_preview([Link], x=100, y=200, width=800, height=600,
5 transform=Transform(hflip=1))

Need help? Contact support@[Link] █


█ [Link] Get Started 13

6 [Link]()

The supported transforms are:


•Transform() - the identity transform, which is the default
•Transform(hflip=1) - horizontal flip
•Transform(vflip=1) - vertical flip
•Transform(hflip=1, vflip=1) - horizontal and vertical flip (equivalent to a 180 degree rotation)
It’s important to realise that the display transform discussed here does not have any effect on the actual
images received from the camera. It only applies the requested transform as it renders the pixels onto the
screen. We’ll encounter camera transforms again when it comes actually to transforming the images as the
camera delivers them. Please also note that in the example above, the start_preview() function must be called
before the call to [Link]() . Finally, if the camera images have a different aspect ratio to the preview
window, they will be letter- or pillar-boxed to fit, preserving the image’s proper aspect ratio.

Next use the camera to capture videos:


In Picamera2, the process of capturing and encoding video is largely automatic. The application only has to
define what encoder it wants to use to compress the image data, and how it wants to output this compressed
data stream.
The mechanics of taking the camera images that arrive, forwarding them to an encoder, which in turn sends
the results directly to the requested output, is entirely transparent to the user. The encoding and output all
happens in a separate thread from the camera handling to minimise the risk of dropping camera frames.
Here is a first example of capturing a ten-second video.
Open Terminal,
1. Enter Raspberry_Pi folder with cd command.
cd ~/Freenove_Camera_Module_for_Raspberry_Pi/Raspberry_Pi
2. Run the code
python camera_h264.py

█ Need help? Contact support@[Link]


14 Get Started [Link] █

Enter the following code:


1 from [Link] import H264Encoder
2 from picamera2 import Picamera2
3 import time
4 picam2 = Picamera2()
5 video_config = picam2.create_video_configuration()
6 [Link](video_config)
7 encoder = H264Encoder(bitrate=10000000)
8 output = "test.h264"
9 picam2.start_recording(encoder, output)
10 [Link](10)
11 picam2.stop_recording()

In this example we use the H.264 encoder. For the output object we can just use a string for convenience; this
will be interpreted as a simple output file. For configuring the camera, the create_video_configuration is a
good starting point, as it will use a larger buffer_count to reduce the risk of dropping frames.
We also used the convenient start_recording and stop_recording functions, which start and stop both the
encoder and the camera together. Sometimes it can be useful to separate these two operations, for example
you might want to start and stop a recording multiple times while leaving the camera running throughout.
For this reason, start_recording could have been replaced by:
1 [Link] = 'test.h264'
2 picam2.start_encoder(encoder)
3 [Link]()
and stop_recording by:
1 [Link]()
2 picam2.stop_encoder()

Need help? Contact support@[Link] █


█ [Link] Get Started 15

All the video encoders can be constructed with parameters that determine the quality (amount of compression)
of the output, such as the bitrate for the H.264 encoder. For those not so familiar with the details of these
encoders, these parameters can also be omitted in favour of supplying a quality to the start_encoder or
start_recording functions.
Thepermitted quality parameters are:
•Quality.VERY_LOW
•[Link]
•[Link] - this is the default for both functions if the parameter is not specified
•[Link]
•Quality.VERY_HIGH
This quality parameter only has any effect if the encoder was not passed explicit codec-specific parameters.
It could be used like this:
Open Terminal,
1. Enter Raspberry_Pi folder with cd command.
cd ~/Freenove_Camera_Module_for_Raspberry_Pi/Raspberry_Pi
2. Run the code
python camera_quality.py
Enter the following code:
1 import time
2 from [Link] import H264Encoder, Quality
3 from picamera2 import Picamera2
4 picam2 = Picamera2()
5 video_config = picam2.create_video_configuration()
6 [Link](video_config)
7 encoder = H264Encoder()
8
9 picam2.start_recording(encoder, 'low.h264', quality=Quality.VERY_LOW)
10 print(encoder._bitrate)
11 [Link](5)
12 picam2.stop_recording()
13
14 picam2.start_recording(encoder, 'medium.h264', quality=[Link])
15 print(encoder._bitrate)
16 [Link](5)
17 picam2.stop_recording()
18
19 picam2.start_recording(encoder, 'high.h264', quality=Quality.VERY_HIGH)
20 print(encoder._bitrate)
21 [Link](5)
22 picam2.stop_recording()

█ Need help? Contact support@[Link]


16 Get Started [Link] █

You can also check out the official documentation to learn more about picamera2:
[Link]
There are so many interesting examples for you to learn in picamera2.
The official library link is as follows:
[Link]

Need help? Contact support@[Link] █

You might also like