Intro to the (Headless) Raspberry Pi!

Finally! Use your Raspberry Pi without spending what feels like forever connecting external peripherals and dealing w/ a cable monstrosity: Configure your Pi to be headless! (not the scary kind tho) This is particularly helpful for folks teaching workshops with the Raspberry Pi, since it can be cumbersome (and expensive) to provide monitors, keyboards, and mice for every student.

I’m assuming that y’all know a bit about the Pi, so this tutorial will not cover what the Pi is or it’s awesome capabilities (I’m lookin’ at you, GPIO pins!). To learn more about what the Pi can do, check out some of my other tutorials (see the last section in this tutorial) or leave a comment.

What is covered in this tutorial: Enabling and using SSH, a general overview of the Linux terminal window, and how to connect to the Pi’s GUI (Graphical User Interface, aka the Desktop view) via SSH.

Read Time: 15 min

Build Time: ~20 min

Cost: Free! (assuming you already have an RPi and Ethernet cable)

Materials

Computer with Ethernet port & SD Card slot

– Raspberry Pi 3

– SD Card (8GB or larger)

– MicroUSB to USB power cord

– Ethernet Cable

– RecommendedRaspberry Pi Case & GPIO cable

Software

For this project, you’ll need the following (free!) software programs:

 

Configure the SD Card

1. Download your favorite flavor of Raspbian! You can get the most recent version here.

2. Insert your SD card and open Etcher.

3. Select the Raspbian zip file, the driver for your SD card, and click “format”.

4. Enable SSH access

Open the file contents for the SD card. Add a new text file titled “SSH”. If the computer adds a file extension (e.g. “.txt”), delete it and ignore any warnings.

5. Eject the SD card and insert it into your Pi.

 

Let’s Get Connected!

1. Plug in the Ethernet cable between the Raspberry Pi & your computer.

2. Plug in the USB power cable.

Check that the red power light turns on and that the Ethernet port lights (yellow & green) are on and/or blinking.

3. Connect the RPi to the World Wide Web (aka the Internet).

Go to Settings -> Network & Internet -> Change Adapter Options (aka Network Connections).

Click on the Ethernet connection, hold down “CTRL”, and then click on your WiFi connection.* Right-click in the window and select “Bridge Connections” — this will bridge the connection between the Ethernet port to your WiFi port.

*If you select the WiFi connection first, it will bridge the connection from the WiFi to the Ethernet, which would allow you to log into the Pi but not connect to the Internet.

4. Open PuTTY and log in to the Pi using the “raspberrypi.local” IP address.

Default username: pi

Default password: raspberry

5. Change the default password by typing passwd and following the prompts.

 

Navigating the Linux Terminal Window (Shell)

The terminal window is the control panel for the system.

It typically shows a command prompt, which gives us information but is not part of the commands to the system. Most commonly the command prompt displays the user’s login name and the current working directory (represented by a twiddle: ~ ).

Inputting Commands

Commands are written after the prompt and inputted by pressing the Enter key.

Commands can be issued as-is or followed by one or more options. Options usually have a dash in front of them, like the following:

ls -a

You can view the options for a specific command by typing the command name followed by “–help” (will cover this more later).

 

 

 

 

 

 

 

 

Linux Hot Keys!

There are a handful of special key combinations that make navigating the terminal window easier and faster. Here are a some of the most common ones:

  • Ctrl+A – Move cursor to beginning of command line
  • Ctrl+E – Move cursor to end of command line
  • Ctrl+C – End running program
  • Ctrl+D – Logout of current session
  • Ctrl+R – Search command history
  • Ctrl+Z – Suspend a program

 

  • Left and Right arrow keys – Move cursor one place to the left or right on command line
  • Up and Down arrow keys – Browse command history
  • Shift+PageUp and Shift+PageDown – Browse terminal buffer (to see text that is off screen)
  • Tab – Command or filename completion
  • Tab Tab – Shows file or command completion options

Practice using these every time you are in the terminal window and you’ll quickly become a Linux wizard!

Getting Help in the Terminal

1. Manual and Information Pages

The manual pages are an exhaustive resource for all of the available commands in the Linux terminal window. To read the manual pages on a particular command, type the following:

man command

This will pull up the manual pages for the particular command that you are searching. Here’s the manual pages for the apropos command:

In the manual, the first line contains the name of the command you are reading about and the ID of the section that contains the manual page.

After the first line is a synopsis, which is a short description of the command that includes technical notation of all the options and/or arguments. Options are a way of executing the command, and an argument is what you execute it on. Optional arguments are put between square brackets.

After the synopsis is a longer description of the command, followed by a more in-depth overview of the available options, information about combining options, other related commands, and other information pertaining to the command.

