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)
6
  • Why would anyone bother to use a script to halt when there is already a kernel function to do this? – Milliways Aug 19 '20 at 11:48
  • The first script will define 2 functions then exit i.e. do NOTHING – Milliways Aug 19 '20 at 12:07
  • @Milliways as mentioned in the question I have a button which calls the functions when pressed. – Baxorr Aug 20 '20 at 10:45
  • Also there is a kernel function to do this? How so? – Baxorr Aug 20 '20 at 10:46
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.