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.
I first tried gpiozero software application pinout to gather some information on the board.
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.
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.
>>>>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!
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.
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.
Top Comments