Some commands have multiple man pages, like the “passwd” command. To see all pages about a command, use the “-a” option:

man -a passwd

The info pages contain more recent information and can be easier to use. Here’s what the menu of the info pages looks like:

To view the info pages on a command (replacing “command” with the actual name of the command you want to research, like “apropos”), type the following:

info command

To navigate the info pages, use the arrow keys to browse through text, the Enter key to read about a particular keyword, “P” and “N” keys to go to the previous or next subject, and the space bar to move one page further. Use “Q” to quit.

2. whatis and apropos commands

The whatis command gives brief information about a command and lists the first section in the man pages that contains a relevant page (in parenthesis after the command name).

If you’re entirely unsure where to start, the apropos command is a good way to search for keywords. For example, if you want to know how to start a browser, you can type apropos browser, which will pull up a list of all browser-related programs, including web browsers, file and FTP browsers, etc.

Here’s the apropos search results for “text”, which displays commands and programs that contain the phrase “text”:

 

3. Using the –help option

Most commands also have the option –help, which gives a short explanation of the command and a list of available options. When in doubt, this is a great way to get some quick and useful information on using a particular command and its possible extensions.

To use the –help option, type –help after a particular command, like the following example (also shown in the photo above):

apropos --help

The output looks like this:

 

Enough of the Terminal Window! Where’s the friggin’ Desktop??

Alright alright.. Remote Desktop Connection is an easy way to use the desktop view, also known as “Graphical User Interface,” or GUI for short.

1. Install Remote Desktop Connection on your Pi:

sudo apt-get install xrdp

2. Install Remote Desktop Connection on your PC (is already installed on Windows OS).

3. Open Remote Desktop Connection and log in using the “raspberrypi.local” IP (or find your Pi’s IP using command ifconfig). Ignore warning (click “yes”).

4. Log in with the Pi’s username and password.

If you haven’t changed your password yet, do so now. (Yes, I know I already told ya to do so but it is worth repeating since someone could actually hack into your Pi if you don’t change the default password.)

Now you can use the Pi’s GUI and do almost* everything via your PC!

*Sadly, we can’t play Minecraft in this mode as it uses too much data to be transferred via SSH. Using a VNC viewer is one option around this if you really want to play Minecraft remotely.

What is SSH, anyway?

SSH stands for “Secure SHell” — it is a “cryptographic network protocol for operating network services securely over an unsecured network.” – Wikipedia

… Uh, what?

In other words, SSH is a secure way to connect between one computer and another, even if the network through which you are connected is not secure.

For example, if you are on a shared network and you use SSH to remotely log into another computer, other folks on the shared network can’t see what you’re doing through the remote connection (although Snowden did release documents that showed the NSA can sometimes decrypt SSH).

Common uses of SSH include remote log in, like if you want to connect to a computer that lives a mile underground without having to, you know, actually go down there. (I used to work for a super cool dark matter experiment called DRIFT and this is how we would access the computers that controlled the detector because the computers lived in a mine about 3 miles underground.. too far to travel to update software!).

Here’s the full Wikipedia page on SSH — it’s super cool so check it out!

More to Explore!

Go forth and explore! Practice using the terminal window until you get comfortable and familiar with the basic commands.

Program the GPIO pins to do cool stuff! Need some ideas? Check out these tutorials:

1. Making a Soil Moisture Sensor

2. Building an Irrigation Controller (can be paried w/ Soil Moisture Sensor)

3. Bark Back: Install an IoT Pet Monitor

4. Expand on your Smart Home & add a Motion Triggered Music Player

Need parts?

Take apart old & broken electronics! Electronic toys are a great place to get motors and speakers. If you want better motors, take apart power tools.

Ask friends or find a repair shop for extra parts and wire, save power cables from old electronics and use them as power supplies or harvest them for wires and/or connectors, save old headphones and use them for audio projects.

Best piece of advice: think before you toss 🙂



			

Setting up a Raspberry Pi to Control Physical Objects, Pt. 1

RaspberryPiLogosmallThere are a slew of relatively simple systems to control physical objects w/ software. The most popular options are Arduino, the Raspberry Pi, and BeagleBoard. I’m an avid Raspberry Pi advocate, so let’s start with that!

The RPi is a simple & inexpensive computer that has general purpose input and output (GPIO) pins that interface w/ the real world.

(This tutorial assumes you are a beginner, but some technical jargon is included. Please feel free to comment if a term or phrase is not clear.)

What is a Raspberry Pi?RaspiModelB-1024x902

The Raspberry Pi is a credit-cared sized computer created by the Raspberry Pi Foundation, an educational charity based in the UK. It is designed to promote programming, computing, and interfacing with the physical world. It can control pretty much anything you are capable of conceiving.

