59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
import time
|
|
import sys
|
|
|
|
try:
|
|
from w1thermsensor import W1ThermSensor
|
|
except ImportError:
|
|
print("Error: w1thermsensor module not found.")
|
|
print("Please install it using: pip install w1thermsensor")
|
|
sys.exit(1)
|
|
|
|
def main():
|
|
print("--- 1-Wire Temperature Sensor Verifier ---")
|
|
print("Checking for connected sensors...")
|
|
|
|
try:
|
|
sensors = W1ThermSensor.get_available_sensors()
|
|
except Exception as e:
|
|
print(f"Error accessing 1-Wire bus: {e}")
|
|
print("Ensure 1-Wire is enabled in raspi-config or /boot/config.txt")
|
|
return
|
|
|
|
if not sensors:
|
|
print("No sensors found!")
|
|
print("Check your wiring:")
|
|
print(" 1. VCC (Red) -> Pin 1 (3.3V)")
|
|
print(" 2. GND (Black) -> Pin 6 (GND)")
|
|
print(" 3. DATA (Yellow) -> Pin 7 (GPIO 4)")
|
|
print(" * Remember the 4.7k resistor between VCC and DATA")
|
|
return
|
|
|
|
print(f"Found {len(sensors)} sensor(s):")
|
|
for i, sensor in enumerate(sensors):
|
|
try:
|
|
print(f" {i+1}: ID={sensor.id} (Type={getattr(sensor, 'type_name', 'Unknown')})")
|
|
except Exception as e:
|
|
print(f" {i+1}: Error reading sensor details: {e}")
|
|
print(f" Debug info: {dir(sensor)}")
|
|
|
|
print("\nReading temperatures (Press Ctrl+C to stop)...")
|
|
try:
|
|
while True:
|
|
output = []
|
|
for sensor in sensors:
|
|
try:
|
|
temp = sensor.get_temperature()
|
|
output.append(f"[{sensor.id}]: {temp:.1f}°C")
|
|
except Exception as e:
|
|
output.append(f"[{sensor.id}]: Error")
|
|
|
|
# Print on same line to act like a dashboard
|
|
print(" | ".join(output), end="\r")
|
|
sys.stdout.flush()
|
|
time.sleep(1)
|
|
except KeyboardInterrupt:
|
|
print("\nStopped.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|