Now that we have installed Raspbian and have it booting into the graphical environment we can start configuring the Raspberry Pi for our purposes. To be able to configure the Raspberry Pi, the graphical environment has a utility tool installed, which eases up the configuration called Raspberry Pi Configuration:
- To open this tool, use the mouse and click on the Menu button on the top left, navigate to Preferences, and press the Raspberry Pi Configuration menu option, as shown in the following screenshot:
- When you click on the Raspberry Pi Configuration tool Menu option a popup will appear with the graphical version of the raspi-config command-line tool. In the graphical popup we see four tabs explaining different parts of possible configuration options. We first focus on the System tab, which allows us to:
- Change the Password
- Change the Hostname, which helps to identify the Raspberry Pi in the network
- Change the Boot method to To Desktop or the CLI
- Set the Network at Boot option
- With the system newly installed, the default username is pi and the password is set to raspberry. Because these are the default settings, it is recommended that we change the password.
- Press the Change Password button and enter a newly chosen password twice, Once to set the password and the second time to make sure we have entered the new password correctly.
- Press Ok when the password has been entered twice.
Try to come up with a password that contains capital letters, numbers, and some strange characters, as this will make it more difficult to guess.
- Now after we have set a new password, we are going to change the hostname of the Raspberry Pi. With the hostname we are able to identify the device on the network. I have changed the hostname into RASPI3JAVA, which helps me to identify the Raspberry Pi to be used for the book.
The hostname is used on the CLI, so you will immediately identify this Raspberry Pi when you log in.
- By default, the Raspberry Pi boots into the graphical user interface, which you are looking at right now. Because a future project will require us to make use of a display with our application, we will be choosing to boot into CLI mode.
- Click on the radio button that says To CLI. The next time we reboot, we will be shown the CLI.
- Because we will be using the integrated Wi-Fi connection on this Raspberry Pi, we are going to change the Network at Boot option to have it waiting for the network. Later on in the book we will be creating network-based services and we will be logging in from remote locations. Having the network ready before any service requiring a network connection is a good practice.
- Tick the box that says Wait for network.
We have set some default settings, which sets some primary options to help us identify the Raspberry Pi and change the boot mode. We will now be changing some advanced settings that enable us to make use of the hardware provided by the Raspberry Pi:
- Click on the Interface tab, which will give us a list of the available hardware provided. This list is as follows:
- Camera: The Official Raspberry Pi camera interface
- SSH: To be able to log in from remote locations
- SPI: Serial peripheral interface bus for communicating with hardware
- I2C: Serial communication bus mostly used between chips
- Serial: The serial communication interface
- 1-Wire: Low data power supplying bus interface conceptual based on I2C
- Remote GPIO
- A future project that we will be working on will require some kind of camera interface. This project will be able to use both the local attached official Raspberry Pi Camera module as well as a USB connected webcam.
- If you have the camera module, tick the Enabled radio box behind Camera. We will be deploying our applications immediately from the editor. This means we need to enable the SSH option. By default this already is, so we leave the setting as it is. If the SSH option is not enabled, tick the Enabled radio button behind the SSH option. For now, you can leave the other interfaces disabled as we will only enable them when we need them.
- As we now have enabled the default interfaces that we will need, we are going to do some performance tweaking. Click on the Performance tab to open the performance options.
- We will not need to overclock the Raspberry Pi, so you can leave this option as it is. Later on in the book we will be interfacing with the Raspberry Pi's display and doing neat tricks with it. For this, we need some memory for the Graphical Processor Unit (GPU). By default this is set to 64 MB. We will ask for the largest amount of memory possible to be assigned to the GPU, which is 512 MB. Put 512 behind the GPU Memory option; there is no need to enter the text MB. The memory on the Raspberry Pi is shared between the system and the GPU. Having this option set to 512 MB results in 512 MB available for the system. I can assure you that this is more than sufficient.
- Now that we are done with the system configuration, we are making sure we can work with the Raspberry Pi. Click on the Localisation tab to show the options applicable to the location the Raspberry Pi resides in. We have the following options:
- Set Locale: Where you set your locale settings
- Timezone: The time zone you are currently in
- Keyboard: The layout of the keyboard
- WiFi Country: The country you will be making the Wi-Fi connection in
- This book uses the US-English language with a broad character set. Unless you prefer to continue with your own personal preferences, change the following by pressing the Set Locale button:
- Language to en (English)
- Country to US (USA)
- Character Set to UTF-8
- Press the OK button to continue.
As this needs to build up the Locale settings this can take up to about 20 seconds to set up. You will be notified with a small window when this process is finished.
- The next step is to set the timezone. This is needed as we want to have time and dates shown correctly.
- Click on the Set Timezone button and select your appropriate Area and Location from the drop-down menus. When done, press the OK button.
- To make sure that the text we enter in any input field is correct, we are going to set the layout of our keyboard. There are a lot of layouts available, so you need to check yours. The Raspberry Pi is quite helpful and provides many keyboard options.
- Press the Set Keyboard button to open up a popup showing the keyboard options. Here, you are able to select your country and the keyboard layout available for this country. In my case, I have to select United States as the Country and the Variant as English (US, with euro on 5).
- After you have made the selection, you can test your keyboard setup in the input field below the Country and Variant selection lists. Press the OK button when you are satisfied with your selection.
- Unless you are connecting your Raspberry Pi to a wired network connection, we are going to set up the country we are going to make the Wi-Fi connection in so that we are able to connect remotely to the Raspberry Pi. Press the Set WiFi Country button to have the Wifi Country Code shown, which provides us the list of available countries for the Wi-Fi connection. Press the OK button after you have made the selection. We are now done with the minimal Raspberry Pi system configuration.
- Press OK in the settings window to have all our settings stored and press No in the popup that follows that says a reboot is needed to have the settings applied as, we are not completely done yet.
- Our final step is to set up the local Wi-Fi chip on the Raspberry Pi.
We will now set up the Wi-Fi on the Raspberry Pi. If you want your Raspberry Pi connected with a network cable, you can skip this section and head over to the Set fixed IP section:
- To set up the Wi-Fi, click on the Network icon, which is at the top of the screen between the Bluetooth and Speaker Volume icons.
- When you click this button, the Raspberry Pi will start to scan for available wireless networks. Give it a couple of seconds if your network does not appear immediately. When you see your network appear, click on it, and if your network is secured you will be asked to supply the credentials required to be able to connect to your wireless network.
If you have any trouble connecting to your wireless network without any messages, log in to your router and change the Wi-Fi channel to a channel lower than channel 11.
- When you have entered your credentials and pressed the OK button you will see the icon changing from the two network computers to the wireless icon, as it it trying to connect to the wireless network.
- Now that the Raspberry Pi has rebooted, we have configured the wireless network to make sure the wireless network will keep its connection. As the Raspberry Pi is an embedded device targeting low power consumption, the Wi-Fi connection is possible set to sleep mode if after a specific time there is no network usage.
- To make sure the Wi-Fi does not go into power sleep mode we will be changing a setting through the command line that will make sure that this won't happen. To open a CLI we need to open a terminal. A terminal is a window that will show the command prompt where we are able to provide commands.
- When you look at the graphical interface you will notice a small computer screen icon at the top in the menu bar. When we hover over this icon it shows the text terminal. Press this icon to open up a terminal.
- A popup will open with a large black screen showing the command prompt, as shown in the following screenshot:
Do you notice the hostname we set earlier? This is the same prompt as we will see when we log in remotely.
- Now that we have a command line open we need to enter a command to make sure the wireless network will not go to sleep after a period of no network activity. Enter the following in the terminal:
sudo iw dev wlan0 set power_save off
- Press Enter. This command sets the power save mode to off so the wlan0 (wireless device) won't enter power save mode and will stay connected to the network.
We are almost done with setting up the Raspberry Pi. To be able to connect to the Raspberry Pi from a remote location we need to know the IP address of the Raspberry Pi. This final configuration step involves setting a fixed IP address into the Raspberry Pi settings:
- To open the settings for a fixed IP configuration, we are going to open up the settings by pressing the wireless network icon with the right mouse button and press the WiFi Networks (dhcpcdui) Settings option.
- A popup will appear with the settings we can change. As we will only change the settings of the Wi-Fi connection, we select Interface next to the Configure option. When interface is selected, we select the wlan0 option in the drop-down menu next to the interface selection.
If you have chosen to use a wired connection instead of the wireless connection you can select the eth0 option next to the interface option.
- We now have a couple of options available to enter IP address-related information. Please refer to the documentation of your router to find out which IP address is available to you which you can use. My advice is to only enter the IP address in the available fields, which leaves the other options automatically configured, like in the following screenshot. Notice that the entered IP address is the correct one; this only applies to my configuration, which could differ from yours:
- After you have entered the IP address you can click Apply and Close.
- It is now time to restart our Raspberry Pi and have it boot to the Command Line Interface (CLI).
- While it is rebooting, you will see a lot of text scrolling, which shows the services starting and at the end, instead of starting, the graphical interface, we are now shown the text-based CLI, as shown in the following screenshot:
- If you want to return to the graphical interface just type in the following command:
startx
- Press Enter and wait a couple of seconds for the graphical user interface to appear again. We are now ready to install the Oracle JDK, which we will be using to run our Java applications.