Raspberry Pi is a tiny computer built onto a miniature circuit board. It’s the most popular device of its type in the world, having sold more than 19 million units since it launched in 2012. This popularity is mostly thanks to the RPi’s legendary ease of use. There’s a wealth of information out there to help Pi owners learn all about the device. There are multiple versions of the Raspberry Pi available, each of which offers its own unique advantages. The company’s flagship device is currently the 3 Model B+, which was launched in March 2018. If you’ve only just gotten your Raspberry Pi out of its box, you might wonder what to do next. Happily, we’ve put together a guide that’ll make getting started with raspberry pi as easy as possible. Let’s begin!
Our first step is to wire everything together and boot the computer. That means you’ll need are:
By Ayaita [CC BY 3.0], from Wikimedia Commons
We can add more peripherals later if it suits our purposes, but for now, let’s keep things simple. If you don’t have a spare monitor lying around, then your HDMI-equipped tv will do the job just as well.
Raspberry Pi is capable of booting a range of different operating systems, of which the most popular is the custom-made Raspbian. The presence of an operating system is what separates Raspberry Pi from similar-looking devices like the Arduino. Rather than executing the same pre-flashed code over and over again, the Pi is capable of running programs, managing files, and executing new code on the fly. If you’ve any experience with desktop computers, you’ll be able to bring it to bear on your Raspberry Pi. If you want to learn more about the differences between Raspberry pi and Arduino, visit our blog post on this topic - Arduino vs. Raspberry Pi.
The Raspberry Pi doesn’t come with any internal storage of its own. It instead relies on interchangeable SD cards. While it’s possible to store files on a separate computer in your home and access them via Wi-Fi, your Raspberry Pi will need to boot to an operating system that’s stored on an SD card.
The easiest way to do this is through a piece of software called, appropriately enough, NOOBS. A zip file containing the program is available via the Raspberry Pi website. After extracting the zip file, you can simply drag its contents onto the SD card from your File Explorer in Windows or Mac OS.
You can then insert the SD card into your Raspberry Pi and plug it in. You’ll be prompted with a list of operating systems to install. Simply select Raspbian and the rest of the process will be taken care of. After the installation is complete, you’ll be asked to reboot. Once you’ve gotten acquainted with Raspbian, your needs might lead you to install a different operating system. If you’re using the Pi as a media center, for example, then specialized software like OSMC might make life easier.
To interact with your Raspberry Pi, you’ll need a keyboard and a mouse. These should be plugged into the device’s USB sockets. While it’s possible to use other input devices, like touchscreens, using a keyboard and a mouse at this stage will help to keep things simple.
Broadly speaking, there are two ways in which you might use your Raspberry Pi. You can either treat it like a normal desktop computer in the way that we’ve described thus far. Or, you can interact with it remotely. Your choice will depend on what, exactly, you’re using your Raspberry Pi for.
Local access is just as the name might suggest. You plug input devices directly into the RPi and monitor things using an output device.
Remote access to a Raspberry Pi is simple to set up. Once you’ve done so, you’ll be able to access your Raspberry Pi from your PC or mobile device. This can be achieved via one of two techniques.
SSH stands for Secure Shell. It offers encrypted access, even over an unencrypted network. To get it set up, you’ll need to know the IP address of the device. You can get this information by typing ‘ifconfig’ into a terminal. If you’re connected wirelessly, you’ll find it under ‘wlan0’; if you’ve plugged in via ethernet, it’ll be besides the ‘inet addr’ text.
We’re not quite done. Since 2016, SSH has been disabled by default in Raspbian. We’ll need to tweak the appropriate setting on the RPi. Go to Menu>Preferences>Raspberry Pi Configuration, and then click on ‘Interfaces’. Set SSH to enabled, and you’ll be able to access the RPi using suitable software on your Mac or PC.
SSH provides access only to your Raspberry Pi’s Command Line Interface. If you’d like to reach the full desktop, you’ll need to use something called Virtual Network Computing, or VNC.
VNC is a means of sharing a desktop interface between devices. So, you could be sitting on the sofa, controlling your Raspberry Pi via your smartphone, even when it’s on the other side of the house. Included with Raspbian are two pieces of software, collectively called ‘VNC Connect’ which make this happen. They are ‘VNC viewer’ and ‘VNC server’.
To access your RPi in this way, you’ll need to ensure that you have the latest version of VNC. Do this by typing the following commands:
sudo apt-get update
sudo apt-get install realvnc-vnc-server realvnc-vnc-viewer
Next, enable VNC server:
sudo raspi-config
You can do the same thing via the graphical interface – it’s a setting under the ‘Interfaces’ section of the Raspberry Pi configuration options.
If your Raspberry Pi lacks a monitor of its own, it’s known as ‘headless’. This means that it isn’t rendering a desktop. It can still create a virtual desktop, however, which you’ll be able to access remotely. Connect to your RPi using SSH and run VNC server. You’ll see an IP address printed on the screen, which you’ll need to input into your VNC viewer application. Once this is done, you should be looking at your newly-configured remote desktop.
As well as hosting an operating system and allowing plenty of in-the-box fun, the Raspberry Pi also boasts an extensive pin count. Those pins can be used to send and receive information from a range of hardware and electrical components. Let’s run through some of the ways in which these pins can behave.
The Raspberry Pi 3 Model B+ SBC (single-board computer) has a total of 40 GPIO (that’s General-Purpose Input Output) pins sprouting from the circuit board. That’s considerably more than the Arduino offers, which makes the Raspberry Pi suitable for both hardware and software-based projects. Some of these, however, are not actually GPIO pins, but power and ground connectors. Confusingly, there are two ways of referring a specific pin. Either by the number that’s actually written on the board, or the ‘Broadcom SOC numbers’.
Since the GPIO pins are distributed throughout the physical pinout, this can get quickly confusing. You might think that using the BOARD numbers is more intuitive, but if you’re porting projects over different Raspberry Pis with different pinouts, things can get a little messy. Whichever option you go for, it’s worth keeping a pen and paper handy to make a note of what’s going on.
Raspberry Pi comes packed with powerful features. Let’s take a look at some of them.
Some of the most interesting and useful applications of Raspberry Pi is its ability to connect to other devices. In some cases, this might be achieved through the pinout; but we should also consider the high-level connectivity that you can use to connect your Pi to shop-bought portable speakers, televisions and computers.
Bluetooth is perhaps the best means of transmitting information from one device to another over short distances. Through it, you’ll be able to connect peripherals wirelessly, and thereby free up USB sockets. You’ll also be able to send control signals without resorting to adaptor dongles. Getting the RPi to transmit and receive audio signals requires a little bit of fiddling; new users will want to get more rudimentary Bluetooth peripherals working first.
The Raspberry Pi comes with onboard Wi-Fi, through which it can connect to your home network in much the same way as any laptop or mobile device. If you’d like to get a little bit more advanced, you can even set up your Raspberry Pi as an access point rather than just a client. It’ll then effectively serve as a replacement for your home router.
If you’d prefer to do things the old-fashioned way, then you can just as easily plug a standard RJ45 cable into the rear of your Pi. Remember that if you’re connecting your Pi directly into your computer in this way, you’ll need a special ‘crossover’ ethernet cable.
Serial data transmissions consist of single-file streams of bits. To avoid transmission errors, you’ll need to make use of resistors that’ll pull signals down or up, and eliminate floating voltages. Your Raspberry Pi makes use of three different sorts of serial data transmission.
Serial Peripheral Interface is another variety of synchronous interface – but one that’s capable of running faster than I2C. It’s built with short-distance communication between peripheral devices in mind and uses a master-slave architecture. You’ll need a total of four wires between the master and slave devices: one to select the slave device being transmitted to, two to send data in both directions, and one to send ‘clock’ pulses that indicate which indicate when a new bit is being transmitted.
Inter-Integrated Circuit is a synchronous serial computer bus that came about in the eighties. It relies on just two wires shared between multiple devices: one to transmit data and one to act as a clock. When a clock pulse is detected, the devices in the chain record the state of the data signal. In order to initiate a transmission, any device can simply pull the data line down while the clock is in an on position.
UART, (or Universal Asynchronous Receiver-Transmitter) information is sent using two pins. The TX pin transmits data, while the RX pin receives it. Being asynchronous, the UART protocol does not require a clock pin to keep everything in sync. Electronic musical instruments talk to one another using a form of UART call MIDI (Musical Instrument Digital Interface), which is traditionally transmitted using five-pin DIN cables.
An analog-to-digital converter is essential if we’re going to turn the analog signal emitted by say, a moisture sensor, into digital information that your Raspberry Pi can comprehend. The Raspberry Pi itself lacks ADCs, and so to achieve this, you’ll need to attach a separate, specialized device. They’re available as headers which attach directly to the top of your Pi.
Pulse-width modulation is a means of simulating a constant voltage through digital on-off switches. By varying the ratio between ‘on’ states and ‘off’ states, we can create the same effect as a fixed voltage. We just need the speed of the pulses to be such that the human eye will perceive a flashing LED as one that’s emitting a fixed brightness.
This can either be done through software (called ‘soft’ PWM) or through specialized hardware PWM pins. A hardware PWM pin will put out a consistent stream of pulses that a servo motor will be able to deal with without encountering problems.
Once you’ve gotten your Raspberry Pi wired up and booted, and you’ve run a few basic programs, you might want to get your hands dirty by creating some programs of your own. Raspberry Pi offers support for a range of languages, but among these, two stand out as noteworthy: Python and C++.
Python is a high-level programming language that’s extremely readable, and thus suitable for novice coders. It came to be in the early nineties and favors English keywords rather than symbols. If you have an idea for a simple program in mind, or you’d just like to have fun with coding on your Pi, then Python is undoubtedly a fantastic place to get started.
In contrast with ‘compiled’ languages like the C-based ones, Python is an interpreted language. You’ll need the Python interpreter on your Pi. Happily, recent versions of the Pi come with the interpreter pre-installed.
To get started, you can simply enter ‘python’ or ‘python3’ into the command line. From there you can create a simple ‘Hello World’ program and save it as an executable file that can be run in isolation.
In contrast with Python, C++ is a ‘compiled’ language, of the sort commonly employed on microcontroller-based circuits. It is highly efficient and flexible and has been around for decades. While C++ is less intuitive and more difficult to get into, a Raspberry Pi offers an excellent opportunity to get to grips with it. Once you’ve gotten the hang of C++, moreover, you’ll be able to more easily take on similar languages like Java, PHP and C#.
Unix-based operating systems might look quite similar to those you might be familiar with from traditional desktop and laptop PCs. There are, however, some significant differences that you’ll want to bear in mind.
Installing a program in Windows is as simple as clicking on the setup program and waiting for the installation wizard to work its magic. In Raspbian, this isn’t the case; you’ll need an additional piece of software to install a new package. There are several of these to choose from, but the most basic of them currently is called APT (or Advanced Package Tool). This will compile the source code into a program that your Raspberry Pi can run. The diverse nature of UNIX-based systems makes this way of doing things is much simpler than having binary-code programs pre-compiled and ready to go.
Raspbian comes with its own command-line interface, into which you’ll be inputting all of your commands. Once mastered, it’ll allow you to manipulate code much more quickly and precisely than a GUI ever could. There are several applications available for this purpose, but the default is ‘LXTerminal’. Start it up, and you’ll be confronted with a black window with luminous green text on it – just like in ‘The Matrix’.
The first line printed onto the terminal interface will contain your username and the hostname of your RPi. By default, it’s ‘pi@raspberrypi’. From here, you’ll be able to input commands. Let’s run through a few of the more important ones.
PWD Standing for ‘print working directory’, this will display the name of the directory you’re currently viewing.
LS Lists the contents of the current directory.
CD Changes the directory. Use in combination with the name of the directory to which you’d like to navigate, or followed by ‘..’ to return to the parent directory.
MKDIR Creates a new directory.
RMDIR Removes an empty directory.
CP Copies a specified file to a specified location.
MV Moves a specified file to a specified location.
SUDO Performs a command as a ‘superuser’. Useful for installing programs and other tasks which require administrative privileges.
APT Uses the Advanced Package Tool to install new software.
By appending extra characters to the end of a command, you can alter its function. This is called a flag. For example, you might write ‘-a’ (for ‘all’) on the end of an ‘ls’ command to signify that you want to see the entire contents of a folder, including dotfiles.
You might suppose that a CLI requires a lot of typing, and you’d be right. With that said, we can use the arrow keys to scroll through a history of recent commands, and the ‘tab’ key to autocomplete the file name we’re midway through typing. When directories get complicated, this can be incredibly handy.
If you’d like to learn more about the commands available in Raspbian, there’s a more exhaustive list here.
As opposed to Arduino, there are dozens of Integrated Development Environments available for Raspbian, each with their own individual strengths and weaknesses. BlueJ is an IDE built with Java in mind; it’s great for learning object-oriented programming. Thonny, on the other hand, is a more recent Python-based application that makes learning and coding in Python simple and intuitive.
We’ve run through quite a lot of information. Let’s put some of it into practice using our Raspberry Pi and the circuit.io app.
Your first step should be to navigate to the circuito.io circuit design tool. Do so, while keeping this article open in another window.
We’re going to hook up our Raspberry Pi 3 with an adxl345 digital accelerometer. Type ‘Raspberry Pi’ into the search bar and the RPi should be among the topmost results. There are two ways to add the component: you can either drag it into the empty space, or you can click on it for a preview, and then click the red ‘add’ button. It will replace the Arduino that’s in there by default. Now do the same with the adxl345.
A breadboard will automatically appear, and the connections between the two devices will be made for you. You should wire the two devices up according to the generated instructions. In this case, they’re simple enough that you can simply glance at the diagram.
Adafruit has kindly posted the instructions for this accelerometer on their Github page. Download the library and install it from source using the following commands:
sudo apt-get install git build-essential python-dev
cd ~
git clone https://github.com/adafruit/Adafruit_Python_ADXL345.git
cd Adafruit_Python_ADXL345
sudo python setup.py install
If you’re serious about learning Raspberry Pi, then you’ll be spending a lot of time on Github. Get into the habit of consulting the readme file that accompanies each download; it’ll save you considerable time and stress!
Next, you’ll want to run the example code. This will ensure that both devices are properly connected and working. Congratulations; you’ve got your first hardware-based Raspberry Pi project up and running. Let’s hope that there are plenty more to come!
After going through this guide, you should be able to run basic functions of the Raspberry Pi and build your project. If you have any questions, or need any help, you can always post on our forum.