3.1.1 Photograph Module¶
Introduction¶
In this kit, equipped with a camera module, let’s try to take a picture with Raspberry Pi.
Required Components¶
In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:
Name |
ITEMS IN THIS KIT |
LINK |
---|---|---|
Raphael Kit |
337 |
You can also buy them separately from the links below.
COMPONENT INTRODUCTION |
PURCHASE LINK |
---|---|
Experimental Procedures¶
Step 1: Go into the Raspberry Pi Desktop. You may need a screen for a better experience, refer to: Connect your Raspberry Pi. Or access the Raspberry Pi desktop remotely, for a detailed tutorial please refer to Remote Desktop.
Step 2: Open a Terminal and get into the folder of the code.
cd ~/raphael-kit/nodejs/
Step 3: Run the code.
sudo node camera.js
After the code runs, the camera will take a photo. Now you can see the photo named test.jpg
in current directory.
Code
const exec = require('child_process').exec;
exec('libcamera-still -o test.jpg');
Code Explanation
const exec = require('child_process').exec;
Import the child_process
module, which allows nodejs to perform various operations on child processes, including creating child processes to directly execute system commands.
Note
About this module, please refer to: https://nodejs.org/api/child_process.html
exec('libcamera-still -o test.jpg');
After enabling the Camera function, you can directly use the command libcamera-still -o test.jpg
to capture photos in the terminal. We can also use the method provided by the child_process
module child_process.exec(cmd, [options] , callback)
to create child processes to run system commands.
By adding loop and delay functions, we can also achieve the effect of timing photos or time-lapse video.