Setting Up The Raspberry Pi

This article discusses how you setup the Raspberry Pi hardware for the EGB320 design project. We recommend you read the general introductory guide before setting up your Raspberry Pi.


Imaging The MicroSD Card

The operating system for your Raspberry Pi will be hosted on a microSD card inserted into the bottom of the Pi. The microSD card included in your EGB320 kits is most likely blank. If the microSD card is blank please look at the Imaging Your MicroSD Card guide to install the EGB320 Raspbian image. The microSD card must have a valid image for the Raspberry Pi to operate correctly.


Installing Your MicroSD Card

The newly configured EGB320 Raspbian image you installed in the previous step contains;

  • OpenCV 3,
  • Python 3,
  • LCD Screen Management,
  • Network Manager, and
  • A demonstration Python3 script for the camera

If you have not already inserted your microSD card, simply insert it into the microSD slot located on the right hand side of the Raspberry Pi in the following image.

Image Not Found
The Raspberry Pi with the MicroSD Card Inserted

Attaching the GPIO Breakout Board (Optional)

If you plan on directly attaching the screen to the GPIO pins and not via cables then we recommend you attach the small GPIO breakout board now. If you do not attach this small board and have the screen directly attached you will not be able to access the GPIO pins. The small GPIO breakout board should be connected to pins 29-40 inclusive, which are the GPIO pins located closest to the USB/ethernet ports.

The GPIO breakout board attached to the Raspberry Pi.

The pinout of the GPIO breakout board is 1 to 1 with the Raspberry Pi layout.

Attaching The Raspberry Pi Camera

To install the camera module, first locate the camera cable slot which is situated next to the HDMI port. Next lift the small black clip of the cable slot; you may need to remove a piece of brown-ish plastic tape. Insert the ribbon cable into the slot with the blue strip facing the USB/Ethernet ports. Push the clip back into place ensuring the cable is firmly locked in place. If you plan on attaching the touchscreen, we recommend that you place the camera so the ribbon cable extends over the USB/Ethernet ports.

Before and After Raspberry Pi Camera Attachment

Attaching The Screen

First attach the four supplied stand-offs to the four screws which can be found on the back of the screen.

Image Not Found
The HDMI Touchscreen with Stand Offs Attached

Next attach the screen's female header to the Raspberry Pi GPIO pins. The HDMI ports on the screen and Raspberry Pi should align. With the stand-offs in place the screen should only fit to the Raspberry Pi in one configuration. Now using the HDMI to HDMI adapter board connect the two HDMI ports. IMPORTANT: if you do not align the pins correctly while attaching the screen, and proceed to power the Raspberry Pi, you can cause damage to the touch capabilities of the LCD screen. We will not be replacing any damaged touch screens.

Image Not Found
The Rear View of the Pi with the HDMI Touchscreen Attached

Image Not Found
The Front View of the Pi with the HDMI Touchscreen Attached

Powering the Raspberry Pi

Before powering the Raspberry Pi connect the supplied Edimax WiFi dongle as well as a USB mouse and keyboard, and a HDMI screen if you wish.

To power the Raspberry Pi simply use the 5V Wall Power Supply and plug it into the micro USB connector onboard. A red LED near the micro USB port will light up, and if you have a screen attached it should show some activity. It may take a moment to boot up, especially when booting it for the first time.

IMPORTANT: the Raspberry Pi 3B+ requires a 5V power supply that can supply 2.5A and you should only ever supply power via the micro USB connector. Supplying power via the 3.3V and 5V rails within the GPIO pin header is risky, as it bypasses the protection circuitry. Additionally, you should always try to power down the Raspberry Pi properly (i.e. main menu -> shutdown). Only pull the power plug if the Raspberry Pi is not responding and you have no remaining options.


Setting Up The Screen

If you are using the LCD screen it should boot up and display correctly. However, at times you may find your Raspberry Pi displays poorly either on the LCD screen or on a standard HDMI desktop monitor. To get your Raspberry Pi to display correctly you will need to run a command within a terminal. To open a terminal you can either select the terminal icon within the menu bar on the top left of the screen, or press CTRL+ALT+T on the keyboard.

To get the Raspberry Pi to display correctly on the LCD screen, run the following command in a terminal. This command will cause the Raspberry Pi to reboot.

sudo LCD5-show

