循环中调用的GPIO引脚未遵循其分配的配置。
我已经运行了没有循环的脚本,它似乎可以正常工作。我相信这个问题是圈内的。我猜每个循环后可能需要GPIO.cleanup吗?
import RPi.GPIO as GPIO
import time
import board
import busio
import digitalio
import adafruit_max31855
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)
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)
# 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()
print("Now Heating...")
else:
cooling()
print("Now Cooling...")
finally:
GPIO.cleanup()
我正试图让MAX31855热电偶读取温度。我定义了GPIO引脚,并定义了名为加热和冷却的功能。使用while循环,热电偶读取温度。用户输入阈值。当温度读数超过该阈值时,程序将切换为冷却。 运行脚本时,循环会根据温度变化打印“ Now Heating ...”和“ Now Cooling ...”,但GPIO引脚似乎未遵循其分配的真/假配置。测量引脚上的电压时,其输出为零。目的是向Peltier模块供电,并根据用户输入温度创建温度保持效果。