1

member

Easy Raspberry basics: Project 02d Raspberry PI camera module V2 and Node-RED - taking a picture

of Acoptex.com in Raspberry Pi 3

Raspberry basics: Project 02d

Project name: Raspberry PI camera module V2 and Node-RED - taking a picture

Tags: Raspberry, Raspberry camera V2, Raspberry PI camera module, Raspberry PI 3, Node-RED, node red, taking a picture

Attachments: template code

In this project, you need these parts :

1.Raspberry PI 3 model B 1 pc

2. Raspberry PI camera module V2 1 pc

3. Micro SD card with NOOBS and SD card adapter 1 pc

4. Micro USB power supply (2.1 A, max 2.5 A) 1 pc

 

TV or monitor and HDMI cable
Keyboard and mouse

 

5. TV or monitor 1 pc

6. HDMI cable 1 pc

7. USB keyboard 1 pc

8. USB mouse 1 pc

General

We will learn how to take pictures with Node-RED using the Raspberry Pi Camera Module V2.

Understanding the Raspberry PI camera module V2

The Raspberry Pi Camera Module v2 replaced the original Camera Module in April 2016. The v2 Camera Module has a Sony IMX219 8-megapixel sensor (compared to the 5-megapixel OmniVision OV5647 sensor of the original camera).

The Camera Module can be used to take high-definition video, as well as stills photographs. It’s easy to use for beginners, but has plenty to offer advanced users if you’re looking to expand your knowledge. There are lots of examples online of people using it for time-lapse, slow-motion, and other video cleverness. You can also use the libraries we bundle with the camera to create effects.

You can read all the gory details about IMX219 and the Exmor R back-illuminated sensor architecture on Sony’s website, but suffice to say this is more than just a resolution upgrade: it’s a leap forward in image quality, colour fidelity, and low-light performance. It supports 1080p30, 720p60 and VGA90 video modes, as well as still capture. It attaches via a 15cm ribbon cable to the CSI port on the Raspberry Pi.

The camera works with all models of Raspberry Pi 1, 2, and 3. It can be accessed through the MMAL and V4L APIs, and there are numerous third-party libraries built for it, including the Picamera Python library. See the Getting Started with Picamera resource to learn how to use it.

The camera module is very popular in home security applications, and in wildlife camera traps.

There’s also an infrared version of the camera (called Pi NoIR) which gives you everything the regular Camera Module offers, with one difference: it doesn’t use an infrared filter. This gives you the ability to see in the dark with infrared lighting.

You can read more about camera module here.

Understanding the Node-RED

You can read more about it here.

Understanding the Raspberry PI 3 model B

The Raspberry Pi 3 is the third-generation Raspberry Pi. It replaced the Raspberry Pi 2 Model B in February 2016.

Specification:

  • Quad Core 1.2GHz Broadcom BCM2837 64bit CPU
  • 1GB RAM
  • BCM43438 wireless LAN and Bluetooth Low Energy (BLE) on board
  • 40-pin extended GPIO
  • 4 USB 2 ports
  • 4 Pole stereo output and composite video port
  • Full size HDMI
  • CSI camera port for connecting a Raspberry Pi camera
  • DSI display port for connecting a Raspberry Pi touchscreen display
  • Micro SD port for loading your operating system and storing data
  • Upgraded switched Micro USB power source up to 2.5A

Signals and connections of the Raspberry PI 3 model B


Signals and connections of the Raspberry PI camera module V2

You can see on the back of ribbon cable one side has a piece of blue plastic and other has some traces on it. Line up traces on the ribbon cable with traces on the Raspberry PI 3 camera port. There is the tab which you can lift up and pull it by its edges. By doing that it will open up so you can insert the ribbon cable end with traces into the camera port. When it's in press tab to fix the ribbon cable.

Step by Step instruction

1. Installing Node-RED

  1. You need to have a Raspbian OS preinstalled in your Raspberry Pi 3.
  2. Connect the Raspberry PI camera module V2 to the Raspberry Pi 3 camera port (CSI camera port). Make sure that Raspberry PI 3 switched off.
  3. Connect Raspberry PI 3 board HDMI port and to your TV or Monitor HDMI port with HDMI cable.
  4. Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI 1,  etc).
  5. Plug in your USB mouse and USB keyboard to Raspberry PI 3 USB ports.
  6. Connect Micro USB power supply to Raspberry PI 3 board micro USB input.
  7. The Raspberry PI desktop will start up.
  8. Go to Raspberry icon-> Preferences -> Raspberry PI configuration
  9. Select Interfaces and make sure that the camera is enabled. If it’s not enabled, enable it and reboot your Raspberry PI 3 board to begin. We suggest to enable all settings and you will not need to come back to these configuration tool again.
  10. After reboot go to Raspberry icon-> Preferences -> Recommended Software
  11. Go to All programs and type NODE in left bottom corner. You will see the Node-RED. Make sure that Install is selected and press OK button.
  12. Press OK button. Congrats!! You have successfully installed Node-RED.
  13. We need to reboot the Raspberry Pi 3 now. Go to Raspberry icon-> Shutdown and select Reboot

