-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgpiotest.py
More file actions
37 lines (29 loc) · 1.59 KB
/
gpiotest.py
File metadata and controls
37 lines (29 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
""" Hardware Verification (The "Gold Standard" Proof)
This method provides undeniable physical proof of synchronization. It requires a small amount of wiring.
Concept: Trigger an event on all Pis at the exact same physical moment and have each Pi record its own system time when the event occurs. If the clocks are synchronized, the recorded timestamps will be nearly identical.
Implementation:
Wiring: Get a simple push-button. Wire one side to a ground (GND) pin on each Pi. Wire the other side to a specific GPIO pin (e.g., GPIO 17) on every single Pi in your array. You are creating a shared trigger bus.
Script: On each Pi (central and camera), save the following Python script (e.g., ~/gpiotest.py):
"""
import RPi.GPIO as GPIO
import time
from datetime import datetime
GPIO_PIN = 17 # The GPIO pin you wired the button to
# Use BCM pin numbering
GPIO.setmode(GPIO.BCM)
# Setup the pin as input with a pull-up resistor.
# The pin will be HIGH by default and go LOW when the button is pressed (connected to GND).
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
print("Waiting for hardware trigger... Press the button.")
try:
# Wait indefinitely for a falling edge (button press)
GPIO.wait_for_edge(GPIO_PIN, GPIO.FALLING)
# --- As soon as the edge is detected, record the time ---
event_time_ns = time.time_ns()
event_time_utc = datetime.utcnow().isoformat()
print(f"Trigger detected at {event_time_utc} ({event_time_ns} ns)")
# Save the result to a file
with open("trigger_time.txt", "w") as f:
f.write(str(event_time_ns))
finally:
GPIO.cleanup()