To get the Raspberry Pi to display correctly on a standard HDMI desktop monitor run the following command within a terminal.

sudo LCD-hdmi

Configuring and Testing The Raspberry Pi Camera

To be able to use the Rasberry Pi Camera, you will need to ensure the camera module is enabled. To do this click on the Raspberry Pi Icon which can be found in the top left corner. Then in the menu select Preferences -> Raspberry Pi Configuration. Within the Raspberry Pi Configuration Display, go to the Interfaces tab and ensure that the Camera is enabled. Also ensure that the Serial Port is enabled and the Serial Console is disabled.

Image Not Found
Navigating to the Configuration Settings
Image Not Found
The Desired Configuration Settings

To test your camera is working open up a terminal (CTRL+ALT+T) and run the following command. This will run a Python script that should show you a live feed of the camera.

python3 test.py

If this doesn't work try running the raspberry config with admin privileges by running the following command in a terminal.

 sudo raspi-config 

If the test script works you should see a window similar to the one in the figure below.

Image Not Found
Live Stream Script Demonstration

Connecting the Raspberry Pi to the QUT WiFi

To connect your Raspberry Pi to the QUT Wifi click on the network interfaces icon, located on the top right of the screen, and select the QUT Wifi network. A network box should appear on the screen where you can setup the QUT Wifi connection. You will need to change the protocol to PEAP, and click no certificate required. Finally, type in your QUT username and password and click connect.


Interfacing with the Raspberry Pi via a Windows Computer

A typical way to communicate with a Linux system via an external computer is via SSH. However, SSH is not straightforward to use on a windows computer. MobaXterm is a software package which can run SSH in a windows OS envrironment (and do many other things).

  • Ensure the external computer is on the same network as the raspberry pi*
  • Open MobaXterm
  • Click the new session button up the top left
  • Click SSH in the top left of your popup window
  • Obtain your ip address of your pi (type ifconfig in a terminal on your pi, should be under WLAN0 if using wifi)
  • Enter your pi's ip address in the mobaxterm prompt window
  • Click "specify username" and type pi as the username
  • Press enter and enter the password (default is raspberry)

*note if you are on QUT WiFi you may need to run the QUT VPN service (Cisco anyconnect client) and connect to sas.qut.edu.au

Image Not Found
Creating a new session
Image Not Found
adding ip and username

Updating necessary software for Motor Hat

To make use of the motor control hardware, several software changes are required.

  1. Login to the Raspberry Pi using your preferred method and verify that it has an internet connection.
  2. Open a new terminal window or ssh connection.
  3. Run the command sudo apt update followed by sudo apt upgrade. This will update installed software packages to the latest available version.
  4. Run command python3 -m pip install psutil. This installs a Python package that is used to get the MAC address of the Raspberry Pi's network interfaces.
  5. Check PySerial version using python3 -m pip show pyserial. If the version is not greater than 3.3, upgrade PySerial using python3 -m pip install pyserial.

Reducing the Number of Touch Screen Pins

There are two methods of reducing the number of pins required by the touch screen.

Method 1 - simply connect the screen to the Raspberry Pi using the HDMI and Micro USB. This will provide the screen with power and display, however the touch interface will not work. The touch interface requires the screen to communicate with the Raspberry Pi via SPI. Feel free to use a wireless/bluetooth keyboard instead of connecting the SPI.

Method 2 - the provided 5 inch touch screen comes with a 26-pin female connector. However, it does not actually require all 26 pins to operate correctly; in fact it only needs 9 pins in total. The touch screen requires power, ground, and the SPI serial communication pins. So if you require access to more GPIO pins, or want flexibility with the placement and orientation of the touch screen and Raspberry Pi, you can do so. The following figures and table display the required pin connections for the touch screen, and indicate the positioning of these pins on the Raspberry Pi. The BOARD numbering convention has been used, but you can convert to BCM if you wish using the provided Raspberry Pi pinout.

Image Not Found Image Not Found
Touch Screen and Pi Pin Number Pi Pin Description
2 5V
4 5V
6 Ground
19 SPI - MOSI
21 SPI - MISO
22 GPIO
23 SPI - Clock
25 Ground
26 SPI - CE1 (Chip Select)
The pinout for the Raspberry Pi, Touch Screen and the Required Connections. GPIO pinout image sourced from Element14