2. Installing Node-RED dashboard

  1. The Raspberry PI desktop will start up after reboot.
  2. Go to Terminal.
  3. Use this command to stop Node-RED if it was automatically running on start up: node-red-stop
  4. Use this command to go to installation directory:  cd ~/.node-red
  5. Use this command to install new package: sudo apt-get install npm
  6. Use this command to install Node-RED dashboard: npm install node-red-dashboard
  7. Reboot your Raspberry Pi 3 to ensure that all changes take effect on Node-RED software - use this command: sudo reboot
  8. The Raspberry PI desktop will start up after reboot.
  9. Go to Terminal.
  10. You need to know your Raspberry Pi 3 IP address in order to access your video streaming web server. Use this command: hostname -I

  11. You will see Raspberry Pi 3 IP address. In our case it is 192.168.0.121.
  12. Run the commands: sudo apt-get update and sudo apt-get upgrade to make sure that you have all packages up to date.
  13. Go to Raspberry icon-> Programming -> Node-RED
  14. You should see a window displaying information about Node-RED starting up.
  15. Go to Web browser.
  16. Locate the address bar at the top and type: http://your_Raspberry_Pi_IP_address:1880/ui (in our case that is http://192.168.0.121:1880/ui) then press Enter button. This will display the Node-RED dashboard.   

3. Installing the Raspberry Pi Camera node

  1. On your PC go to web browser (Google chrome or Microsoft Edge). We are using PC with Windows 10.
  2. Locate the address bar at the top and type: http://your_Raspberry_Pi_IP_address:1880 (in our case that is http://192.168.0.121:1880) then press Enter button. You will see the Node-RED.
  3. Go to Main menu in the right top corner and select Settings.
  4. In User Settings select Palette and then select Install. Type  node-red-contrib-camerapi in search field.
  5. Press Install button.  The node will be installed.
  6. Reboot your Raspberry Pi 3 to ensure that all changes take effect on Node-RED software - use this command: sudo reboot

4. Choosing the pictures directory

  1. The Raspberry PI desktop will start up after reboot.
  2. Go to Terminal.
  3. Choose a directory where the pictures will be saved. You need to edit the settings.js file. Type the command: sudo nano ~/.node-red/settings.js (or sudo nano /root/.node-red/settings.js) as your Node-RED directory installation may be different)
  4. Scroll the file down and find the httpStatic setting, uncomment and type your desired directory to store the Raspberry Pi Camera picture, we selected: httpStatic: '/home/pi/Pictures/',
  5. When you’re done, exit and save the changes. Press Ctrl+X and then Enter buttons.

5. Starting Node-RED and creating the tab and group on Node-RED to add your dashboard widgets. 

  1. Use this command to start Node-RED: sudo node-red start

  2. Open a tab in any browser on your PC within the local network and type: http://your_Raspberry_Pi_IP_address:1880 (we have http://192.168.0.121:1880)
  3. You need to create a tab and a group on Node-RED to add your dashboard widgets. On right top corner of the Node-RED window you need to go to menu to select the dashboard.
  4. To add a tab to the user interface click on the +tab button.
  5. Once created, you can edit the tab by clicking on the edit button.
  6. You can edit the tab’s name and change its icon. Name: you can use any (we used Home); Icon:  you should use a name accordingly to the icon’s names here. Press Update button.
  7. To add a group to the tab, you need to click on the +group button.
  8. You can edit the created group by clicking on the edit button.
  9. You can edit its name, select its corresponding tab and change its width. Press Update button.
  10. Before creating the flow, make sure you have the camerapi takephoto node.
  11. Drag 3 nodes into the flow: template, camerapi takephoto and debug.
  12. Double click on the Template node to edit it. Copy and paste the template code. Make sure that correct group selected too - we have Dashboard Home. Press Done button.
  13. When a new photo taken Node-RED page updated automatically.
  14. Edit the camerapi takephoto node.
  15. Press Done button. Do not forget to add the right File Path to your node including the last forward slash – /home/pi/Pictures/ Every time you open the camerapi takephoto node, it will change the file default path to yes. So, make sure you select the right properties, every time you open the node. When you take a new photo, it will be saved on your chosen directory with the name photo1.JPEG. Every time you take a new photo, Node-RED overwrites the existing photo because they have the same name.
  16. Connect the nodes and press Deploy button.
  17. Open a tab in any browser on your PC within the local network and type: http://your_Raspberry_Pi_IP_address:1880/ui/(we have http://192.168.0.121:1880/ui/)
  18. You can take pictures now. Just press Take Photo button.

Troubleshooting

 

  1. If your image is not being displayed on the Node-RED UI, you can go the following URL and see if your httpStatic path was set properly: http://Your_RPi_IP_address:1880/photo1.JPEG
  2. If the Pi Camera does not take photos, double-check that the camera ribbon is well connected to your Pi’s CSI port. Also confirm that it’s enabled in your Raspberry Pi configuration menu. Go to Raspberry icon-> Preferences -> Raspberry PI configuration
  3. Open the camerapi takephoto node and ensure that it has the right file path.

 

Summary

We have learnt how to take pictures with Node-RED using the Raspberry Pi Camera Module V2.

Library

  • No libraries needed in this project

Script

  • Attached on the begining of this project


Other projects of Acoptex.com
Medium Basics: Project 083w Sipeed Maixduino board - Using PlatformIO IDE of Acoptex.com in Sipeed Maixduino 08-08-2019
Medium Basics: Project 083e Sipeed Maixduino board - Uploading MaixPy of Acoptex.com in Sipeed Maixduino 04-08-2019
Medium Basics: Project 083f Sipeed Maixduino board - Using MycroPython of Acoptex.com in Sipeed Maixduino 04-08-2019

Published at 12-09-2018
Viewed: 4339 times