Raspberry Pi AI Part II: Some Software Configuration Required

This week, let’s tackle the initial software configurations on our Raspberry Pi. Last time, you should have assembled your Pi with the AI hat and the camera module. This week, there’s some extra configurations we need to apply. Let’s get started.

Boot ‘Er Up

Plug your Pi into power, connect USB peripherals, and connect to a monitor; we’ve got some setup to do!

Once I get booted into the OS and see the desktop, I like to open up terminal and update/upgrade my packages. You can run this command to do such:

sudo apt update && sudo apt upgrade

This will get all of your packages up to date, which is best practice.

*Snap* Screenshot setup

I need a nice way to take screenshots. How else are you going to believe me if I don’t show proof?! I’m installing Flameshot utility into the OS, that way I have something similar to Window’s Snipping Tool.

sudo apt update
sudo apt install flameshot

Then do a quick reboot.

Smile for the Camera

You’ll need to get the Pi to recognize the camera. This is pretty simple and well documented.

Open up terminal again to modify the config.txt file. We’ll make a few minor adjustments so that the Pi and camera talk to each other.

sudo nano /boot/firmware/config.txt

Now look for the “camera_auto_detect” line in the config file and change the “1” to a “0”.

Next, scroll to the bottom and find “[all]” section. Add the following line in:

dtoverlay=imx708,cam0

Finally, reboot the Pi.

Once you’re up and running, open up another terminal, point the camera directly at yourself and run the following command:

rpicam-still -t 0

You should now be starring directly at you and your double chin! How neat is that?!

In all seriousness, you should now have a live feed of the camera’s input.

Coding Prep

Next, we’re going to install Python and Flask.

Most Raspberry Pis come with Python installed, but I want to install the latest production version on this guy.

sudo apt install python3-pip git

Now, let’s install Flask – a Python library for making web apps.

sudo apt install python3-flask

If you’re lucky, both Python and Flask are already installed thanks to Raspberry Pi OS, but it never hurts to double check.

These Things Are “Nice to Haves”

SMB Share

I got tired of using a USB drive to transfer files between my Pi and primary workstation where I’m writing this, so I installed Samba on the Pi and made a network shared folder.

sudo apt install samba

Then create the folder you want in the place you want. I just, again, made it in /Home/Admin.

Now you need to make a password for your SMB share

sudo smbpasswd -a $USER

Then you need to open up your smb.conf file, scroll down to the bottom and add the following:

sudo nano /etc/samba/smb.conf

[sambashare]
   comment = My Shared Folder
   path = /home/admin/Share
   read only = no
   browsable = yes
   valid users = admin

Now on your Windows machine, you can simply use file explorer to dig into the file system of your Raspberry Pi

Static IP

Since we are SMBing to our Pi, now would be a great time to setup a static IP address. On our version of Raspberry Pi OS we can access network settings from Terminal by entering in the following command:

sudo nmtui

Go to “Edit a connection”, scroll down to “IPV4 CONFIGURATION”, change “<Automatic>” to “<Manual>”, then click “<Show>”. From here, punch in your network information. You’ll need your desired IPv4 address, your Gateway address, and your DNS server.

What Can Go Wrong Will Go Wrong && Lessons Learned

Here’s my lessons learned:

I had a bunch of brushing up to do with Linux. I haven’t used it in years and my BASH is a little rusty. It took me an embarassingly long amount of time to get Flameshot working. All I needed was a reboot after installing the module. Who knew?!

I didn’t think about camera quality and the lack of focus ability. While playing around with the camera and a couple of cards, I noticed the poor capture quality of up close images. I’m starting to think that maybe the scope of this project will change.

I needed a way to transfer my screenshots from from the Pi to my main PC. I found an old USB drive that had a prior Pi project on it. I was in no need of these, so I installed GParted on my Pi and reformatted the drive. GParted is a GUI based disk manager, much like Windows has. It made it super easy! I was also able to reformat that SD card that I had trouble with from the last blog!