Adding ROS Raspberry Pi 4B Camera

This post describes how to get the Raspberry Pi 4B camera working under ROS. Try following these steps to get it working on your Pi 4B-based robot too!

Where to Begin?

The basic config of the robot is:

The previous employed Ubiquity approach failed on Pi 4. So I fall back to trying to install similar to:,


The Details

Get the userland code:

git clone /home/ubuntu/userland


cd userland
./buildme –aarch64

The build appeared to succeed.

My quitter, lame attempt to see if it worked failed:


Command not found.


ubuntu@ubuntu-pi4:~/userland$ sudo find . -name raspicam

So the code appears to be there but is perhaps not getting built. Note the comment on ‘’…

“Whilst 64-bit userspace is not officially supported, some of the libraries will work for it.”

There might be a ray of hope here:

Trying it…

git clone

Step-by-step commands:

cd src/
git clone
cd userland/
git checkout 64bit_mmal
./buildme –aarch64
ls /opt/vc/bin/

find . -name

This now runs:

LD_PRELOAD=”/opt/vc/lib/ /opt/vc/lib/ /opt/vc/lib/ /opt/vc/lib/” /opt/vc/bin/raspistill -o cam.jpg

But gives errors:

mmal: Cannot read camera info, keeping the defaults for OV5647
mmalipc: mmal_vc_dump_client_components: mmal_vc_dump_client_components: 0 entries in use
mmalipc: mmal_vc_dump_client_contexts: mmal_vc_dump_client_contexts: 0 entries in use
mmal: mmal_vc_component_create: failed to create component ‘’ (1:ENOMEM)
mmal: mmal_component_create_core: could not create component ‘’ (1)
mmal: Failed to create camera component
mmal: main: Failed to create camera component
mmal: Camera is not enabled in this build. Try running “sudo raspi-config” and ensure that “camera” has been enabled

Fixing the Runtime Errors

So next… I added:


to ‘/boot/firmware/config.txt’.

And added:


to ‘/etc/udev/rules.d/10-vchiq-permissions.rules’.

sudo vi /etc/udev/rules.d/10-vchiq-permissions.rules
sudo usermod -a -G video ubuntu
sudo reboot
LD_PRELOAD=”/opt/vc/lib/ /opt/vc/lib/ /opt/vc/lib/ /opt/vc/lib/” /opt/vc/bin/raspistill -o cam.jpg
680 LD_PRELOAD=”/opt/vc/lib/ /opt/vc/lib/ /opt/vc/lib/ /opt/vc/lib/” /opt/vc/bin/raspivid -o video.h264 -t 10000

(Note: there are some messages to the console that don’t inspire confidence, but they seem to actually be harmless!)

export LD_LIBRARY_PATH=/opt/vc/lib
/opt/vc/bin/raspivid -o video.h264 -t 10000

sudo ln -s /opt/vc/bin/raspivid /usr/bin/raspivid
raspivid -o video.h264 -t 10000

(added ‘export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/vc/lib’ to .bashrc)

sudo apt install ffmpeg

Direct encode to .mp4:

raspivid -ih -t 0 -o – | ffmpeg -i – -vcodec copy test.mp4

Enable ROS raspicam_node

To enable raspicam_node, do the following steps:

cd catkin_ws/src/
git clone raspicam
cd ..
source devel/setup.bash
export LD_PRELOAD=”/opt/vc/lib/ /opt/vc/lib/ /opt/vc/lib/ /opt/vc/lib/”

rosrun raspicam raspicam_node _height:=1280 _width:=960

In another terminal:

rosservice call /camera/start_capture


With the above in place and working, getting the video presented in ROS is via standard practice.


If you run into problems, it would be best to start from a fresh install of Ubuntu/ROS, see:

Install ROS on Raspberry Pi 4B

Let me know your experience in the comments…

Leave a Reply

Your email address will not be published. Required fields are marked *