Ultrasonic distance counter using two US-100 sensors displayed on a 32x64 RGB LED matrix. Runs on a Raspberry Pi with an Adafruit RGB Matrix HAT.
- Raspberry Pi (with Adafruit RGB Matrix HAT)
- 2x US-100 ultrasonic sensors (connected via USB serial:
/dev/ttyUSB0,/dev/ttyUSB1) - 32x64 RGB LED matrix panel
Make sure the virtualenv at ~/loadcounter/env has the dependencies installed:
pip install adafruit-circuitpython-us100 pyserial rgbmatrix
./setup-service.sh
This installs a systemd service that starts on boot and auto-restarts on crash.
Edit the Python files locally, then push to the Pi and restart:
./deploy.sh
./logs.sh # live tail (Ctrl+C to stop)
./logs.sh last # last 100 lines
./logs.sh last 500 # last N lines
./logs.sh prev # logs from previous boot
./logs.sh today # today's logs
./logs.sh status # service status
Count events are appended as JSON Lines on the Pi:
/var/lib/loadcounter/events.jsonl
Logged event names are counter_triggered, manual_number_changed, and
counter_reset.
The iPhone app's History screen reads this same file through a paginated BLE characteristic. It does not create or maintain a second event log on the Pi. When no Pi is connected, the same screen can generate deterministic sample data on the iPhone to test its charts, filters, statistics, and PDF reports offline.
Run the remote keyboard controller from this repo:
./loadcounter-remote.py
It opens one SSH connection to jul@raspberry.local and sends the same commands
the Bluetooth keyboard listener writes on the Pi. Use the arrow keys, Return,
Escape, Space, digits, ., Backspace, r, y, and n. Press q or Ctrl+C to
quit the Mac controller.
For one-shot commands:
./loadcounter-remote.py --send esc no enter
Open the SwiftUI app project in Xcode:
ios/LoadCounterRemote/LoadCounterRemote.xcodeproj
Run it on the iPhone, then tap Connect. The Pi advertises as LoadCounter
through the loadcounter-ble.service systemd service.
ssh jul@192.168.1.218
cd ~/loadcounter
./env/bin/python test-ultrasonic.sensors.py
python3 -m unittest discover -s tests -v
| File | Description |
|---|---|
load-counter.py |
Main script — reads sensors, displays on matrix |
loadcounter-remote.py |
Mac-side CLI keyboard controller over SSH |
loadcounter-ble.py |
Pi-side Bluetooth Low Energy command bridge |
test-ultrasonic.sensors.py |
Sensor test script (distance + temperature) |
fonts/ |
BDF bitmap fonts for the matrix display |
loadcounter.service |
systemd unit file |
setup-service.sh |
One-time service installation (run from Mac) |
deploy.sh |
Push code to Pi and restart (run from Mac) |
logs.sh |
View service logs (run from Mac) |