-
CommentStreams:Fdd5ada5c04e809af32d26cb374097b0
Jump to navigation
Jump to search
This is a working python script for soft shutdown sensing Pin 7 for power disconnect using Jetson GPIO. Power both the Jetson DC port and the T201 hat DC port with the same DC source and it will power on when power is connected.
- !/usr/bin/env python3
import Jetson.GPIO as GPIO import time import os import subprocess
- Use board pin numbering
GPIO.setmode(GPIO.BOARD)
- Pin to monitor for power loss
POWER_LOSS_PIN = 7
- Set up the GPIO pin as input
GPIO.setup(POWER_LOSS_PIN, GPIO.IN)
def check_power_loss():
return GPIO.input(POWER_LOSS_PIN)
def shutdown_system():
print("Power loss detected. Initiating shutdown...")
subprocess.call(['sudo', 'shutdown', '-P', 'now'])
try:
while True:
if check_power_loss():
shutdown_system()
break
else:
print("Power is connected. System running normally.")
time.sleep(5) # Check every 5 seconds
except KeyboardInterrupt:
print("Exiting program")
finally:
GPIO.cleanup()