0

I have two completely seperate python scripts involving the GPIO that runs on startup. The issue i'm having is that when I call the turn fan on or off it sometimes triggers the halt script I have and turns off the pi. I've tried disabling my halt script and that eliminates the issue. I'm completely lost here as to why it happens, i'd love to hear some input! :D

The function I use in my django website to trigger the relay

import RPi.GPIO as GPIO
channel = 21
GPIO.setmode(GPIO.BCM) 
GPIO.setup(channel, GPIO.OUT)

def TurnFanOff():
    GPIO.output(channel, GPIO.LOW)

def TurnFanOn():
    GPIO.output(channel, GPIO.HIGH)

My halt script triggered by a physical button

import RPi.GPIO as GPIO  
import time  
import os

GPIO.setmode(GPIO.BCM)  
GPIO.setup(3, GPIO.IN, pull_up_down = GPIO.PUD_UP)

def Action(channel):
        os.system("shutdown now -h")
        GPIO.cleanup()

GPIO.add_event_detect(3, GPIO.FALLING, callback = Action, bouncetime = 500)  
 
while 1:  
   time.sleep(1)
Baxorr
  • 101

1 Answers1

4

All I can think of is the fan causes a power spike which temporarily drains power causing a voltage drop.

I suppose you could sort of test that by using the script without the fan connected.

joan
  • 67,803
  • 5
  • 67
  • 102