# Initial Configuration

## Initial Configuration:

.

This guide assumes a fresh install of Raspbian OS on your Raspberry Pi. The card shipped with the Spirit Rover already has this OS installed. It can also be downloaded and added to your own microSD card following instructions at the official Raspberry Pi website.

Advanced users can follow these instructions or use their own. This is a general guideline to get your Raspberry Pi setup and ready for use on the Spirit Rover.

For these steps you will be using the Linux based operating system on your Raspberry Pi. You will do most of these steps using a terminal or console window without a graphical user interface. This is how the power users do it. It can be a bit complicated and overwhelming if you've never worked with a terminal window before. Just hang in there and try to type the commands exactly as shown. You may need to use google and watch some YouTube videos if you need help with the specifics. We'll try to make the guide as user-friendly as possible, but as you will soon discover with Linux and more advanced code, you will need to be resourceful in finding your own answers to some questions. This is how all the power users have learned and they all feel a bit overwhelmed at first.

**VERY IMPORTANT NOTE:** The Raspberry Pi draws a lot of current from the battery. If you begin working on the Pi and don't have your Spirit charged, you may find the Spirit wants to turn off due to low battery after a while. You may want to leave the Spirit plugged into a USB connection for a while before starting. The orange CHG (charge) LED next to the battery connector will remain lit during charging and will turn off automatically when charging is complete. You can operate the robot during charging, so you may want to leave this plugged in during the setup process as it may take a while.

.

## Startup and WiFi Setup:

The first step is to startup the Pi and connect to WiFi. This will allow you to remotely access the Pi from another computer, which is where you will do most of your interaction from.

For the first startup, we suggest attaching an HDMI cable to the Pi (this can all be done while it is installed in the Spirit robot). Also attach a mouse (optional but useful for the very first step) and a keyboard. We suggest using corded mouse and keyboard. The wireless dongles used for wireless keyboards and mouse may pull more current from the device than necessary and may cause it to shut down).

**Raspi-Config**

On first boot, the Raspberry Pi will likely boot into the graphical desktop environment.

Open a terminal window (it is the black monitor symbol in the upper left corner).

Start the Raspberry Pi configuration utility with this command:\
`sudo raspi-config`

Make the following changes:

(Optional)\
Select Internationalisation Options and set I4 Change Wi-fi Country options if needed.

(Required)\
Boot Options > B2 Text Console Autologin Text Console as 'pi' user.\
Advanced Options > A4 SSH > Enabled, Module Loaded By Default > Yes\
Advanced Options > A7 I2C > Enabled, Module Loaded By Default > Yes

Once these have been set, select \<Finish> and reboot when prompted. If you miss it or are not prompted, you can goto the menu and select shutdown and reboot.

After reboot, you should see a screen with lots of text scrolling as the Pi reboots. When complete, you will be presented with the standard Linux prompt. pi\@raspberrypi: $

**Keyboard**

The Keyboard setup is massively over-complicated. If you discover your keyboard won't type double-quotes, you will need to manually change the keyboard setup. There are options to do this in the raspi-config above, but you're presented with a few thousand options and none of them seem to work (at least not with any of the keyboards I own). If this is your situation, perform the following:

At the command line, type the following:\
`sudo nano /etc/default/keyboard`

Edit the file that appears, being careful to not delete the existing double quotes. Make your file look like this:

`XKBMODEL="pc101"`

`XKBLAYOUT="us"`

`XKBVARIANT=""`

`XKBOPTIONS=""`

`BACKSPACE="guess"`

To save the file press Control-X to exit, then press Y to save changes, then press return or enter. This should return you to the command prompt with the file saved.

You can verify the file is correct by typing:\
`cat /etc/default/keyboard`

This should display the file in the terminal window.

Reboot the Pi by typing `sudo reboot`

After the reboot, your keyboard should now work. You can test this at the command prompt after the reboot by trying to type a double-quote at the command line. If you get a double quote, then you're good. If you're still getting an @ symbol or something else, you'll need to try a different configuration. Try google for this (as I said, this step is massively over complicated, the first time I used a Pi it took me hours to get just this part working).

