Several Tips for Raspberry Pi Beginners

by Cindy Ding on October 09, 2018

Thanks for your attention with Geekworm. We get this blog is to provide quick help to Raspberry Pi beginners on the Raspberry Pi projects.
This post is a collection of answers to questions you will inevitably ask if you start on Raspberry Pi.

What are the most important tips to know when you are a raspberry pi beginner?


Well, there are a lot of tips to know, but the first questions you’ll probably ask are:

  • How to enable SSH: sudo service ssh start ?
  • How to update your system: sudo apt-get update && sudo apt-get upgrade ?
  • How to set a static IP: edit /etc/dhcpd.conf ?
  • How to change the keyboard layout: sudo raspi-config ?

First Start

Hardware
Before start your raspberry pi, you have to plug the power cable to the mini micro USB port
If possible, also plug an HDMI cable to your screen or tv and a keyboard

If you get some heatsinks with your kit, they are not mandatory, but you can install them on your Pi, it is very easy.

Operating system
If it was not provided with your kit, you have to create a new SD card with Raspbian on it.
You need a micro SD card like in some phones or cameras
If you don’t have one, you need to buy one online.

Once you have both hardware and SD card ready, you can start the Raspberry Pi by clicking the power switch. Please note there is no button on the Raspberry Pi board directly, it starts as soon as it’s powered.

Install Raspbian

If you are new on Raspberry Pi, Raspbian is a Linux distribution optimized for Raspberry Pi.
You have to create an SD card with Raspian on it, and then start.
You can follow this guide to install Raspbian for the first time.

There are two versions of Raspbian:

Lite: without GUI, for embedded systems or to save power or disk space.
Desktop: with GUI, to use it as a classic computer.
If you are new in Linux or Raspberry Pi, we recommend installing Raspbian with Desktop.

Get a command line

For all the tips below,we will only explain how to do it with commands so that everyone can follow them
If you choose the Desktop version, you have to use the Terminal app to enter the following commands.
You can find it in the taskbar or in the main menu, under “Accessories”

Most of the time there is an equivalent for the Desktop version, to do this with a graphical tool
If you don’t want to use commands, first look in the main menu if you could find something to do the same.
Often you can do this in the Main menu > Preferences> Raspberry Pi configuration tool

Default password

On the first boot, the Lite version will ask you for a login and password

Here is the default Raspbian user:

Login: pi
Password: raspberry
On the Desktop version, the welcome wizard will ask you to change this password, so you don't need this.

Be careful the keyboard layout is US (QWERTY) by default on the Lite version
We'll explain in the next paragraph how to change it, but for the first login you'll have to adapt (enter rqspberry for example if you have an AZERTY keyboard)

Change the keyboard layout

On the Lite version, the first boot is made in QWERTY mode
If you have another keyboard layout, you have to change it using raspi-config:

sudo raspi-config

Then go to Localization and change the keyboard layout.
You can also change here some custom options for your keyboard (regions layouts or specific keys)

Raspi-config is a great tool to manage a lot of system options
Feel free to check it in detail before looking for a complicated command.

On the Desktop version, I never had issues with the keyboard because you can configure it directly in the welcome wizard
But if you have issues, you can also use raspi-config in a terminal

Change the password

If you want to change the pi password you can use this command:

passwd

This command will ask you the current and the new password.
If everything is correct, the password will change immediately (your current session will stay active)

Don’t enable any remote connection tool (like SSH or VNC) if you haven’t changed the default password. This is a major security issue.

Connect to the network

If you have a DHCP server on your network (generally your Internet box), it will be easy
As soon as you connect the ethernet cable, you’ll get an IP address and be connected

But if you don’t have a DHCP, or if you need to set a static IP, then you have to edit the /etc/dhcpd.conf file:

sudo nano /etc/dhcpd.conf

You’ll find all the information to set a static IP on the Raspberry Pi in my Raspbian installation guide
I also explain how to set up a WiFi connection from a terminal.

If you are on the Desktop version, you should use the graphical tool to configure this. It will be much simpler
Click on the network icon in the top navigation bar and you’ll get all you need to configure the network connection, with cable or wireless.

Find your IP address

For your first remote connection to your fresh installed Raspberry Pi, you’ll need to find his IP address. If you have a screen on it, you can use ifconfig to display it:

ifconfig

This command will show you the current IP address



The first IP (eth0) is for the ethernet cable, the second (wlan0) corresponds to the WiFi connection

If you are on another computer, you can read this article on how to find de Raspberry Pi IP address
I explain how to scan the network to find your current IP address.

Change the date/time

To check your current date and time you can use this command:

date

This command will display the date, the time and the timezone

If you need to change it, you can use raspi-config to do this:

