3.1.1 Photograph Module¶
In this kit, equipped with a camera module, let’s try to take a picture with Raspberry Pi.
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
ITEMS IN THIS KIT
You can also buy them separately from the links below.
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.
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.
const exec = require('child_process').exec; exec('libcamera-still -o test.jpg');
const exec = require('child_process').exec;
child_process module, which allows nodejs to perform various operations on child processes, including creating child processes to directly execute system commands.
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.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.