CabCam Goes UV4L

This is the updated CabCam software package running UV4L. It operates similarly to MJPEG Streamer but it has a WebGUI for on the fly changes and it generally runs better with less bandwidth useage. If you have already setup the hardware for your CabCam skip to step 3 for the updated software. JMRI’s WebThrottle with video will be the next post.


We describe how to set up a small computer to stream cab view video from an HO locomotive. This allows remote operation of trains at local or remote layouts, optionally connecting it to video conferencing software like Google Meet or Zoom.


  1. Easy to set up and maintain.
  2. Easy to access the cab view via a URL or via conference software eg. Zoom or Meet.
  3. Distribute the setup to others for the betterment of the hobby.
  4. Provide a low latency video stream to enable remote control via Engine Driver/WiThrottle
  5. Keep the hardware within HO NMRA clearances.
  6. Use commonly available components and open-source software where possible.


Hardware: We are using one Raspberry Pi Zero W 2 per CabCam car. The original Zero works as well but is slower.

Camera: The Pi Zero Spy Camera works well for our purposes.

Software: The project uses Raspian Buster running UV4L conference streaming software on the CabCam car. This streams video from a URL on the local network. The video can be viewed locally or streamed to conference software via OBS and the OBS VirtualCam feature. This software runs Raspberry Pi OS Bullseye(Debian 11) 32bit.

Power: The Juiceb0x Zero is a “hat” for the Pi Zero. While the Pi Zero WH comes with the required header already installed, soldering is required to install header pins on the Juiceb0x Zero board.

Rolling Stock: The easiest approach is build a mounting sled out of styrene as shown below. With a little bit more work the setup can be installed inside a dummy engine, too.


How To

This section describes the setup in more detail. Some familiarity with Raspberry Pi and respective software management is helpful.

1. Gathering the hardware

You will need for the self contained unit.

For the cheaper unit running a battery bank:

Raspberry Pi Zero 2 W

Small Battery Power Bank Amazon has some as well.
160 Degree Pi Zero Camera
SDHC card 8GB or larger
USB charger with microUSB charging cable

2. Setting up the hardware

Solder the male header to the Pi Zero 2. Connect the camera to the Pi Zero 2 W. Solder the header pins to the Juiceb0x Zero per the instructions that come with it and attach it to the Pi Zero 2. Connect the battery to the Juiceb0x Zero. Connect the USB charger to the Juiceb0x Zero to charge the battery.

Never connect power to the USB ports of the Pi Zero 2 W while the Juiceb0x Zero is attached. 

For the cheaper version you need plug in the camera then plug the USB micro cable into the power bank and then into Pi Zero. Be mindful of your NMRA gauge, if you need to you can build a sled to hold the Pi Zero on its side so the USB cable is vertical.

3. Burning the image and setting up the software. Those skipping to this step, do this on a second SD card so you don’t mess up your MJPEG Streamer install.

Head over to the Raspberry Pi Foundations website and download the Raspberry Pi Imager and install and run it.

Once open you will be presented with the option to CHOOSE OS, click this and select Raspberry Pi OS(other) and select Raspberry Pi OS Lite(32-bit). Once that is chosen click the gear icon on the main page.

Check Set hostname and set your hostname to whatever you want. I generally chose cabcam# where # is the number of the camera on the layout, eg cabcam1, cabcam2 etc. You want to then mark on the camera hardware which one it is.

Check Enable SSH which automatically checks use password authentication. Below that you can set the username and password. Make sure you write these down or otherwise remember them or you will be making yourself a new image.

Check Configure wireless LAN and set your SSID(Network name) and Password for the wireless network you are going to be using. This MUST be a 2.4ghz network for the Pi Zero W and 2 W. Set your Wireless LAN country to your country abbreviation.

Check Set locale settings and find your time zone. Then if you use a different keyboard layout than US, go ahead and set that.

Optional: Uncheck enable telemetry.

Click SAVE

Click CHOOSE STORAGE and choose your SD card from the options. Then click WRITE. Once the image is written eject your SD card and place it in your Pi. Power the Pi on and give it a few minutes.

4. Logging in to the Pi

Find the IP address your Pi is using via your router and log in using ssh. You may get away with just typing cabcam#.local

Use the credentials you set in step 3.

On a Mac use Terminal. On Windows use PuTTY (you may have to download it)  and put in the IP of your Pi in the Hostname block. Try cabcam.local if you can’t find the IP. When you connect use the credentials you set in step 3.

Windows 1909 and up can use the command prompt with the command shh username@ipadressofpi to connect now so you don’t need putty.

On many networks the following also works:

ssh username@cabcam.local

5. Configuring the Pi

Once on the Pi command line type

sudo raspi-config

to enter the configuration page for the Pi. Arrow down to 3 Interface Options and open I1 Legacy Camera. Follow the prompts to enable legacy camera drivers so we can use UV4L. Exit the config utility.

6. Install UV4L.

Now we are going to configure the software to allow us to stream the cab POV and you can configure the settings you want.

First run the following command to add the UV4L repo to your install.

curl | sudo apt-key add –
echo “deb stretch main” | sudo tee /etc/apt/sources.list.d/uv4l.listing/uv4l_repo/lpkey

Then run sudo apt-get update, then run sudo apt-get upgrade and accept any prompts.

Run the following accepting any prompts.

sudo apt-get install uv4l uv4l-raspicam

sudo apt-get install uv4l-raspicam-extras

Now you are going to configure UV4L

sudo nano /etc/uv4l/uv4l-raspicam.conf

Set resolution to 640×480 20fps quality to 8(no joke it works great). You can increase this if you are only streaming localy over wifi.
I don’t suggest going much higher if you are going over the internet due to low upload speeds.

