.. 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 [|link_sf_facebook|] and join today! .. _3.1.1_js: 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. .. image:: ../img/photo1.png :width: 800 It's definitely convenient to buy a whole kit, here's the link: .. list-table:: :widths: 20 20 20 :header-rows: 1 * - Name - ITEMS IN THIS KIT - LINK * - Raphael Kit - 337 - |link_Raphael_kit| You can also buy them separately from the links below. .. list-table:: :widths: 30 20 :header-rows: 1 * - COMPONENT INTRODUCTION - PURCHASE LINK * - :ref:`cpn_camera_module` - |link_camera_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 :ref:`remote_desktop`. **Step 2:** Open a Terminal and get into the folder of the code. .. raw:: html .. code-block:: cd ~/raphael-kit/nodejs/ **Step 3:** Run the code. .. raw:: html .. code-block:: 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** .. code-block:: js const exec = require('child_process').exec; exec('libcamera-still -o test.jpg'); **Code Explanation** .. code-block:: js 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 .. code-block:: js 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.