Hostingheaderbarlogoj
Join InMotion Hosting for $3.49/mo & get a year on Tuts+ FREE (worth $180). Start today.
Advertisement

How to Take Raspberry Pi Screenshots With VNC

by
Gift

Want a free year on Tuts+ (worth $180)? Start an InMotion Hosting plan for $3.49/mo.

With a picture you can paint a thousand words and, as a tool for teaching anything relating to computers, a screenshot is an effective way of getting across ideas or information. 

In this tutorial I'll show you how to take screenshots on a Raspberry Pi.

Virtual Network Computing

VNC stands for Virtual Network Computing and is a method of graphical desktop sharing to remotely control another computer. 

Virtual Network Computing is independent of platform, thus it is possible to use a Mac to remotely control a Raspberry Pi. Or you could to the same from a Windows PC or a Linux box.

VNC allows the keyboard and mouse of Computer A to control Computer B which relays back the graphical user environment, GUI, to Computer A over a local-area or wide-area network.

Install VNC on a Raspberry Pi

If you have not already done so, install Raspbian on an SD Card. Instructions on how to do this are in the How to Install NOOBS on a Raspberry Pi With a Mac tutorial.

Once you have created an SD Card with Raspbian, or NOOBS, insert the SD Card into the Raspberry Pi. Connect the Raspberry Pi to a keyboard, mouse, monitor and power.

Switch on the power to boot the Raspberry Pi and boot into Raspbian

SSH From a Mac

Using SSH Secure SHell to access a Raspberry Pi from a Mac
Using SSH (Secure SHell) to access a Raspberry Pi from a Mac

If you have already enabled SSH, on the Pi, it is possible to use Terminal on the Mac to log into the Raspberry Pi command line by entering the following command in Terminal:

ssh pi@[IP address of the Pi]

Command Line Interface on the Pi

Installing tightvncserver on the Raspberry Pi
Installing tightvncserver on the Raspberry Pi

If you are still at the command line, enter the following commands. If you are in the graphical user environment, first launch LXTerminal to bring up the command line so that you can enter the following commands:

sudo apt-get update
sudo apt-get install tightvncserver

Then allow the software to be installed from the software repository.

Starting VNC

Once the tightvncserver software has finished installing, you need to run the software by entering the following command on the command line:

tightvncserver
Enter a password
Enter a password

As this is the first time that tightvncserver has been run on the Raspberry Pi, it will prompt you to enter a password. 

The password that you enter will be used to authenticate remote VNC clients that try to connect to the Raspberry Pi. You must enter a password at this stage. Make a note of it.

Enter a view-only password if required
Enter a view-only password, if required

You will then be asked if you wish to enter another password that the remote viewer will need to use in order to view the Raspberry Pi desktop, ie: a password that you need to enter everytime you connect.  You can decline this one if you wish.

Change the VNC Screen Resolution

If you wish to run the Raspberry Pi at a particular screensize, for the VNC server, you can do so by entering a command that configures the port number and the screen resolution.

Changing the resolution of the Raspberry Pi desktop
Changing the resolution of the Raspberry Pi desktop

Examples of the command that you can enter are:

vncserver :1 -geometry 1440x900
vncserver :1 -geometry 1600x900

Where 1 is the port number 5901, 2 is 5902, 3 is 5903 and so on.

If the tightvncserver is already running, you will need to stop it before running one of the commands, above, to change the resolution.

Provided that you kill the server, each time, you can change the resolutions displayed.

Raspberry Pi desktop at 1024x768 pixels
Raspberry Pi desktop at 1024x768 pixels

Changing the aspect ratio and pixel resolution, of the Pi, is possible.

Raspberry Pi desktop at 1600x900 pixels
Raspberry Pi desktop at 1600x900 pixels

Stopping VNC

If, at any point, you wish to stop the VNC server running, enter the following command:

tightvncserver -kill :1

Determine the Raspberry Pi’s IP Address From a Mac

In order to determine the IP address of a Raspberry Pi on the local area network, you will need to know the MAC (Media Access Control) address of the Raspberry Pi.

If you know the MAC address of the Pi you can find the IP address from Terminal
If you know the MAC address of the Pi, you can find the IP address from Terminal on the Mac

Provided that you know the MAC address, open Terminal and enter the following commands:

ifconfig | grep broadcast
arp -a | grep :

This creates a list of IP addresses that are currently being used on the local area network. It's a case of matching the known MAC address to the IP address.

