INSTALLING PYTHON LIBRARY ON RASPBIAN BOOKWORM OS

On Raspbian Bookworm OS the pip install commands can not be executed right away from the current user prompt. We need to run virtual environment first (venv) on our raspberry pi os, download the pip package and install it there, login as root user and then install it again globally so pi user also can access it.

But first we need to prepare the OS. Run Raspbian OS imager, select Raspberry PI OS (64 bit) Debian Bookworm version as seen on picture below.

Because we are going to access our raspbian os via ssh, we need to setup the pi user as well as the WIFI credentials. Click EDIT SETTINGS then YES button.

blah

Just let the default hostname as what ever it is. So with the pi username. You just need to change the password to something easy to be remember like Password123** in my case. You can choose your own. For WIFI credential i am going to let my raspberry pi to connect to my local WIFI hotspot name as WIFI with the same password Password123**. Click Save.

Another dialog window will appear asking for your confirmation. Just click YES button.

It may takes minutes to complete the process depending the speed of your computer.

Once the process is completed another dialog window will appear to advice you to remove the sd card from the reader.

Login to your raspberry pi via ssh. On pi@raspberrrypi prompt, type : pip install pyodbc followed by ENTER. pyodbc is our first library we try to install in this scenario.

The system returns error message saying error:externally-managed-environment. The rest of the message is description in detail to get the installation right. On raspbian BookWorm version, unlike the apt install command the pip install command must be called on virtual environment. To run the virtual environment you need to type python -m venv /home/pi/venv followed by ENTER. After that type /home/pi/venv/bin/pip install pyodbc followed by ENTER.

After the pyodbc library is installed on virtual environment, we need to install it to our root as well so our pi user can access it. On pi@raspberrypi prompt type apt search pyodbc followed by ENTER. It finds out the pyodbc package has been saved as python3-pyodbc.

Back on pi@raspberrypi prompt type sudo su to switch to root user. On root@raspberrypi:/home/pi# prompt type apt install python3-pyodbc followed by ENTER.

The prompt may ask your confirmation to continue or not, just type Y followed by ENTER.

Type exit on the prompt to go back to pi@raspberrypi prompt.

In order to test if our pi user now has access to pyodbc library or not, we need to run the python command to import that library. On pi@raspberrypi prompt type python followed by ENTER.

Once the python >>> prompt appears, type import pyodbc followed by ENTER. If there is no error happens that means our pi user now has access to pyodbc library.

Now you can follow the same steps above to install other pip libraries. To exit python prompt, just type exit() followed by ENTER. You will get back to pi@raspberrypi prompt.

INSTALLING USB GPS

#Install Updates
sudo apt-get update
sudo apt-get upgrade

#see USB devices
lsusb

#Install GPS software
sudo apt -y install gpsd gpsd-clients python-gps 

#Edit GPS config file
sudo nano /etc/default/gpsd

#Add this to file
START_DAEMON=”true”

USBAUTO=”true”

DEVICES=”/dev/ttyACM0″

GPSD_OPTIONS=”-n”

#Install chrony
sudo apt-get install chrony

#reboot pi

#check to see if services are running
systemctl is-active gpsd
systemctl is-active chronyd

#Check GPS output
cgps – s
gpsmon -n

#Edit chrony config file
sudo nano /etc/chrony/chrony.conf

#Add this to end of file
refclock SHM 0 offset 0.5 delay 0.2 refid NMEA

#Check Chrony Output
sudo chronyc sources -v

# Check chrony output
sudo chronyc tracking

#Force time sync
sudo chronyc makestep

INSTALLING RASPBIAN OS ON YOUR RASPBERRY PI 4

First thing first, you need to insert your sd card into your computer sd card reader slot. After that download Raspberry Pi Imager from Raspberry Pi website by clicking here. By default the website can detect what OS that is running on your computer and give you default highlighted download button. Because my computer is running on window, so the windows version is the one that is highlighted.

Once the installer downloaded (on my computer it went to download folder), double click to run it. On the pop up window you will see three clickable buttons in series. At the time this article is written, the latest Raspbian OS installer version is 1.7.5.

Click CHOOSE OS button. A drop down list will appear to give you a list of Raspberry PI OS you wish to install. It seems Debian Bookworm is the latest version at the time being.

I am going to choose Debian Bookworm with out Desktop because i just want to run the light version without desktop GUI access. So, i scrolled a little bit down and select Raspberry Pi OS (other).

On the next option list, select Raspberry Pi OS Lite (64-bit).

Click CHOOSE STORAGE button. On storage selection list, select Raspberry Pi OS Lite(64-bit)

We need to setup internet access so our Raspberry Pi is able to download all necessary packages from the internet. Click the cork at the bottom right of the window.

Tick Set hostname. Type raspberrypi on text box. We are going to see this raspberry pi named as raspberrypi.local on our local network.

We are going to access this raspberry pi via SSH. Tick on Enable SSH. Select Use password authentication. Then tick on Set username and password. For this exercise i going to use pi as username and pi123** for the password.

This step i want to connect my raspberry pi to my wifi network. So tick on Configure wireless LAN checkbox. Provide your home wifi ssid and the password. For Wireless LAN country drop down options, i choose AU because i am living in Australia.

blah

blah

blah

blah