Setting up a new Raspberry Pi for electronics hobbyists and makers

Setting up a new Raspberry Pi for electronics hobbyists and makers

Whenever I setup a new Raspberry Pi, or reinstall the operating system because I've broken something or need to test some hardware with a new install, I tend to go through the same steps to get it setup the way I want it.

Sure, there are plenty of guides out there - but many are now dated and most of them are not aimed at people like me - people who mainly want to connect to their Pi from the network, are happy to use the command line, and like to make things and use add-ons with their Pi - so need to have I2C and SPI enabled.

So, without further ado, here's are the steps I follow...

Get Raspbian onto an SD card

We need an OS for the Pi, and there are plenty to choose from, so why Raspian?  Why not Ubuntu?  Or Windows 10?  Other options are great if you want to run a Linux desktop, or setup a media centre, or develop Windows programs (sorry, "apps"), but if you're mainly interested in what you can make with a Pi, whether projects you build yourself or through the many available add-ons, it's easiest to use Raspbian.  It has the most support - more drivers, more software, more people who can help you to get your hardware working.

First download the latest official build of Raspbian from No, not NOOBS. Raspbian.

Then unzip it, creating a 3+ GB image (.img file) that you will then write to an SD card.  This process is pretty well documented here, but briefly: because I use Windows (boo, hiss - would you believe I used to make my living administering UNIX and then Linux servers?), I use Win32DiskImager, which you can download from here, browse to the .img file, select the SD card (e.g. "F:"), click "Write", and then eject the SD card.

I usually use an 8GB card, which is plenty big enough for most things, unless you're going to log a lot of data, in which case a USB drive might be a better option for extra (and removable) storage.

Connecting to the RPi for the first time

Insert the SD card into your Pi - which you will have powered off first!

If you have a spare monitor (or TV) with an HDMI input, or an HDMI to DVI or VGA converter, and a USB keyboard, it's probably easiest to plug those into your Pi to first get it going.  After you connect a monitor to the Pi's HDMI port, and plug in a keyboard, you can apply power to the Pi (via its micro USB port) and, after a bunch of boot messages, you'll find that the Pi is running the raspi-config utility.

