Machine Learning on a Raspberry Pi: The Complete Guide to Setting Up Your Raspberry Pi 3 2023 (Mac)

Wiktoria Kasprzak
5 min readJun 5, 2023

--

Fully connected Raspberry Pi

Introduction

Welcome to the first part of this series on machine learning on a Raspberry Pi, where you will be guided through the process of setting up your Raspberry Pi 3 and configuring it for various tasks. This instalment will cover the initial setup of the Raspberry Pi, as well as setting up a USB camera for future projects.

What is Raspberry Pi?

Raspberry Pi is a small, affordable computer that can be used for a wide range of projects. It’s especially popular due to its capabilities and flexibility.

Specs

  • MacBook Pro 2020 - macOS Ventura 13.2.1
  • Raspberry Pi 3 b+ and power source
  • Razer Kito Pro camera
  • Cat 6 ethernet cable
  • Micro SD 32 GB and SD adapter
  • Ethernet to USB C adapter

Useful commands

In the terminal, two useful commands are ls (list) and cd (change directory). These commands allow you to navigate and explore the file system on the Raspberry Pi.

Steps

1. Format SD Card

Begin by formatting your SD card to the FAT32 file system. This can usually be done using the Disk Utility application on your Mac. Once the formatting is complete, download the Raspbian OS and write it to the SD card using an imaging tool such as Raspberry Pi Imager. For this project, the recommended version of the OS was downloaded.

2. Install GUI Software (optional)

Install VNC Viewer on your MacBook. VNC Viewer will allow you to connect to the Raspberry Pi remotely and access its graphical user interface (GUI).

3. Booting the Raspberry Pi

Insert the SD card into the Raspberry Pi and connect the power cable. The Pi will start booting up, and you should see the LED indicators light up. Be patient as the booting process may take a few moments.

4. Connect to Laptop via Ethernet

To establish a connection between your Raspberry Pi and your MacBook, connect an Ethernet cable between the two devices. On your MacBook, navigate to System Preferences and select Network. Ensure that the Ethernet connection is active and configured properly by looking for “USB 10/100 LAN”.

5. Change Password

By default, the Raspberry Pi's username is "pi" and the password is "raspberry." It is essential to change this password to enhance the security of your device. To change the password, open the terminal on your MacBook and enter the following command:

ssh pi@192.168.0.1

Replace “192.168.0.1” with the IP address assigned to your Raspberry Pi. This can be found by running the command:

ping raspberrypi

6. Create SSH File

To enable SSH access to your Raspberry Pi, create an empty file named “ssh” in the boot partition of the SD card. This file will notify the Pi to enable SSH upon booting up.

7. Create a Config File

Open a text editor on your MacBook Pro and create a new file named “config”. In this file, enter the following line:

username:password

Replace “username” with your desired username and “password” with the encrypted password of your choice. Save the file.

8. Connect to the Pi via SSH

Open the terminal on your MacBook Pro and enter the following command:

sudo ssh -l username 192.168.0.1

Replace “username” with your chosen username and “192.168.0.1” with the IP address of your Raspberry Pi. You will be prompted to enter the password you set in the previous step. Once authenticated, you will be logged into the Raspberry Pi via SSH. You can confirm this has worked as the terminal prompt will display username@raspberrypi.

9. Connect to VNC Viewer (optional):

To access the Raspberry Pi’s GUI, you need to change the boot settings in the config file. Open the terminal on your MacBook Pro and enter the following command to open the config tool:

sudo raspi-config
Raspberry Pi configuration menu

Next, select “System Options” and choose “Boot/Autologin”. Now, you have two options: “Desktop” or “Desktop Autologin”. Select your preferred option. This will enable the GUI to start automatically upon boot. Press Tab to select “Finish” and press Enter to exit the configuration tool.

Alternatively, you can use VNC Viewer to access the Raspberry Pi’s GUI. Follow these steps:

  1. Launch VNC Viewer.
  2. Enter the IP address of your Raspberry Pi in the connection field.
  3. Click “Connect” to establish the VNC connection.

To find the IP address of your Raspberry Pi, you can use the ifconfig command. Look for the IP address corresponding to your connection, such as wlan0 for a Wi-Fi connection. Make sure to select the IP address that corresponds to your connection when entering it in VNC Viewer.

SSH (Secure Shell) and VNC Viewer (Virtual Network Computing Viewer) serve important purposes in setting up and managing a Raspberry Pi. SSH provides secure remote access to the Pi’s command-line interface, allowing convenient configuration and control from a separate device. It ensures encrypted communication over unsecured networks, enhancing security. On the other hand, VNC Viewer enables remote graphical access to the Pi’s desktop environment, facilitating interaction with the GUI from a remote location. This is especially useful for projects requiring visual elements or when a physical display is not connected. Together, SSH and VNC Viewer offer flexibility, convenience, and security in managing and utilising Raspberry Pi setups.

Setting up USB camera

  1. Connect the USB camera to one of the available USB ports on your Raspberry Pi.
  2. Open the terminal on your Raspberry Pi or SSH into it from your MacBook Pro.
  3. Enter the following command to update the package lists on your Raspberry Pi: sudo apt-get update
  4. Once the update process is complete, install Fswebcam by running the following command: sudo apt-get install fswebcam
  5. To verify that the camera is functioning correctly, enter the following command to capture an image: fswebcam image.jpg Note that this saves the image to the current directory.
  6. Once the capture process is complete, you can check if the image was successfully saved by running the command ls to list the files in the current directory

Troubleshooting

  • If you encounter the issue where your Pi displays the message “Wi-Fi is blocked by rfkill,” check that your ethernet cable is properly connected on either end.
  • If you are struggling to connect to wifi, ensure you have enabled the correct settings under w-lan in the Rapsberry Pi config

Conclusion

You have successfully set up your Raspberry Pi 3 on your Mac! The next part of the series will explore running a TensorFlow Lite project on your Raspberry Pi setup, delving into the fascinating world of machine learning.

--

--