Reinstalls of RPi's

Updated October 2025

Reinstalls of RPi's
Pi Zero W

I run multiple RPi's, a 3B and a ZeroW. They are both quite old now and haven't been upgraded to the latest OS. I've had the 3B since mid 2017 and I haven't installed a new Raspbian since I got it...

I've blown the dust off the Pi Zero W and reinstalled the latest version of debian using the Imager https://www.raspberrypi.com/software/
This was so simple and much easier than years before with the old Rasbian OS.
I installed the OS Lite as ill be running headless.

I have a few things connected to the GPIO:
- SainSmart 2-Channel 5V Relay Module (Newer versions are available now...)
- Bosch bme280 module (Digital Temperature/Humidity/Barometric Pressure)


Installation

After updating the distro with sudo apt update, apt full-upgrade.

- GaragePi - https://github.com/Responseless/GaragePi (Custom version of relay trigger for the sliding front gate)
- bme280 MQTT script (logs Temp/Humidity/Pressure to HA)
- bluepy Broodminder bluetooth MQTT script (logs Temp/Weights/Other to HA)

Prerequisites

Were using python3 so we usually would install pip3 and any other python modules your scripts use. On this version of debian on the PiZero W we dont use pip so we can install modules from apt or pip3, depending on the environment.

RPIZeroW >

sudo apt install i2c-tools
sudo apt install python3-smbus
sudo apt install python3-bme280
RPi3B >

sudo pip3 install smbus2
sudo pip3 install RPi.bme280

We're using the I2C so this can be enabled in raspi-config. Interface Options > I2C > enable.

sudo raspi-config

edit the boot config to include the line below:

sudo nano /boot/firmware/config.txt

dtoverlay=w1-gpio

-

sudo nano /etc/modules

w1-gpio
w1-therm

reboot the pi zero

sudo reboot now

Wait a minute for it to restart and connect with SSH again.

get_bme280.py - Pulls current values from the bme280 module temp,humidity, pressure.

#!/usr/bin/python3
import smbus2
import bme280

# bme280 settings
bme280_port = 1
bme280_address = 0x76
bme280_bus = smbus2.SMBus(bme280_port)

calibration_params = bme280.load_calibration_params(bme280_bus, bme280_address)

# the sample method will take a single reading and return a
# compensated_reading object
bme280_data = bme280.sample(bme280_bus, bme280_address, calibration_params)

# the compensated_reading class has the following attributes
print(bme280_data.id)
print(bme280_data.timestamp)
print(bme280_data.temperature)
print(bme280_data.pressure)
print(bme280_data.humidity)

# there is a handy string representation too
print(bme280_data)

create the file with these contents above. Output will show below.

chmod +x get_bme280.py

python3 get_bme280.py
user@pizeroW:~/bme280 $ python3 get_bme280.py
68a1955d-d268-42a4-9795-be981c2071a7
2024-05-09 11:47:50.917301+00:00
24.910461120144465
1013.6039477597245
39.39722134492959
compensated_reading(id=68a1955d-d268-42a4-9795-be981c2071a7, timestamp=2024-05-09 11:47:50.917301UTC, temp=24.910 °C, pressure=1013.60 hPa, humidity=39.40 % rH)

BM_Scan.py

This was a little trickier of an upgrade with the new debian version the bluepy library didnt exist as an apt package (python3-bluepy).

sudo apt install python3-pip
sudo pip3 install bluepy --break-system-packages

We then need to work around this by installing pip and forcing it in. This worked fine and everything installed correctly. There was a Deprecation error when installing with pip so I updated to pip3.

BM_Scan.py – Scans using bluetooth for Broodminder devices and decodes the data.

sudo python3 BM_Scan.py

If you get an error likle below you might need to release the a block on the bluetooth with rfkill. After the reboot the script was working as expected.

raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)
bluepy.btle.BTLEManagementError: Failed to execute management command 'scanend' (code: 11, error: Rejected)

sudo rfkill block bluetooth
sudo rfkill unblock bluetooth
sudo reboot now

The scripts are on my github with their equivalent MQTT versions.

GIT Links: https://github.com/Responseless/broodminder-diy/


Pi Zero W - SSH Lag Issue

The issue is Wifi power saving mode. This can be disabled by adding the file:

/etc/NetworkManager/conf.d/default-wifi-powersave-on.conf 

with contents:

[connection]
wifi.powersave = 2


Details here: https://gist.github.com/jcberthon/ea8cfe278998968ba7c5a95344bc8b55