Alternatively, if your RPi has a wired (not wireless/WiFi) Ethernet connection, you may be able to use SSH to set it up Raspberry Pi remotel, over the network. It's not ideal, because you won't be able to see the Pi booting, and you won't know its IP address (which will have been allocated dynamically via DCHP, if available). Most home routers act as DHCP servers and provide a list of the IP addresses currently allocated - if you don't have a lot of devices on your network, it's probably not hard to figure out which is the RPi - after having given it a minute or so to boot (you should see a steady connection LED and a flickering traffic LED on the Pi's Ethernet port).  You can then use PuTTY (if you're running Windows) to connect via SSH to that IP address, on port 22.  You should see a "login as:" prompt.

A simpler option, if you don't have a spare monitor and keyboard, but do have some RPi hardware which provides a USB serial port (such as the Wombat prototyping board), is to it to connect a USB port on your laptop or PC to the Pi's serial console.  If you start a terminal emulator (such as PuTTY) and connect via a virtual serial port (such as COM8) at 115200 bps, then apply power to the Pi, you'll see the usual boot messages in the terminal window, followed by a "login" prompt.

If you're using a serial console connection or SSH over wired Ethernet to setup your RPi, you should login as 'pi'. The default password is 'rasbperry'.  You can then type 'sudo raspi-config' and you'll be at the same place as if you'd connected an HDMI monitor and USB keyboard to your Pi.

Initial setup using raspi-config


First, you should expand the filesystem to use the whole of your SD card, to select "Expand Filesystem" and press 'Enter'. Then when that's ddone (it only takes a second) press 'Enter' again.

If you're in an environment where you care about preventing other people logging into your RPi (and, if you ever take it to a meet, you should!), you should next select "Change User Password", press 'Enter' a couple of times until prompted and then, as the prompt says, enter a new (UNIX - but actually this is Linux) password.  Type it again for good measure, press 'Enter' once more, and we're back at the config menu.

By default, Raspbian will log you in to a text console (shell) environment, so there's no need to go into the "Enable Boot to Desktop" section.  Unless of course you do want to work in the graphical desktop, but then you're probably following another guiide, not this one...

Next you'll need to configure Raspbian for your location, so go into "Internationalisation Options".  Since I'm in Australia and speak (a version of) English and use a US keyboard layout, I don't need to worry about changing the locale or keyboard layout.  Your milage may differ.  But I do want to change my timezone, so I go into "Change Timezone", select my geographic area ("Australia"...) then on the next screen my city ("Sydney").  99.9% of people don't live in Sydney, so the odds are that you'll need to choose another location.  Having done so, you'll find yourself back in the main raspi-config menu.

The other things we need to configure are considered to be more advanced, so from here we go into "Advanced Options".

raspi-config advanced options

If you'll be connecting to your Pi over the network, and not using the HDMI or composite video outputs, overscan isn't relevant.

Your Pi needs a name though, so go into "Hostname", read the rules about naming, press 'Enter' and give your Pi a better name than then default "raspberrypi".  When you've entered your new name, you'll find yourself back at the top menu, so you need to go back into "Advanced Options" (over and over again...  Grrr!).

Remote remote access via SSH is already enabled by default, so you can skip the "SSH" option.

The next advanced option is "Device Tree". This is the new, recommended way to load and configure the kernel modules (or drivers) needed to support hardware add-ons. It's already enabled by default, so we can ignore it.

By default, Raspbian doesn't support SPI or I2C devices.  From an electronics hobbyist's or maker's perspective that's crazy - SPI and I2C are very useful ways to connect add-ons to your RPi. For example, the Wombat prototyping board uses SPI for its ADC interface, and our upcoming "Joey" display board (watch this space...) will use I2C.  So we want to enable both.

Go into "SPI", select "Yes" (arrow or tab across) then press 'Enter'. You'll then be asked if you'd like the SPI kernel module to be loaded by default. The answer is "Yes", so select "Yes" then press 'Enter'.

Now repeat for "I2C" - "Yes", you'd like the ARM I2C interface to be enabled, and "Yes" you'd like the I2C kernel module to be loaded by default.

By default, it's possible to login to the console via the serial port.  If you use some hardware (such as a GPS module) which uses the serial port, you'll need to turn this off, via the "Serial" advanced option.  Personally I like to be able to login to the serial console (which is why I designed that feature into the Wombat board!). It's very useful when the network connection isn't working, and saves having to connect a monitor and keyboard - something that's not always practical. So, I leave the serial login enabled.

Finally, if I want my Pi to make sounds, I'll want them to come out of the headphone socket, since the Pi is usually on a workbench somewhere and not plugged into an HDMI monitor.  So I go into "Audio" and select "Force 3.5mm ('headphone') jack".

That's as much as we can configure through the "raspi-config" utility, so, when back at the top menu level, press 'Tab' until you've highlighted "Finish", press 'Enter' then again for "Yes" to reboot, and you'll see the Pi rebooting.

Creating a new user account

When the Pi has rebooted, connect to it as before (HDMI monitor and USB keyboard, SSH over wired Ethernet or serial console), and login as 'pi', using the password you choose earlier.

I don't like working as "pi" though; I prefer to have my own account.

To create an account, type 'sudo adduser', followed by the username you want to add. For example, 'sudo adduser david'.

You'll be prompted for a password, which you'll need to enter twice, plus details such as full name, room number (?!) and phone numbers - it's up to you what details (if any) you choose to fill in, and just press 'Enter' to ignore a field.  Then press 'Enter' to confirm that the information is correct (or 'n' to go back and enter it again...).

For the new account to be as capable as the default "pi" account, it must belong to the same groups as "pi", which you can do with:

sudo usermod -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,netdev,gpio,i2c,spi,input username

where username is the name of the new account, e.g. "david".

It's also very useful for the new account to be able to use "sudo" to run commands with superuser (or root) privileges. That's done by editing the "/etc/sudoers" file (which controls access to the "sudo" command), which you can do by typing 'sudo visudo'. Despite the name, the "nano" editor is invoked to edit the sudoers file, not the "vi" editor (which I personally much prefer, but has a steep learning curve...).

At the bottom of the sudoers file, you'll find the line 'pi ALL=(ALL) NOPASSWD: ALL'. This is the line that gives the "pi" user its superuser powers.  You need to add another line under this, with the same format, but specifying your new account, not "pi".  For example:


Press Ctrl-O to save the file - you'll be prompted for a file name, with "/etc/sudoers.tmp" being the suggestion.  Backspace over the ".tmp" part, then press 'Enter', then press 'Y' to overwrite the file.  Finally press Ctrl-X to exit.

You can now logout from the "pi" account (press Ctrl-D), and then log back in, using your shiny new account, with the password you set earlier.

And finally, while we're working on accounts, you can set a new "root" password, with 'sudo passwd'.  You'll be prompted for a new password - remember that this is for the "root" account, not your personal account.  Of course, you can use the same password for both if you choose to - it's your Pi!

Setting up WiFi

If you have WiFi (and these days, who doesn't?) and a supported USB WiFi "dongle" (most are supported...), plug it into one of your Pi's USB ports.

Instructions for setting up WiFi from the command line are available here,

Essentially you only need to know your WiFi network's SSID (name) and PSK (password), and then use your favourite eidtor (not necessarily nano...) to add appropriate 'ssid=' and 'psk=' lines to the "/etc/wpa_supplicant/wpa_supplicant.conf" file.

Restart the WiFi interface and verify that it's working with:

sudo ifdown wlan0
sudo ifup wlan0
ifconfig wlan0

You should see an IP address listed alongside "inet addr" - take a note of it; you should now be able to connect to it over the network via SSH, logging in with your new user account.

The IP address is likely to have been dynamically assigned using DHCP, in the same way as described earlier for wired Ethernet connections. It's usually convienient to have a fixed IP address for your RPi, so that you don't have to figure out what its IP address is every time you try to connect to it! Although it's possible to configure the Pi to use a fixed, or static, IP address (by modifying the "/etc/hosts" file), it's often better to configure your router to reserve an address which it will always allocate in response to a DHCP request from the Pi - there's much less chance of ending up with IP address conflicts on your network that way!

Updating Raspbian

Now that we have a Raspberry Pi that we can log into via SSH over WiFi, using our own account and with superuser powers available to us, we can get to work! But there are a couple more things to do first...

Like most open source software, the Raspbian Linux distribution is often updated and improved, so before doing anything more we should bring our Raspbian installation up to date, with:

sudo apt-get update
sudo apt-get dist-upgrade

then press 'Enter' to continue, and then reboot with 'sudo reboot'.

You should then repeat this update process every so often (once a month or so) - unless you've built an embedded application where it's a case of "if it ain't broke, don't fix it" - sometimes updates create problems and if your system is dedicated to a purpose and is stable, it might be safer to leave it well enough alone.

Adding I2C Device Support

Finally, we'll finish configuring the system for I2C support.

Didn't we do that earlier, with the raspi-config utility?  Yes - the kernel now loads the I2C module, which you can verify by running the 'lsmod' command: the output should include "i2c_bcm2708", which is the driver for the I2C hardware within the RPi's Broadcom SOC.

That's great - but a vital piece is still missing!  Most drivers for I2C add-ons expect to connect via the I2C device files in the "/dev" directory, and by default Raspbian does not create these device files - not even after I2C has been enabled with raspi-config.

Use your favourite editor (vi, anyone?) to add a 'i2c-dev' line to the "/etc/modules" file - you'll need to use 'sudo' to access it, e.g. 'sudo nano /etc/modules'.

The "/etc/modules" file should now contain:


After a reboot ('sudo reboot'), the "/dev" directory should now contain an "i2c-1" file (or "i2c-0" if you're using one of the original Raspberry Pis).


Of course, there's always more to do when it comes to setting up a new computer or operating system, but at this point we have a Raspberry Pi running the latest version of the recommended operating system, which we can connect to using SSH via WiFi, logging into a personal user account with superuser access, and with fully enabled and usable SPI and I2C interfaces to use in our projects.

That's good enough for now...  Time to go and make something!

Posted by David Meiklejohn

Products related to this article

Related Articles

How to use ITEAD's 2.8" LCD touch screen for Raspberry Pi (v2.0)

Setting up and using the ITEAD 2.8" TFT LCD touch screen for Raspberry Pi v2.0

1 comments on this article - view comments
How to use ITEAD's 16x2 character LCD display for Raspberry Pi (v2.0)

Setting up and using the ITEAD 16x2 character LCD display module for Raspberry Pi v2.0

1 comments on this article - view comments
How to use ITEAD's 128x64 OLED display for Raspberry Pi (v2.0)

Setting up and using the ITEAD 128x64 OLED display module for Raspberry Pi v2.0

0 comments on this article - view comments

2 Comments To "Setting up a new Raspberry Pi for electronics hobbyists and makers"

Anders Jackson On 28 Oct 2015
Great tutorial: Some comments. You don't need to change /etc/sudoers, as you already added the user to the group sudo. Every user belonging to that group can use sudo. (It is good that you uses visudo though, as that also check the contents so you don't write some errors in that file, as you wouldn't be able to do sudo at all if you get that wrong) I would recommend against using ifconfig, as it is marked as obsolete. Us the much more competent program ip instead. Specificly 'ip address list' (or ip ad' for short). If you only want to add to the end of a file, you could use redirect to write to the end of the file. Either as root do echo "i2c-dev" >>/etc/modules or echo "i2c-dev" | sudo tee /etc/modules That is just suggestions, your post is a good summery of setting up a Raspberry Pi. (If you don't uses Graphics, you could also change the split between graphics and CPU use of the computers memory in 'Advance Options') Reply to this comment
David Meiklejohn On 02 Nov 2015
Thanks Anders! I agree with your suggestions, except for the change to /etc/sudoers. Yes, it's true that adding a user to the 'sudo' group will allow that user to use sudo - but they'll be asked for their password every time they use it. Adding the line with the "NOPASSWD" option avoids this - it's much more convenient!

Write a comment

Your Name:

Enter the code in the box below:

Your Comment:
Note: HTML is not translated!
Powered By OpenCart
Gooligum Electronics © 2021