How to Set Up and Use VNC on Raspberry Pi: A Complete Guide for Remote Access
Sep 14, 2024

Why Use VNC on Raspberry Pi?
The primary advantage of using VNC with Raspberry Pi is the flexibility it provides. We can run the Raspberry Pi in "headless mode" (without a physical display) and still have full access to its graphical user interface (GUI). This reduces the need for additional hardware, making setups more affordable and efficient. Whether we’re a hobbyist developing projects, an educator managing a classroom full of Pis, or someone experimenting with IoT devices, VNC offers a user-friendly, customizable way to control and manage the Raspberry Pi remotely.

Remote access: Control your Raspberry Pi from anywhere without needing a separate monitor, keyboard, or mouse.
Integration: VNC is compatible with various operating systems (Windows, macOS, Linux), making it versatile for users with different setups.
Multiple Device Access: Several devices can connect to and control the Raspberry Pi simultaneously, making it useful in collaborative environments.
Step-by-Step Guide to Setting Up VNC on Raspberry Pi
1. Upgrade Raspberry Pi OS Bookworm (IMPORTANT STEP)
Open the terminal and run:
sudo apt-get update
sudo apt-get upgrade
sudo apt full-upgrade
For more information about this commands, visit:
https://www.sunfounder.com/blogs/news/raspberry-pi-update-essential-steps-for-a-secure-and-optimized-system
2. Enable VNC on your Raspberry Pi:
Open the terminal and run:
sudo raspi-config
Navigate to Interface Options > VNC and select Enable.


3. Reboot
Connect to Raspberry Pi Using VNC
Download and install VNC Viewer
https://www.realvnc.com/en/connect/download/viewer/

1. Open VNC Viewer tool on your computer
2. Go to File > New Connection
Complete VNC Server with your Raspberry Pi IP address

Raspberry Pi 5, Bookworm and RealVNC Connect
With the release of Raspberry Pi 5 and the transition to the Bookworm (Debian 12) operating system, the setup process for RealVNC Connect (previously RealVNC) has some adjustments compared to earlier versions.
Real VNC official stanament: https://help.realvnc.com/hc/en-us/articles/14110635000221-Raspberry-Pi-5-Bookworm-and-RealVNC-Connect#statement-0-0
At the moment, RealVNC Connect does not support Wayland for Linux systems. If we don't disable Wayland, when we connect to RealVNC Server on these OS we will see a blank/blank screen or a message stating "Cannot currently show the desktop", or find we cannot connect until there is a user logged in on the remote computer. The RealVNC Server GUI may also fail to load.
1. Open Terminal and run the command:
sudo raspi-config
2. Navigate to > Advanced Options, then select Wayland

3. Select X11

4. Reboot and connect to Raspberry Pi using VNC Viewer

Enhancing Your VNC Setup: Security & Performance
Set a VNC Password
We need to set a password that will be used to connect remotely:
1.Open Terminal and run the command:
Vncpasswd
2.Restart VNC Server
service vncserver-x11-serviced restart
Alternative VNC Password with VNC Connect:
1. Go to Options

2. Go to Security tab and select Autentication: VNC password

3. Select “Standard user” and set the Password then Apply the configuration.

RealVNC Cloud
If we want to access your Raspberry Pi remotely over the internet (not just on your local network), we’ll need to connect to RealVNC Cloud
1. Create a RealVNC account at RealVNC Connect.
2. Sign in to VNC Server on your Raspberry Pi:
Open VNC Server on your Pi (from the desktop, go to Menu > Preferences > Raspberry Pi Configuration > Interfaces, and ensure VNC is enabled).
Click the VNC icon in the taskbar, and choose Sign In. Enter your RealVNC email and password to sign in.

3. Access Raspberry Pi from Anywhere:
From VNC Viewer on another device, sign in with the same RealVNC account, and we’ll see your Raspberry Pi listed for remote access.
Solving Common VNC Issues on Raspberry Pi
Black or Blank Screen in Headless Mode
When we connect via VNC without a monitor, the screen appears black or blank.
Set a virtual resolution for the display if the Pi is in headless mode (no monitor attached):
sudo raspi-config
Navigate to Display Options > Resolution, and select an appropriate resolution such as 1280x720.
Alternatively, we can edit the /boot/config.txt file to force a specific resolution:
sudo nano /boot/config.txt
Add or uncomment the following lines:
hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=82
sudo reboot
Slow or Laggy VNC Performance
The remote desktop lags or freezes during use.
Network Quality: Ensure both the Raspberry Pi and the device we’re connecting from are on a fast and stable network. If using Wi-Fi, consider switching to Ethernet for a faster and more stable connection.
Change the VNC Encoding Settings:In the VNC Viewer, go to Options (cog icon) and adjust the encoding. ZRLE or Hextile encodings use less bandwidth but may sacrifice image quality for better performance.
Reduce Screen Resolution: If the remote desktop experience is slow, try reducing the resolution of your Raspberry Pi display (either in raspi-config or in the desktop settings) to lower the strain on the connection.
Conclusion
VNC is a powerful and flexible tool for remote access to your Raspberry Pi, allowing you to manage projects efficiently without the need for additional hardware. Whether you're working on a local network or accessing your Raspberry Pi from anywhere via the internet, VNC provides a seamless experience. By securing your connections and optimizing performance, you can ensure smooth remote operations. With the steps and tips outlined in this guide, you’ll be well-prepared to fully utilize VNC with your Raspberry Pi.