CommentStreams:Fdd5ada5c04e809af32d26cb374097b0

< T201
Revision as of 18:39, 20 December 2023 by 69.62.198.249 (talk) (Migrated comment #4200)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

  1. !/usr/bin/env python3

import Jetson.GPIO as GPIO import time import os import subprocess

  1. Use board pin numbering

GPIO.setmode(GPIO.BOARD)

  1. Pin to monitor for power loss

POWER_LOSS_PIN = 7

  1. 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()