Note

Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.

Why Join?

  • Expert Support: Solve post-sale issues and technical challenges with help from our community and team.

  • Learn & Share: Exchange tips and tutorials to enhance your skills.

  • Exclusive Previews: Get early access to new product announcements and sneak peeks.

  • Special Discounts: Enjoy exclusive discounts on our newest products.

  • Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.

👉 Ready to explore and create with us? Click [here] and join today!

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.

../_images/photo1.png

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Raphael Kit

337

Raphael Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

Camera Module

BUY

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 Access for Raspberry Pi.

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.