sudo raspi-config

Go to Localisation Options => Change Timezone
Then select your Geographic area and your nearest City to set the correct timezone.

Sudo command (be root)

Debian, and so Raspbian, tries to prevent the users from using the root account
If you have enough privileges (pi has), you can use sudo instead
Every command you add after the sudo prefix will be run with root privileges.

pi@raspberrypi:~ $ whoami
pi
pi@raspberrypi:~ $ sudo whoami
root

This command will be useful to manage system files or services.
Every time you don’t have access to something, you need to use sudo to unlock it

Here are some examples:

sudo service ssh start
sudo nano /etc/dhcpd.conf

If you have a lot of commands to run as root, it’s always possible to switch to a root session with this command:

sudo su

Another tip for sudo is to use sudo !! to run the last command with sudo (if you forgot it)

sudo !!

Enable SSH

SSH is disabled by default for security reasons.
If you need it you have to start it with this command:

sudo service ssh start

But as you’ll quickly see it, you’ll need to do this after each reboot.
The service doesn’t start automatically

To start it on each boot, you have to use these two commands:

sudo update-rc.d ssh defaults
sudo update-rc.d ssh enable

On the next boot, SSH will start automatically.

Update the Raspberry Pi

After a new install and also regularly, you need to update your system, to get the last version of each installed package.
Firstly you need to get the last version of the packages list

sudo apt-get update

Then upgrade all packages to the last version

sudo apt-get update

You can also look for distribution upgrade

sudo apt-get dist-upgrade

Install a new software

To install new software, you need to know the exact package name
To do this the best way is to use the search tool from apt

sudo apt-cache search 


Here is an example:

sudo apt-cache search myadmin
adminer - Web-based database administration tool
phpmyadmin - MySQL web administration tool
Then you can install your package with
sudo apt-get install phpmyadmin

Edit files with nano

Nano is a great tool to edit files in the terminal
You may also know vim which is another good editor, but on Raspbian only nano is installed by default.


To edit a file, you need to use nano with the file name in the parameter
Here are some examples:

nano 
nano test.txt
nano /home/pi/Documents/file.txt
sudo nano /etc/dhcpd.conf
Unlike vim, once in the editor you can directly write and edit the text

There is a list of actions you can do to help with editing.
All are listed at the bottom of the screen
For example:
  • CTRL+O: Save the file
  • CTRL+X: Exit nano

We hope that these few lines will be enough to help you get started.

Stop or restart properly

Most likely, you have already found that it’s possible to turn off the Raspberry Pi by pressing the power button .
But it’s better to do it properly with these two commands

To stop the Raspberry Pi immediately use:

sudo shutdown -h now

If you use this to stop the Raspberry Pi, you’ll need to press the power button twice for the next start

And to restart the Raspberry Pi:

sudo reboot

Run and schedule a script

If you start creating scripts or using advanced software, you may need to schedule something to start at a specific time
For this, there is a tool called “cron” on Linux
You can schedule commands in your user environment by using crontab

To display all planned crons

crontab -l

To edit the crontab list

crontab -e

This command will open the crontab with nano (you can choose another editor the first time)

For each new script to schedule you have to add a line following this syntax:

A B C D E /home/pi/myscript.sh

The first five columns define the time you want to start the script, following this rules:

  • A: Minutes (0-60)
  • B: Hour (0-23)
  • C: Day of the month (1-31)
  • D: Month (1-12)
  • E: Day of the week (0-7), 0 and 7 are Sunday, 3 is Wednesday, 6 is Saturday

And the last column is the command to run at this specific time

If you need to run your script as root, you can use sudo to open the crontab

sudo crontab -e

Uninstall programs

Well, if you want to remove some packages from your system, you have to use apt-get to uninstall them.
As for the installation, you need to know the exact package name to remove it.
To search for a package, use this command

sudo apt-cache search <search-name>

You can also display all your installed packages with this one

sudo dpkg -l

Feel free to use grep to filter the output

sudo dpkg -l | grep <search-name>

Then, to uninstall the package, enter this command

sudo apt-get remove <package-name>

Backups

Backups are an important thing to think about when you start doing a lot of work on your Raspberry Pi
There are several ways to do this:

  • Backup only the critical files (configuration, MySQL database, …)
  • Clone the entire SD card
  • Backup the whole system while running

You’ll find all the information in my backup guide for Raspberry Pi.

Play games

Raspberry Pi is often associated with retro gaming, but rarely explains how to do it.

So if you bought your first Raspberry Pi, you might be looking in Raspbian how to play games
Well, there are some small games in Raspbian, but I don’t think that’s what you want
To play classic games from old game consoles, you need to install the Retropie distribution.

