Wednesday, September 21, 2016

Raspberry Pi Basics

 

I started out with a new (Dec 2016) Raspberry Pi v3 purchased online from Amazon.   When I first tried this project I spent a lot of time getting basic functions like WiFi working.  The new Pi has onboard wifi and bluetooth, which makes things much easier, as the Linux OS is preconfigured to use them.

The Raspberry Pi comes without an operating system, and without any storage.  It has a Micro-SD slot and four USB ports.  It is configured to boot from an operating system on the Micro-SD slot.  Best practice is to put the operating system on a fast Micro-SD card, and use a USB thumb drive to store data.

Operating System Installation

Any Linux OS will work on the Raspberry Pi, but it is best to use a variant that has been built specifically for the Raspberry Pi.  I chose the most common on which is called Raspbian.  Raspbian has named major releases, the first was called Debian, the second and latest is called Jessian.

The operating system is downloaded from the Raspberry Pi website.  There are two sets of installation files to choose from:  "New Out of The Box" aka NOOBS, which is a simple version with everything pre-configured, and a version to self-configure.  I chose NOOBS.  Here are the steps:

  1. Download NOOBS to my Macbook
  2. Unzip the NOOBS download
  3. Insert the SD card into my Macbook
  4. Using the Mac Disk utility format the SD card as MSDOS
  5. Using Finder, copy the NOOBS files into the root directory of the SD card
  6. Put the SD card into the Raspberry Pi's SD card slot.  Connect keyboard, mouse and monitor and boot it.
  7. The Raspberry Pi presents a configuration screen.  I selected Raspberry Pi "JESSIAN" operating system full version, and English-US keyboard.  I did not configure WiFi at this stage.  The software then proceeded to install and configure itself and booted up to a Linux desktop.

Configuring WiFi on a Rapsberry Pi 3 with JESSIAN is easy.  No editing of files like the previous version, just click the WiFi icon, select the network SSID, enter the network password and you are done.

With the wifi now working, I want to set the PC up for remote access.  I want two types of remote access: SSH terminal access and RealVNC screen sharing.  I will do the SSH first, as once I have that I can configure the Raspberry Pi for RealVNC remotely over SSH.

The Raspberry Pi comes with a default user account called "pi" with a password of "raspberry". First thing to do is to reset the password for the account pi.  This can be done by opening a terminal window on the Pi and using the  passwd  linux command.  Note that you will be forced to select a complex password that is not based on a dictionary word.

Static IP Address

Because I don't want to have to reconfigure my SSH and VNC settings each time the Raspberry Pi device is assigned a new IP address by DHCP, the next thing to do is to configure the Raspberry Pi for a static IP address.  This involves two steps: (1) reserve an IP address for the Raspberry Pi on the router and (2) configure the reserved IP address on the Raspberry Pi.

For my router I'm using an airport extreme, so I open the Airport Utility, select the Airport, select Edit.  On the network tab I add a DHCP reservation for the Raspberry Pi.  I chose 192.168.0.30

The Raspberry Pi's Static IP address on the WiFi interface is configured by editing the file /etc/dhcpcd.conf and adding the following lines at the end:

    interface wlan0

    static ip_address=192.168.0.200/24    static routers=192.168.0.1    static domain_name_servers=192.168.0.1

Secure Shell (SSH)

I enable the Raspberry Pi's SSH server.  On the Raspberry Pi terminal window, run the  rasbpi-config  command.  Select "Advanced Options" then enable both SSH.

If I open a terminal window on my Mac I can run:
       ssh pi@192.168.0.23
I am then prompted for a password and I am able to enter script commands directly to the Raspberry Pi.

Configure USB Drive For Storage

Here's a good Instructable on setting up the USB drive.  It was straightforward to follow.  After formatting it I created two directories in the USB drive root - /code and /data.  When I configured the USB drive into the Raspberry Pi file system I made it /usbdrv, so on the Pi the directories will appear as /usbdrv/code and /usbdrv/data.   I also made a second mapping so that my code and data folders would appear under /home/pi/usb.

File Transfer

To be able to easily transfer files between my Macbook and the Raspberry Pi, I use the Macbook's Finder app and configure the Raspberry Pi as a remote server by selecting
     Go / Connect to Server



The Raspberry Pi's file system is now visible in the Finder left nav in the "Shared" section.  I am able to navigate to the /usbdrv folder which represents the USB drive that is plugged into the Raspberry Pi.



In the dialog that appears I add afp://192.168.0.23, and when prompted I enter the username pi and the password that I changed on the Raspberry Pi.

Remote Desktop (VNC)

To remotely control the Raspberry Pi's desktop requires three tasks

  1. Enable the VNC server function on the Raspberry Pi's BIOS
  2. Set the VNC server running
  3. Run VNC client software on my Mac and make a connection to the Raspberry Pi

I enable the Raspberry Pi's VNC server.  On the Raspberry Pi terminal window, run the  rasbpi-config  command.  Select "Advanced Options" then enable both SSH.

To set the VNC server running, run the following command:
vncserver :1 -geometry 1024x600 -depth 16 -pixelformat rgb56
Next to access the remote desktop on the Raspberry Pi.  I downloaded the Mac VNC viewer application from the RealVNC website.   I launch the app and enter the details of the Raspberry Pi
   192.168.0.23:5901

Note - the password entered is not the password associated with the Pi account on the Raspberry Pi - it is the password that was entered as the VNC password when VNC was installed on the Raspberry Pi.

I am now able to remotely control the Raspberry Pi's desktop (of course being careful to use the Mac's Control Key instead of the Command Key!)


Next Steps

Once all that's in place then I can move on to the new sensor board, and accessing it via the Raspberry Pi's i2c Serial Bus.

No comments:

Post a Comment