Make a note of the IP address. You'll need this, later.

Determine the IP Address of the Pi With a Mac App

If you do not know the MAC address of the Raspberry Pi, don't want to use the command line interface, CLI, or just prefer using a graphical interface, it is possible to download an app to do the job for you.

Either google for an IP address scanning app, or visit the Mac App Store, to download and install a network scanning app.

Scanning for IP addresses with IP Scanner
Scanning for IP addresses with IP Scanner

My app of choice is IP Scanner which scans for devices and presents the results in an easy to understand way. 

Note, depending on which version of IP Scanner you download, you will be limited to the number of devices that can be scanned on the network. The free version of the software will only scan for six devices.

Make a note of the IP address. You'll need this, later.

Determine the IP Address of the Pi From the Pi

Using ifconfig on the Raspberry Pi to determine the device IP address
Using ifconfig on the Raspberry Pi to determine the device IP address

In order to access the Raspberry Pi from another computer,  the IP address of the device needs to be determined.

To determine the IP address of the Pi, enter the following command from the command line interface, or LXTerminal if you are in the graphical user interface:

ifconfig

The IP address of the Raspberry Pi is displayed on the second line, in this example as 

inet addr:10.0.1.33

Make a note of the IP address. You'll need this, later.

Install a VNC Client on the Mac

Either google for or download a VNC client, sometimes called a VNC Viewer, from the Mac App Store.

The VNC viewer that I use is ScreenSharingMenulet which is available from the Mac App Store less than the price of a coffee. The app sits in the menu bar for quick access to other machines on the network.

Configure the VNC Viewer

Launch the ScreenSharingMenulet app and click on its icon on the menu bar.

Configuring the VNC viewer
Configuring the VNC viewer
  • Navigate to ScreenSharingMenulet icon > Preferences > ScreenSharingMenulet
  • Click My Computers
  • Click the + symbol and enter the IP address in the Host column. 
  • Enter a meaningful name, I went with raspberrypi, in the Name (optional) column 
  • Enter 5901 in the Port column.

To exit, click General and then the red dot in the top left of the window.

Remote Access the Raspberry Pi

Using ScreenSharingMenulet to access the Raspberry Pi
Using ScreenSharingMenulet to access the Raspberry Pi

Launch the ScreenSharingMenulet app and click on its icon on the menu bar.

  • Navigate to ScreenSharingMenulet icon > Preferences > ScreenSharingMenulet
  • Click raspberrypi

The ScreenSharingMenulet app will then launch a new window containing the Raspberry Pi desktop environment.

Take Screenshots From Raspberry Pi

It is now possible to take screenshots of content on the Raspberry Pi. To do this:

Full Raspberry Pi Desktop

The Raspberry Pi Desktop
The Raspberry Pi Desktop
  • Move the mouse cursor out of the VNC client window, that is showing the Raspberry Pi desktop, and into the Mac environment
  • To take a screenshot of the full VNC window, to capture the entire Raspberry Pi desktop, press Command-Shift-4
  • Press the Space bar and then move the mouse cursor over the VNC window
  • The window will be highlighted; clicking the mouse will record the screenshot

A screenshot of the Raspberry Pi desktop will now be sent, as a .png file, to the Desktop of the Mac.

Selected Area on Raspberry Pi Desktop

A selected screenshot of the Raspberry Pi desktop
A selected screenshot of the Raspberry Pi desktop
  • Move the mouse cursor out of the VNC client window, that is showing the Raspberry Pi desktop, and into the Mac environment
  • To take a screenshot of the full VNC window, to capture the entire Raspberry Pi desktop, press Command-Shift-4, to change the mouse cursor to crosshairs.
  • Click and hold the mouse and drag across the area that you wish to capture as a screenshot
  • Releasing the mouse will record the screenshot

A screenshot of the selected area of the Raspberry Pi desktop will now be sent, as a .png file, to the Desktop of the Mac.

Conclusion

In this tutorial I have shown you how to install VNC server software on a Raspberry Pi and VNC viewer software on a Mac, to remotely access a Raspberry Pi from a Mac.

I have shown you how to select the full desktop, or a selected area of the desktop, on the Raspberry Pi to record as a screenshot.  I have also explained how to change the screen resolution on the Raspberry Pi.

You can also access a Raspberry Pi, using VNC, from a Windows or Linux box. Doing so is a useful way to be able to take screenshots of what you can see on the desktop of a Raspberry Pi.

Advertisement