Network attached counter using Pi5, python, pyqt6, and sqlite
- clone repository:
git clone https://github.com/rassweiler/pi-networked-counter.git && cd pi-networked-counter
- Setup python environment:
python3 -m venv venv
source venv/bin/activate
pip3 install gpiozero lgpio msal msal_extensions python-dotenv pygobject
- Install optional packages:
sudo apt install qtcreator sqlitebrowser
- 1 Raspberry Pi 5+
- 1 Raspberry Pi 5+ Power Supply
- 1 Micro SSD
- 1 Raspberry Pi 7" screen
- 1 Pi5 Diplay adapter cable
- 2 Harting Cables
- 2 M12 AMP Connector Male
- 2 M12 AMP Connector Female
- 1 Pack of jumper pin connectors
- 1 Roll of PETG filament
- 2 IR Emitter/ Receiver 5mm 3.3v
- 1 Ethernet Keystone Inline
- 1 Ethernet Patch Cable
- 1 USB C Keystone Jack Adapter USB 3.1
- 1 USB C patch cable
- 1 USB A Keystone Jack Cable
- 1 22awg Wire 2 Conductor 25ft
- 1 Rugged Metal Pushbutton - 16mm White Momentary
- 2 Wire Connector Pack
- 1 GPIO Ribbon Cable
- 1 GPIO Header
- 1 DC Power Panel Jack
- 1 DC Power Supply
- 1 Through-Hole Resistors - 1K ohm 5% 1/4W
- 1 Through-Hole Resistors - 220 ohm 5% 1/4W
- 1 AQY210EH SSR
- 1 Tower Light - Red Yellow Green Alert Light
- 1 Tiny Premium Breadboard
- Update system
sudo apt update && sudo apt upgrade
- Install packages
sudo apt install < .packages
- Disable sudo NOPASSWD:
sudo nano /etc/sudoers.d/010_pi-nopasswd
remove NOPASSWD:
- Enable sudo logging:
sudo visudo
Insert:
Defaults logfile=/var/log/sudo
- Harden ssh config:
sudo nano /etc/ssh/sshd_config
PermitRootLogin prohibit-password
MaxAuthTries 5
MaxSessions 3
MaxStartups 3:90:15
PasswordAuthentication no
- Harden ssh keys:
echo -e "# Restrict key exchange, cipher, and MAC algorithms, as per sshaudit.com\n# hardening guide.\n KexAlgorithms sntrup761x25519-sha512,sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,gss-curve25519-sha256-,diffie-hellman-group16-sha512,gss-group16-sha512-,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256\n\nCiphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-gcm@openssh.com,aes128-ctr\n\nMACs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128-etm@openssh.com\n\nHostKeyAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256\n\nRequiredRSASize 3072\n\nCASignatureAlgorithms sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256\n\nGSSAPIKexAlgorithms gss-curve25519-sha256-,gss-group16-sha512-\n\nHostbasedAcceptedAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-256\n\nPubkeyAcceptedAlgorithms sk-ssh-ed25519-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-256\n\n" > /etc/ssh/sshd_config.d/ssh-audit_hardening.conf
- Remove avahi:
sudo systemctl stop avahi-daemon && sudo systemctl disable avahi-daemon
sudo apt purge avahi-daemon -y
- Remove CUPS:
sudo systemctl stop cups && sudo systemctl disable cups
sudo apt purge cups -y
-
PI configure Set the locale to UTF-8
-
Setup keyring for sharepoint integration Run seahorse and make sure there is a default keystore
-
clone repository to PI:
git clone https://github.com/rassweiler/pi-networked-counter.git && cd pi-networked-counter
- Copy the desktop file to autostart the app:
sudo cp objectcounter.desktop /etc/xdg/autostart/objectcounter.desktop
- Add panel icon
cp objectcounter.desktop ~/.local/share/applications/
Then restart the system to get the app in the menu under other, then right click the app and select add to taskbar
- Setup startup IO for push button
echo "dtoverlay=gpio-poweroff,gpiopin=25,active_low" >> /boot/firmware/config.txt
- Add to the
.settup.tomlfile your sharepoint access details:
[sharepoint]
authority = "https://login.microsoftonline.com/{AID}"
client = "{CID}"
scopes = 'User.ReadBasic.All Files.ReadWrite Sites.ReadWrite.All'
endpoint = "https://graph.microsoft.com/v1.0/me"
- run the
get_token.shscript once to initialise your sharepoint token, it should provide a link and a key to login using a browser.
- Print out the Front case section (Should contain the screen brackets as well)
- Print out the Rear case section
- Print out the Sensor case sections
- Print any required brackets/stands
- Connect both power wires together from the IR emitter and receiver
- Connect both ground wires together from the IR emitter and receiver
- Solder the M12 AMP Connector Male to the sensors following the pinout below
- Pin 1 (Brown): 3.3V
- Pin 2 (White): Unused
- Pin 3 (Blue): Emitter signal (Yellow)
- Pin 4 (Black): Ground
- Pin 5 (Gray): Unused

- Cable Brown: 12V
- Cable Green: Green LED
- Cable Yellow: Yellow LED
- Cable Red: Red LED
- Pin 1 (3.3V): To infeed sensor pin 1
- Pin 2 (5V): To Display pin 5 (5V)
- Pin 6 (GND): To Display pin 1 (GND)
- Pin 9 (GND): To infeed sensor pin 4
- Pin 11: To infeed sensor pin 3
- Pin 13: To stack light green wire
- Pin 14 (GND): To outfeed sensor pin 4
- Pin 15: To stack light yellow wire
- Pin 16: To outfeed sensor pin 3
- Pin 17: (3.3V): To outfeed sensor pin 1
- Pin 18: To stack light red wire
- Pin 22: To power led +
- Pin 25 (GND): To dev board for ground
- Pin 30 (GND): To power led -
The Pi5 board is not entirely accurate, the J2 and J8 pins are proper however.