You may need to set rotation to flip the camera if your Pi camera is on its side, it goes by degrees so rotation = 180 will flip the image around 180 degrees.

Also find the following and uncomment them.

server-option = –connection-timeout=15

server-option = –enable-keepalive=yes

server-option = –keepalive-timeout=7

and make sure server-option = –max-streams=5 is uncommented and =5. The newer UV4L holds on to connections a little too long.

Run sudo reboot

Now it is time to test the stream.

Open a browser and head to http://IPofPi:8080/

Click MJPEG/Stills Stream and you should see the stream from your camera. If not turn off the Pi and check your cable seating. That is the issue 99% of the time.

The Internet uplink bandwidth at SVL is quite limited. For cab control with remote operators we found that SD resolution is sufficient and limits bandwidth demand. We are using a frame rate of 20 images per second. The stream doesn’t get smoother turning this up.

The camera stream is set to startup on boot.

Put your CabCam car on the front of a train, and run the train while watching the video stream in the browser.

Bernhard wrote down some thoughts on camera placement and car choice on his blog.

9. What’s Next?

To stream the video to remote operators we use OBS with the built in Start Virtual Camera option, configured with CabCam feeds. This is connected to Google Meet and can even stream to Youtube Live. Other video conferencing software like Zoom, Duo, Skype, etc. can be used, too. Remote operators join the video conference and use Engine Driver or WiThrottle to control trains via JMRI over a VPN. You can also run your train all from JMRI’s WebThrottle which will be covered in the next post. OBS will be covered after that because the real star of this show is the WebThrottle.

10. Things to Consider.

If you plan to have multiple cameras you should look into making an image of your SD card so you can burn them to other SD cards without having to do all the above steps. I will leave it up to you to Google “imaging raspberry pi SD card for (insert OS here).” Once you have the image backed up and burned to a new SD card you should run sudo raspi-config and change your hostname to increment your camera name.


Hardware: While we are using a Raspberry Pi Zero 2 W, any Pi with built-in Wifi will work.

Camera: Any compatible Raspberry Pi camera can be made to work. Possible options are the official Pi camera, the spy cameras, or other compatible cameras available from e.g. Adafruit.

Power: The Zero2Go board is an alternative to the Juiceb0xZero. However, the Zero2Go can’t charge the battery. In either case, do not power the Pi from the onboard USB while the power solution board is attached.

Some people had success with using a small form-factor USB power bank connected to a Pi Zero without additional hardware.


Over time we have made corrections to these instructions, or fine tuned settings. Below is a list of important revisions.

  • None Yet.

These Trains Look a Little Funny

A Raspberry Pi Zero 2 W gets a I2S microphone added in with a prototyping ribbon cable.

The for the past few decades model railroading has been looking more like 1970s Silicon Valley garages. Electronics bits strewn everywhere. On deck today is prototyping a microphone for our CabCams. It is turning out to be easier said than done.

Fall Virtual Open House is a Wrap

Another success, hopefully next year we get to do this in person as well.

If you joined us for our Fall Virtual Open House thanks for joining us and we hope you had a good time. If you would like to inquire about a remote operations or in person membership please email

The day started off with some JMRI troubles but after a quick pivot we got trains running and were able to get our trains back on schedule pretty quickly. As the day progressed it became apparent that even with our new Raspberry Pi Zero 2 W powered CabCams we could use more wireless access points to alleviate some issues with the small antenna on the Zero 2.

Below is our live stream from the day.

And now for some photos.

One of our remote engineers rolls past Ebbetts Pass in Western Pacific 759.
The same engineer headed across the bridge over the village of Eagle. The residents recently got a major stretch of their main road repaved.

A different remote engineer pilots Northern Pacific 6504 past the orange groves of Fremont and Farmer Jensen’s produce.

Norfolk Southern 9-1-1 highballs past one of SVL’s LCC signals in Jacksonville.
A meeting of eras. NS 9-1-1 and NP 6504 have a meet in Jericho. Meetings like these can be pretty exciting as a remote engineer. Due to a limitation of the technology you get the prototypical cab experience from our CabCams.
A view from the aisle with some of the hardware we use to make these streams exciting. While I had stepped away the SVL helicopter’s battery died (gimbal battery that is).
The sun has set over Silicon Valley Lines. We have one of, if not the only NCE Layout Lighting setups in the wild. It is a bit blue but this allows both local and remote engineers to get a bit of nighttime running but not be completely in the dark.
You can see the NCE light boards in this shot from Fryton as a train waits on the siding for one of our hotshot remote trains to pass.
An overhead shot of Tracy. Tracy is modeled after mid century Illinois and is the work of member John Donovan. He has been working on Tracy for 20+ years.
Another shot of Tracy.
A billboard for our local model railroad shop, they are extending their market all the way to Illinois.
The round-end of an illustrious Daylight is poking out of the Bayshore passenger facility.
Peering through the windows into the Bayshore roundhouse, seeing the side of SP 4349.
Another shot through the windows, this time seeing the rear of SP 4349 and the side of Penny 6200.
A shot of the Bayshore engine facility and the greater town on the left.
A young remote engineer gets ready to take our subway train out for a run.
The Subway train scoots along while the truck awaits a clear signal to leave.
Cars for the SVL’s Pathfinder wait for their next group of passengers to eagerly board in Nowheres.
Gamers & Thrones is our newest industry on the layout and busy at work 24/7 (hence the bright lights).

Well that is all for now, keep an eye on our events page for the next virtual open house and hopefully our summer in person open house. If you subscribe to our YouTube you should get notified of all our live streams.

Thanks for joining us!