element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
RoadTests & Reviews
  • Products
  • More
RoadTests & Reviews
Blog Riding The Rails with Raspberry Pi Zero 2W: Camera
  • Blog
  • RoadTest Forum
  • Documents
  • RoadTests
  • Reviews
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
RoadTests & Reviews requires membership for participation - click to join
  • PiZero2W
  • raspberry pi 2W
  • pi camera
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Related
Recommended

Riding The Rails with Raspberry Pi Zero 2W: Camera

colporteur
colporteur
7 Mar 2022

Welcome to the fifth of six blog posts in support of the Raspberry Pi Zero 2W Roadtest. The blog posts will explore different aspects of the product while attempting to engage the E14 Community members. Comments and questions to the blog posts are welcomed and encouraged. The blog posts will serve as the resources for assembling the RoadTest Review document.

The project objective is to pair a Raspberry Pi Zero 2W with a camera, assemble it on a HO scale model railroad car with a power source and stream or record video of the train in motion.

I can see the final station on the horizon. This is the part of the project that has to work or the application proposal is a bust. Can the Pi stream video over wifi?

Confusion Resolved

Before starting the camera exploration, let's resolve the confusion in blog three about the Pi hardware. The silkscreen on the board indicated Raspberry Pi Zero 2, Raspberry Pi 2021. No reference to a 2W. A command-line look at file /proc/cpuinfo of the Pi after boot and there is no doubt this board is sporting a quad-core processor of a PiZero2W.

image

I first tried gpiozero software application pinout to gather some information on the board.

image

I will assume since the board is new, the software doesn’t fully support the hardware, resulting in the picture. The hardware identified doesn't exist and has no model number.

Opening Camera Shot

Raspberry Pi is transitioning from a legacy camera software stack based on proprietary Broadcom GPU code to an open-source stack based on libcamera. Raspberry Pi OS images from Bullseye onward will contain only the libcamera-based stack. The application for the project indicated that the latest O/S, Raspberry Pi OS Lite Version: 11 (bullseye) would be installed along with the native camera software stack libcamera.

I have no experience using the libcamera software stack. I am going to use the documentation link as my reference source for the camera configuration.

The note below can be found in the getting started link of the camera on the  Raspberry Pi Documentation site.

Reasons to consider staying with an older OS and using the legacy Raspicam camera stack might include:
• It may perform better on Raspberry Pi 2 and Raspberry Pi Zero devices, as it offloads more to the GPU and is less dependent on the ARM cores.
• libcamera is still missing certain features, most notably Python bindings. Whilst this work is in progress, users who need a Python interface (such as Picamera) will have to stay with the legacy stack for the time being.

The recommendation to use the old camera software stack with Pi Zero devices is cause for concern. I'm going to assume they are talking about the single-core PiZero devices. Let's hope the multiple ARM cores in the PiZero2W will help with the heavy lifting needed to support the camera.

After getting the camera installed and post boot-up, I tried the recommended libcamera-hello. I received an error message. libcamera-hello is the equivalent of a "hello world" application for the camera. It starts the camera, displays a preview window, and does nothing else.

image


The camera hardware I am using is a few years old. Maybe it is not supported? After some head-scratching and further troubleshooting, I discovered the error message is a result of using the SSH connection. Man is that embarrassing! Of course, video over the ssh connection is not supported.

In my defence. Rarely do I connect a Pi to a monitor and use a local keyboard. Remote connection is my norm. I will take this as a lesson learned. Until I gain some more experience with the hardware, I’m going to use a keyboard and monitor attached to the PiZero2W to continue development.

image
>>>>adapter heaven<<<<<

I will reiterate my recommendation from blog four. Mr PiZero2W kit vendor, please include the video and USB adapters in the kit. I have them so the setup was easy. I'm confident they will improve the user experience when using the device. The correct adapters make the initial setup of the device so much easier.

With the Pi hardware connected to a monitor and keyboard, the libcamera-hello command output had no errors and for five seconds my mug was shown on the monitor.

Time for a happy dance!

image

I will mark this point in the development as a milestone. I have a working PiZero2W with camera hardware. Now for the video streaming feature.

Libcamera has five basic libcamera-apps. The site documentation is very good at explaining the use and operation. I spent a little time playing with the apps to gain some experience before proceeding. I took some pics and recorded some short videos. The libcamer-app developers have tried to provide the same functionality that was available in the original camera software stack. I found the apps easy to use and well supported in the documentation.

I'm confident I have a plan B now if I can't get streaming to work, the recording of video does work.

On With the Show

IT WORKS! I can stream video from the PiZero2W to my wireless laptop.

image

No stopping or jittering on the video. On the first test, the laptop was connected to the wired network. The same network that the wireless router is attached to. After switching the laptop to wireless, video streaming was still possible and of good quality.

There is a whole section in the documentation on Network Streaming. I found that not all the commands work as published. I'm speculating that maybe not all the camera functionality is available on a lite load of the O/S. After a google search, I loaded some additional software packages to see if I could get the missing pieces working. I did resolve some issues but created others. Unfortunately, the original commands that worked reliably before my software foray no longer worked after the software changes.

CRAP! I will spend time later troubleshooting those issues. The focus now is a streaming video. I need to stay focused on that. I blew away the Pi O/S that was installed and did a fresh installation of lite once again. A quick application of my O/S configuration tweaks and I was back to having a PiZero2W with consistent Network Streaming using the following commands.

On PiZero2W