**Set Pi to Connect to WiFi**

In this step we will set your Pi to automatically connect to your WiFi network so you can access it from a different computer, like your normal PC or Mac, etc.

Edit the file that controls access to WiFi networks. Enter the following command at the command prompt. Enter it very carefully. If a blank document comes up with no content, then you have likely made an error typing the name and path.

`sudo nano /etc/wpa_supplicant/wpa_supplicant.conf`

Under the text already present in the file, add the following. Note the curly braces. If this is not correct, it won't connect to your WiFi. Enter your network SSID (the name of your network) and your WiFi password where indicated.

`network={`\
`ssid="your wifi ssid network name"`\
`psk="your wifi password"`\
`}`

Press Control-X, then Y, then Enter to save the file. You can verify the file by typing:

`sudo cat /etc/wpa_supplicant/wpa_supplicant.conf`

Reboot the Raspberry Pi with sudo reboot

After the reboot, verify your Pi is connected to your WiFi network by typing:\
`ifconfig`

Look at the section next to "wlan0". If it is connected, the second line of this section should show the IP address your WiFI router assigned to your Pi. It will say `inet addr:192.168.1.10` (or something similar). The address should end in something other than .1 Make note of this IP address. Note that it may change from time to time, as this address is assigned by your WiFi router, and it may occasionally change up addresses depending on what other devices you have connecting to your WiFi. The IP address is just the number part with the periods between. In the example above, the Pi has the IP address of `192.168.1.10`

These instructions should work in most cases. If you still have trouble, you'll need to spend some time on the internet searching for how to connect your Raspberry Pi to WiFi. You can connect your Pi through the graphical interface (which you can re-launch at any time by typing `startx` at the command line), but the Pi may not always automatically re-connect on boot.

To verify that your Pi can be found and connected to from your WiFi network, use the computer you plan to use for working on your Spirit and download the [Adafruit Pi Finder](https://github.com/adafruit/Adafruit-Pi-Finder/releases/latest) application. Select the correct version for your operating system from the link.

When you run the application you should get a small window with the Adafruit flower logo. Click the button to find your Pi. It will search for a minute and hopefully come up with a result. The IP address displayed should match the address you saw in the `ifconfig` step above. You can then exit the Pi Finder application.

At this point, you should be able to connect to your Spirit Pi unit from another computer.

**Connect using SSH and SFTP**

Note: When logging into your Pi, the default login details are Username: `pi` Password: `raspberry`

You will generally connect to your Pi using two pieces of software. The first piece of software is called an SSH Client, which is software you will install on your computer (the one you will use to work with your Spirit). If you google "SSH Client" you will find lots of options. I suggest **MobaXTerm** for PC users. It is fairly full featured and free.

SSH basically presents a console screen on your PC (or Mac, Linux, etc) computer that looks just like the terminal window you have been using. It works the same as typing directly into your Pi with an attached keyboard. This allows you to type all sorts of Linux commands to the Pi, and this is how power-users interface with all kinds of servers - everything from Raspberry Pi to web servers and the like. Learn as much as you can about this console / terminal operation as you can. It will be useful as you do other things with Linux in the future.

While SSH allows you to type commands, it's not user friendly for moving files to and from your Pi. For this function we will use a different piece of software called an SFTP client. SFTP stands for Secure File Transfer Protocol. Like SSH clients, there are many options available. I suggest using **WinSCP** for Windows users. It is free and fairly user friendly. This program creates a window on your PC that has your local computer file system on one side, and the file system on your Pi on the other side. You can drag and drop files in either direction between your PC and the Pi. When you start writing your own python code, I find this is the easiest method to move your code files onto your Pi.

Download and install an SSH client and SFTP client onto your working computer, and attempt to connect with both to your Pi. You may need to dig around the net a bit for specifics on this. Google and YouTube are good resources for this.

If you can connect via SSH and see a command prompt in the terminal window (which will look just like the window you worked in above when typing other commands directly into the Pi) then you are all set. Same thing with connecting via SFTP.
