IoT Shaman

Getting Started with Raspberry Pi

by Kyle Brown, June 27th 2017

Raspberry Pi (RPi for short) is a single-board computer, meaning all the components needed to run the operating system are included in the RPi board. Here at IoT Shaman we love the Raspberry Pi, and a number of our current and future projects utilize the RPi as the platform for typical deployments. There are many benefits of using a RPi for IoT projects, here are some of our reasons for using them (frequently!):

  • Low-cost (usualy less than $50)
  • Small-size
  • Low power utilization
  • OS run on Micro SD (easy to swap-out)
  • If you are interested in learning more about the benefits of Raspberry Pi's, check out their official website.

This article will walk you through how to provision an SD card with Raspbian (the default OS for Raspberry Pi), setup your user accounts, and configure your wifi connection. The goal for this article is for you to be up-and-running with your new Raspberry Pi in a few minutes. After reading this article, please check out our blog page and find some fun projects to try out your new RPi!

What you will Need

Before we get started, there are a few things that you will need. If you need help choosing a RPi model, take a look at this artice (for most projects here we use the Raspberry Pi Model 3 B).

Required Items

  • Raspberry Pi
  • 12V Micro USB power cable
  • Micro SD card (regular SD for older models)
  • An Ethernet cable
  • Another Computer (to provision SD card) +A Raspbian Jessie Image (found here)

There are a couple more things you may need, but we will cross that bridge when we get to it. For now, we are ready to begin.

Provision your SD Card

We will be using an application called "Etcher" to install an image file on the SD card. So before we proceed, click here to download Etcher, then follow the on-screen instructions to install it. Once it is installed, follow the below steps to image your SD card:

  • Connect your SD card to your computer
  • Open Etcher and select from your hard drive the Raspbian Jessie image
  • Select the SD card you want to write to
  • Click 'Flash!' to write to the SD card

Connecting the Pieces Together

We are now ready to begin plugging things in. Start by inserting your SD card into the available slot on the end of your RPi. Once this is in place, plug an ethernet cable into into your RPi and subsequently into your router. If you are planning on using a monitor / keyboard to access your RPi, please plug your HDMI cable into the RPi then subsequently into your TV, then connect your keyboard's USB dongle. The last thing you need to do is connect the power supply, so go ahead and plug the Micro USB charger into the wall then into your RPi. You should see the indicator light begin flashing, and if you are connected to a monitor you should see some activity on the screen.

Accessing the Terminal

In linux operating systems almost everything can be managed from the terminal, and this is where we will spend most of our time configuring the RPi for your purposes. If you are using a monitor and keyboard, accessing a terminal is as easy as typing (Cntl + Alt + T); The other option is to access the terminal via SSH (which i recommend to intermediate-advanced users). To connect to the terminal via SSH, perform the following operations on your Windows or Mac OS computer (Windows users will need to install Putty):

  • Locate the internal IP address of your RPi (via your router's admin panel or netstat)
  • Windows users, open Putty and use the internal IP address of your RPi as the hostname for SSH connection. Click 'Open'.
  • Mac OS users, open a terminal and type ssh pi@[internal-ip] replacing [internal-ip] with the RPi's IP address. Click Enter.

Once you have completed the above steps, you should be prompted with a request for login credentials. Mac OS users will have already provided the username when connecting via the terminal, Putty users will need to first enter the username 'pi'. Next you will be prompted for a password, type 'raspberry' then click enter. Congratulations, you are now connected to your Raspberry Pi! We shouldn't not stop here however, let's keep the momentum going by configuring our user accounts.

Configuring User Accounts

If you are simply messing around with your RPi and aren't very concerned about network security, you can skip this step. However you should do so with caution because the default user for RPi is the same for everyone who installs Raspbian, and it also has sudo access, which means if someone is able to get access to this device they will have full control, and could possibly use this as a launch-platform for other attacks on your network.

In order to harden the security of our RPi, the first thing we need to do is change the password for the default user ("pi"). To accomplish his, open a terminal (via SSH or desktop) as the user "pi", type passwd then click Enter. You will then be asked to provide a new password, then confirm it.

Create New User (optional)

Let go ahead and create another user for typical use, since pi by default has access to basically everything its a good idea to have another user for every-day use. If this user gets hacked, the damage will be more contained and easier to fix than if "pi" user were to get hacked. To create a user, open the terminal and enter the following commands (replace instances of [newuser] with the desired username):

adduser [newuser]
usermod [newuser] -a -G pi,adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio

These two commands will first create a new user, then add that user to a series of system groups, thereby granting access to certain commands / applications.

Add Sudo Privileges (optional)

If you are wanting this user to have root privileges, you will need to perform another step. Keep in mind, by giving this user 'sudo' permissions you are potentially giving a hacker keys to the castle, so-to-speak. Only do this if you know what you are doing. First, open a terminal and enter visudo. A file-editor will open, scroll to the bottom of the file and add the line: [newuser] ALL=(ALL) NOPASSWD: ALL. Save and close.

Change Default User (optional)

If you have created a new user, you may want the system to default to it. In order to accomplish this, first open a terminal and enter the following command:

nano /etc/lightdm/lightdm.conf

Then find the line that says "autologin-user=pi" and replace "pi" with your new user.

Setting up Wifi

We are almost there, the last thing we need to do is setup our RPi to automatically connect to your wifi. If you plan on being tethered via ethernet, you can skip this step. The below article has a very detailed explanation of how to configure wifi on your RPi, please read through it and perform the necessary steps.

http://weworkweplay.com/play/automatically-connect-a-raspberry-pi-to-a-wifi-network/

Conclusion

We hope after reading this article you are now up-and-running with your new Raspberry Pi! We here at IoT Shaman use the Raspberry Pi for a large variety of projects, so don't forget to check out our Project Page to see if there are any project that interest you. If anything sparks your interest, feel free to use it to your heart's content or better yet, get involved! Thank you for reading, have a great day!