libcamera-vid -t 0 --inline --listen -o tcp://0.0.0.0:<port>

On Ubuntu 18.04 Laptop

ffplay tcp://<ip-addr-of-server>:<port> -vf "setpts=N/30" -fflags nobuffer -flags low_delay -framedrop

I confess the operation is not neatly packaged for ease of use. Command-line options typed on a console are not ideal. Raspberry Pi development has been demonstrated through its history, over time things get worked on and improved. I have proven the device can stream video. I'm going to turn my efforts to the final assembly.

The sixth and final blog post is our final stop before the RoadTest Review. The model train hardware is ready. The model railroaders have been busy cutting, trimming and painting the rail cars that will hold the Pi hardware. The Pi hardware is complete with an O/S installed and a working camera software stack ready.

I have started designing and assembling the cable harnesses to supply power to the PiZero2W and control the servo that the camera is mounted to. I then realized a shortcoming, How do I turn the Pi off? Back to the drawing board to incorporate that feature.

I'm heading to the workshop to pull everything together. Looking forward to the possibility of capturing those Riding the Rails videos.

See you at the next stop.

  • Sign in to reply

Top Comments

  • colporteur
    colporteur over 1 year ago +1
    An update on this blog post. I noticed on the Raspberry Pi Camera documentation side a disclaimer about some of the commands. It seems the problems I experienced using some of the commands are not…
  • colporteur
    colporteur over 1 year ago in reply to no_carrier

    I'm at a fork in the road, so to speak on what is next. I've taken motivation from beacon_daves comments to pursue the ffmpeg avenue. I did the online course he indicated and have ordered books about using ffmpeg to stream video. I'm waiting for the delivery truck to arrive.

    I'm currently putting the finishing touches on the prototype and gathering information to make a final blog post in preparation for the the RoadTest Review submission.

    Your suggestion piqued my interest but raises some questions. If you attempted this sometime ago would it not have used the old camera software stack versus the libcamera software stack default in bullseye? My intent was to focus on the libcamera stack and only revert if I had issues. The camera working under the current operating system with the PiZero2W demonstrates the hardware is up to the challenge. That was an objective of mine in the RoadTest.

    The outline above is building stuff from scratch. I have done this but my limited knowledge is a short coming when problems occur. I appreciate that you shared your insight. I'm going to hold off pursuing it for now.

    Where the heck is that delivery truck?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • no_carrier
    no_carrier over 1 year ago

    I did this some years ago and successfully streamed at 720p/25ips in H.264. The streaming was done using RTSP and VLS as client.

    Here are the notes I took at that time : 

    INSTALL Gstreamer

    sudo apt-get install gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-tools libgstreamer1.0-dev libgstreamer1.0-0-dbg libgstreamer1.0-0 gstreamer1.0-omx-rpi gstreamer1.0-omx-rpi-dbg libgstreamer-plugins-base1.0-dev gtk-doc-tools


    INSTALL Camera driver

    sudo apt-get install git
    git clone github.com/.../gst-rpicamsrc.git
    cd gst-rpicamsrc
    ./autogen.sh
    make
    sudo make install
    gst-inspect-1.0 |grep rpicamsrc (to test that the camera works)


    INSTALL RTSP Server

    git clone git://anongit.freedesktop.org/gstreamer/gst-rtsp-server
    gst-launch-1.0 --version
    git checkout 1.10 (according to previous line)
    ./autogen.sh
    make
    sudo make install

    TEST

    ~/gst-rtsp-server/examples/test-launch "( rpicamsrc preview=false bitrate=2000000 keyframe-interval=15 ! video/x-h264, framerate=15/1 ! h264parse ! rtph264pay name=pay0 pt=96 )"

    (server listens to rtsp://rtsppicamera:8554/test)

    CONFIG Automatic startup

    sudo nano /etc/systemd/system/RTSPpiCamera.service
    [Unit]
    Description=RTSPpiCamera Process.
    After=network.target

    [Service]
    ExecStart=/home/pi/gst-rtsp-server/examples/test-launch "( rpicamsrc rotation=180 preview=false bitrate=10000000 keyframe-interval=15 ! video/x-h264, framerate=25/1 ! h264parse ! rtph264pay name=pay0 pt=96 )"
    WorkingDirectory=/home/pi/
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=RTSPpiCamera
    User=pi

    [Install]
    WantedBy=multi-user.target

    sudo chmod 644 /etc/systemd/system/RTSPpiCamera.service
    sudo systemctl daemon-reload
    sudo systemctl enable RTSPpiCamera.service
    sudo systemctl start RTSPpiCamera.service

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • colporteur
    colporteur over 1 year ago

    An update on this blog post. I noticed on the Raspberry Pi Camera documentation side a disclaimer about some of the commands.

    image

    It seems the problems I experienced using some of the commands are not unique.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • colporteur
    colporteur over 1 year ago in reply to beacon_dave

    Get test b_d, I will give it a try.

    I've been documenting some other tests I would like to perform once the assembly is complete. I'm curious about the battery life with wifi and the camera running. Going to perform a test on that to see what I get.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave over 1 year ago

    "I will assume since the board is new, the software doesn’t fully support the hardware, resulting in the picture. The hardware identified doesn't exist and has no model number."

    Not sure it will make a difference but you can pass pinout the revision code of the board rather than relying on autodetection.

    image

    Looks like 902120 is the revision code for the Zero 2 W

    image

    so pinout -r 902120 may or may not do something interesting...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube