A “headless” computer is one that operates without a monitor, keyboard, or mouse. The Raspberry Pi works great as an inexpensive computer that can help people learn to program and create fun, interesting projects (without many repercussions if you break something–just reflash the SD card!). The one downside is that as a computer (as opposed to a microcontroller), it requires a monitor, keyboard, and mouse to work, which can quickly increase the costs of acquiring the necessary components.
To use a Raspberry Pi, you often need a monitor, keyboard, and mouse
The Raspberry Pi can be extremely useful for projects that do not require a monitor, keyboard, or mouse. The downside is that setting up the Pi to connect to the Internet, expand the filesystem, and run code generally requires these computer accessories.
An example of a simple headless Raspberry Pi project: Twitter Monitor
This tutorial will show you three different ways you can configure your Raspberry Pi without the need for a monitor, keyboard, or mouse.
- Serial Terminal – This requires extra hardware in the form of a serial-to-USB adapter, but it is by far the most robust way to connect, as you are not relying on any network setup.
- Ethernet with Static IP Address – This method requires a Linux operating system to change some files on the Raspberry Pi image. You can give the Raspberry Pi a static IP address and then use an Ethernet cable (or WiFi) to log in.
- WiFi with DHCP – You will need to have access to your router to find your Raspberry Pi’s IP address in order to log in via SSH. As a result, this may not be the best option in school or office environments.
Certainly, there are more ways to connect to the Raspberry Pi. These show three common approaches to get you started interacting with a headless operating system on the Pi.
To follow along with this tutorial, you will need a Raspberry Pi, power supply, and micro SD card. Note that no monitor, keyboard, or mouse is required! Any extra hardware needed will be listed in the specific section.
Flashing the OS
The Raspberry Pi has several options available for operating systems. It’s often recommended that beginners start with NOOBS, as that walks the user through the necessary steps of installing an operating system. However, it usually requires a monitor to see the selection process, so we’ll be creating an image of Raspbian manually. Additionally, we’ll be using Raspbian Lite, which saves us space and time by not including the desktop (i.e. the graphical interface). Because we’re creating a headless image, we’ll be doing everything through the command line!
To start, download the latest version of Raspbian Lite.
To flash the image to your SD card, we recommend the program Etcher. Download and install it. Plug your SD card into your computer (using a microSD USB Reader if necessary), and run Etcher. It will walk you through selecting the OS image file, selecting your SD card reader, and then flashing it.
Once that’s done, you will need to make a choice: how do you want to interact with your Raspberry Pi? Without a monitor, keyboard, and mouse, you have a few choices:
- Serial Terminal – Requires extra hardware
- SSH with a Static IP Address – Requires Linux to modify files on the SD card
- SSH with a Dynamic IP Address – Requires access to your router to find the Raspberry Pi’s IP address
If you would like to access your Raspberry Pi using the least amount of software work, you will need some extra hardware. Two of the pins on the Raspberry Pi offer transmit and receive data for serial communication. With a small change to a file on the boot sector of the SD card, a command line terminal will be broadcast over this serial line, and you can enter commands to control Linux, write programs, etc.
If the other methods do not work to gain access to your Raspberry Pi or you lose your video out signal, using the serial terminal is a great way to see if your Raspberry Pi is still working and to debug any problems you might have.
Enable the Serial Terminal
In versions of the Raspberry Pi after 3 (e.g. 3 Model B, 3 Model B+, Zero W), the processor contains two hardware UARTs. One is dedicated to the Bluetooth module, while the other is a less-featured “mini UART.” This mini UART is broken out on pins 8 and 10 and can be used as a serial terminal into Linux.
The problem is that the mini UART’s clock is tied to the variable clock speed of the graphics processing unit (GPU). We need to set a static system clock in order to use the mini UART as a serial terminal. This can potentially disable some features (e.g. overclocking or power-saving mode), but it should not affect normal operation. See here to learn more about the mini UART.
With your SD card still plugged into your computer, browse to the boot partition, and find the config.txt file.
Use your text editor of choice to modify the file (on Windows, something like Notepad++ is recommended). Add
to the end of the document.
Save and exit.
Take a look at the pinout for the Raspberry Pi 3.
You’ll see that pins 8 and 10 are connected to UART transmit (TXD) and receive (RXD), respectively. We’ll need to connect GND (Raspberry Pi) to GND (USB to serial converter), TXD to RXI, and RXD to TXO. Note that we do not need to connect any power pins (3.3V or 5V).
Connect the USB to serial converter to your computer, and connect the wall adapter to the Raspberry Pi’s PWR (USB micro B) port.
Choose a serial terminal based on your operating system (here are some options).
If you are using Windows, you will need to know the COM port number connected to your USB to serial adapter, which can be found in the Device Manager.
Change the settings as necessary to match the following:
- Baud rate: 115200 bps
- Data bits: 8
- Parity: None
- Stop bits: 1
- Flow Control: None
Open the connection, and press enter. You should be presented with a login prompt.
Enter the following credentials (default login):
- Username: pi
- Password: raspberry
You should be logged in at the command prompt and ready to type Linux commands!
Ethernet with Static IP Address
If you do not want to use the serial terminal or want to be able to log in to your Raspberry Pi over a network connection, you can give your Pi a static IP address, connect it to your network (or to your computer via a crossover/Ethernet cable), and log in via SSH.
Set Up Static IP Address
Plug the micro SD card (with the flashed Raspbian image) into your Linux computer. Most modern versions of Linux should automatically mount both partitions (boot and rootfs). You will need superuser privileges to edit the files on rootfs. Open a command prompt and edit /etc/dhcpcd.conf in rootfs.
Navigate to the rootfs directory (wherever your Linux distro has mounted it):
Edit the dhcpcd.conf file:
sudo nano etc/dhcpcd.conf
Scroll down to the bottom of the file and add the following lines:
Save and exit by pressing ctrl + x and y when asked if you would like to save.
Read to More Info…..