It’s an entire operating system, dedicated to retro gaming
You can download it from the official website
And then you’ll find some information about game download on this post .

Free space

If your SD card is full, you may need to free space
To see your current disk usage, use df

df -h

This will display something like this


On the first line, you can see I have 15G on the main partition.
I’m using 1.2G so 9%
If you are above 80%, this paragraph will help you find and remove unnecessary files

To get the biggest files on the SD card, I often use this kind of command:

cd /
du -ak | sort -nr | head -50
This command will display the 50 biggest files or directories in the / partition
If you want to focus on a specific folder, change the first line
Then check if every file in the list is needed for you, if not remove it

Another easy way to gain space is to remove wolfram and LibreOffice if you don’t use it
sudo apt-get remove --purge wolfram-engine libreoffice*

This command will free about 1G in a fresh Raspbian Desktop installation

If this is not enough, you could check this article on how to uninstall programs
There are some other tips to free space at the end.

Check temperature

If you are worried about the temperature of the Raspberry Pi, there is a way to check it

This command will give you the current temperature of your CPU in real-time:

/opt/vc/bin/vcgencmd measure_temp

You have to keep it under 85°C if possible
If you exceed this threshold, Raspbian will start to run slower

If you have issues with your Raspberry Pi temperature, consider adding heatsinks or even a fan to keep it low

Create a new user

When you install Raspbian, a new user is created for your: pi

But if you want a more personal account, you can create a new one
To do this, enter this command:

sudo adduser <login>
Replace <login> with the name you want for your new user
This will ask you the password and other optional information

If you’re going to allow the new user to use sudo, you have to enable it like this:
sudo visudo

This will open the sudo configuration file
Scroll down to the line for the pi user and duplicate it
Something like that:

 ALL=(ALL) NOPASSWD: ALL

Then you are ok. The new user has the same rights than pi.

Disable WiFi

You may want to disable the WiFi if you are now plugged by cable
I already noticed network issues when both ethernet and wireless connections are enabled

So, if you’re going to disable the WiFi temporarily you can disable the interface like this:

ifdown wlan0
The interface will come up at the next boot, or you could force it with this command:
ifup wlan0
But this won’t work if you want to disable it permanently
To completely disable the wifi follow these steps:

Edit the boot configuration file
sudo nano /boot/config.txt
Add this line at the end of the file
dtoverlay=pi3-disable-wifi
Save and exit (CTRL+O, Enter, CTRL+X)
Until you remove this line in the configuration file and reboot the Raspberry Pi, your Wifi will never come up again

Use camera

The Raspberry Pi doesn’t come with an integrated camera, but you can buy and install one easily.
However, there is one tip to know about this: the camera port is not enabled by default
You have to do it using the raspi-config tool:

sudo raspi-config
Then go to :

 

  • Interfacing options
  • Camera
  • Confirm that you want to enable the camera interface

Then you’re ready to go
You can test the camera with raspistill:

raspistill -o image.jpg
This command will create an image file in the current directory with the camera view

You’ll find a lot more information to start with the camera in this page

 

Mount USB drive

If I remember well, USB drives are automatically mounted in /media/pi with Raspbian Desktop
But on Raspbian Lite you need to do it yourself

Follow these steps to mount your USB drive

Plug the USB drive in the Raspberry Pi
Create a folder in /media to use it later to access the drive

sudo mkdir /media/usbkey
Change rights to allow pi to access it later
sudo chmod 777 /media/usbkey
List the connected drives to get the UUID
sudo blkid


Note the UUID and the file format. You’ll need this later

Edit the fstab file to prepare the mount
sudo nano /etc/fstab
Paste this line at the end of the file
UUID=B17B-299B /media/usbkey vfat defaults,nofail 0 0
Don’t forget to replace UUID and file format to fit your USB drive values

Save and exit (CTRL+O, Enter, CTRL+X)
Mount the drive
sudo mount /media/usbkey/
Check that you can see files on it
ls /media/usbkey
It should be ok now

This procedure will automatically mount this key at each boot if you plugged it before
If you plugged it after the boot, you’d need to use the mount command

 

Use GPIO

A great feature on the Raspberry Pi is the GPIO pins you’ll find on the main board


This pins have a lot of purposes, like adding hats to your Raspberry Pi
It’s something similar to the PCI slots on a computer

But every pin has his role and configuration, and you need to comply with it
The best thing you can do is to use a guide with pictures, like on this site

This article is a reprint article from RaspberryTips.com!  If there any Infringement, please cotnact us, thank you!

To get more latest information about Geekworm, please follow us on Facebook , PinterestInstagram , Youtube.

LEAVE A COMMENT

Please note, comments must be approved before they are published


BACK TO TOP