There are two versions of the Pi:

  • Model A is cheaper w/ fewer features; 256 MB of RAM, one USB port and no Ethernet port.
  • Model B is more expensive, but has 512 MB of RAM, two USB ports, and a 100mb Ethernet port.

Where to purchase:

You can buy a Raspberry Pi from a variety of distributors. Model B from Adafruit is $40 (+ shipping & handling).

Other supplies:

RaspPiStarterKitThe Pi is literally just a computer. You’ll need a few additional supplies to set it up and use it (unless you’re a wizard). Think of it like a puzzle: collect the remaining pieces to customize an inexpensive interactive computer! To make the process easier, here’s a list of parts w/ explanations (you probably already have some):

  1. Power Cord
    The Pi runs on a micro-USB power supply, similar to many phone chargers. More specifically, the Pi needs 5 VDC and at least 700 mA. The Pi Foundation recommends a power supply that can provide 1200 mA. You can get one for less than $10, best values ~ $5, if you’re crafty you can find cheaper (or free). Here’s a google search for some that meet the best specs. Take note of where the power cord plugs into: wall socket, USB, etc.
  2. SD Card
    The Pi needs an SD card for physical memory storage (it doesn’t have a built-in hard drive or solid state drive). For ~ $6, you can buy an SD card with a pre-installed operating system and necessary software from the Pi Foundation’s Swag store here.
    With slightly more effort, you can buy any generic SD card and download the software here. This is fairly easy with a Mac system; if you chose to go down this route, here’s a great tutorial.
  3. Monitor & Display cable: HDMI/DVI cable or RCA composite video lead.
    Most modern monitors and TVs have HDMI ports for video (you can connect your RPi to your TV, woo!!). If you don’t already have one lying around, HDMI cables are found at RadioShack, Best Buy, Amazon, Ebay, etc. You can also get a HDMI converter cable for monitors or TVs w/ different ports. Older monitors are easy to find for free; many places of business, colleges/universities, and friends are happy to part with old monitors, or you can check out e-waste recycling bins.
  4. USB Keyboard & mouse (easiest way to set up).
    Any keyboard and mouse w/ a USB connection will work w/ the Pi.

Optional Supplies:

  1. Raspberry-Pi-Geek-Cases-1Ethernet Cable  (easiest way to connect to the Internet for Model B).

    Usually blue and lying around in some pile of cords you know are important. You can also buy them at places like Radio Shack, Best Buy, Amazon, etc.
  2. USB WiFi chip.
    Getting a USB WiFi “dongle” (yes, that is actually what it is called..) will allow you to connect to the Internet w/out an Ethernet cable. This requires some fairly involved setup, but it is completely doable for a RPi user of any experience level. Here are two methods:
    –Using wicd-curses,
    –Using GUI application
  3. Audio Lead (if not using HDMI)
    To get sound w/out an HDMI cable, you’ll need a standard 3.5mm jack to connect to speakers or headphones.
  4. Case
    The Raspberry Pi is designed to be a bare-bones computer to reduce cost as much as possible. However, cases are helpful protection from inevitable accidents and improve the mechanical connection of cables. There are TONS of awesome cases made specifically for the Raspberry Pi, although feel free to get creative and make your own!

Basic Setup:

raspberry_pi_iphone

  1. Insert SD card. Plug the RPi into a monitor & connect the keyboard and mouse via USB. An Ethernet cord is also recommended as it makes installing software on the RPi much easier.
  2. Plug the power cord into the RPi. Make sure you see a light turn on. (Yes, I honestly needed to include this step because this is an all too frequent problem for me.)
    Always do this after everything else is plugged in.
  3. If everything has been connected properly, you will see a start-up window. Every operating system (OS) will be different, but initial setup is simple and manageable.
    If you have a pre-loaded RPi-specific OS, or you have Raspbian or Adafruit’s OS, here’s a super straightforward tutorial on how to fully configure the RPi.Changing a few basic settings will definitely make life easier. From personal experience, if you have an SD card larger than 2 MB it’s useful to initially expand root partition to use the full SD capacity. If you want to avoid a command line window, you can specify Desktop launch whenever you power up the RPi.The default username is “pi” and the password is “raspberry”.Note: Since every OS is different, if your Pi doesn’t launch into the startup window, if you are still on the terminal window type “startx” into the command line. If that doesn’t work, leave a comment and we can troubleshoot together!
  4. Essentially that’s it! Once you’re at the desktop, you can use the Pi much like any other computer! Some basic programs: Midori is a simple Internet browser, Leafpad is a word processing program, Idle is a Python programming environment, and Scratch is kid-friendly programming language.

I will add more on how to set up the wireless, or other topics as requested.