简体   繁体   中英

GPIO pins not turning on in While loop

I am trying to control the GPIO pins on the pi within a while loop that connect to a motor controller which activates some peltier devices. The code is running, but the GPIO connections are not actually triggering the motor controllers. Nothing happens and I have a multimeter which shows that the motor controller is not switching the peltier devices on.

We moved the print command into the function so that we could see if the function is actually being called. Everything seems to be working fine except the GPIO connections are not triggering the hardware.

import RPi.GPIO as GPIO
import time
import board
import busio
import digitalio
import adafruit_max31855
from sys import exit

GPIO.setmode(GPIO.BCM)
GPIO.setup(0, GPIO.OUT)
GPIO.setup(2, GPIO.OUT)
GPIO.setup(3, GPIO.OUT)
GPIO.setup(4, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.setup(25, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)

def heating():
    GPIO.output(0, False)
    GPIO.output(2, True)
    GPIO.output(3, False)
    GPIO.output(4, True)
    GPIO.output(22, False)
    GPIO.output(23, True)
    GPIO.output(24, False)
    GPIO.output(25, True)
    GPIO.output(27, True)
    print("Now Heating...")

def cooling():
    GPIO.output(0, True)
    GPIO.output(2, False)
    GPIO.output(3, True)
    GPIO.output(4, False)
    GPIO.output(22, True)
    GPIO.output(23, False)
    GPIO.output(24, True)
    GPIO.output(25, False)
    GPIO.output(27, False)
    print("Now Cooling...")

# User Input
desired_temp = int(input("Enter your desired temperature: "))

spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.D5)

max31855=adafruit_max31855.MAX31855(spi, cs)

try:
    while True:
        tempC = max31855.temperature
        tempF = tempC * 9 / 5 + 32
        print('Temperature: {} C {} F '.format(tempC, tempF))
        time.sleep(0.05)
        if tempF <= desired_temp:
            heating()
        else:
            cooling()
finally:
    GPIO.cleanup()
    exit()

try doing it pieces by pieces. get one for heating and one for cooling. try using a LED too to determine if its giving signal to the motor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM