液晶屏编号信号和插槽



我已经整理了一些代码(来自本网站的许多研究问题,谢谢)一些代码,这些代码将部分显示我的qt Creator GUI中的qlcdnumber小部件上的Raspberry Pi输入引脚电压。 代码运行完美,gui 弹出,引脚电压打印到端子(临时),按钮在 gui 中起作用,使其他引脚高低。 我没有收到任何错误,但问题是信号不会显示在 gui LCD 上。 我已经尽我所能地研究了没有成功,我觉得我现在好像在猜测它。 我将不胜感激任何意见和指导。 我已经学到了很多东西,但还有很长的路要走,所以任何帮助都会很棒。 我正在使用Raspbian和Qt4/Qt Creator 3.2.1

这是整个代码,再次感谢您的任何说明:

import sys
import RPi.GPIO as GPIO
import time
import re
from PyQt4 import QtGui, uic, QtCore
import spidev
GPIO.setmode(GPIO.BCM) 
GPIO.setwarnings(False)
o2zero = 26
o2span = 19
cozero = 13
cospan = 6
co2zero = 5
co2span = 21
status = "nil"
o2_channel = 0
o2_temp_channel = 1
spi = spidev.SpiDev()
spi.open(0,0)
class MyWindow(QtGui.QMainWindow): 
def __init__(self):
super(MyWindow, self).__init__()
uic.loadUi('mainwindow.ui', self)
self.o2_zero_up.clicked.connect(self.o2zeroup) 
self.o2_zero_down.clicked.connect(self.o2zerodown)
self.o2_span_up.clicked.connect(self.o2spanup)
self.o2_span_down.clicked.connect(self.o2spandown)
self.co_zero_up.clicked.connect(self.cozeroup)
self.co_zero_down.clicked.connect(self.cozerodown)
self.co_span_up.clicked.connect(self.cospanup)
self.co_span_down.clicked.connect(self.cospandown)
self.co2_zero_up.clicked.connect(self.co2zeroup)
self.co2_zero_down.clicked.connect( self.co2zerodown)
self.co2_span_up.clicked.connect(self.co2spanup)
self.co2_span_down.clicked.connect(self.co2spandown)  
self.close_button.clicked.connect(self.gpiocleanup)
self.thread = O2_Channel()
self.thread.o2_concentration.connect(self.onChangeValue)
self.thread.start()
self.show()
def onChangeValue(self, values):
o2_volts = values

def o2zeroup(self):  
GPIO.setup(o2zero, GPIO.OUT)   
GPIO.output(o2zero, 1) 
def o2zerodown(self): 
GPIO.setup(o2zero, GPIO.OUT) 
GPIO.output(o2zero, 0) 
def o2spanup(self):  
GPIO.setup(o2span, GPIO.OUT)  
GPIO.output(o2span, 1) 
def o2spandown(self): 
GPIO.setup(o2span, GPIO.OUT) 
GPIO.output(o2span, 0) 
def cozeroup(self):  
GPIO.setup(cozero, GPIO.OUT)  
GPIO.output(cozero, 1) 
def cozerodown(self):
GPIO.setup(cozero, GPIO.OUT)  
GPIO.output(cozero, 0) 
def cospanup(self):
GPIO.setup(cospan, GPIO.OUT)   
GPIO.output(cospan, 1) 
def cospandown(self): 
GPIO.setup(cospan, GPIO.OUT) 
GPIO.output(cospan, 0)
def co2zeroup(self):
GPIO.setup(co2zero, GPIO.OUT)   
GPIO.output(co2zero, 1) 
def co2zerodown(self): 
GPIO.setup(co2zero, GPIO.OUT) 
GPIO.output(co2zero, 0)
def co2spanup(self):
GPIO.setup(co2span, GPIO.OUT)   
GPIO.output(co2span, 1) 
def co2spandown(self): 
GPIO.setup(co2span, GPIO.OUT) 
GPIO.output(co2span, 0)   
def gpiocleanup(self): 
GPIO.cleanup() 
def closeEvent(self, event):
self.thread.stop()
self.thread.quit()
self.thread.wait()
self.thread.deleteLater() 
print ("GPIO CleanUP")
GPIO.cleanup() 
event.accept()   
def ReadChannel(channel):
adc = spi.xfer2([1,(8+channel)<<4,0])
data = ((adc[1]&3) << 8) + adc[2]
return data
def ConvertVolts(data, places):
volts = (data * 3.3) / float(1023)
volts = round(volts,places)
return volts    
class O2_Channel(QtCore.QThread):
o2_concentration = QtCore.pyqtSignal(int)
def __init__(self):
QtCore.QThread.__init__(self)
self.mRunning = True
def run(self):
while self.mRunning:
o2_level = ReadChannel(o2_channel)
o2_volts = ConvertVolts(o2_level,2)
print("{}".format(o2_volts))
self.o2_concentration.emit(o2_volts)
delay = .2                         
time.sleep(delay)
def stop(self):
self.mRunning = False
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = MyWindow()
sys.exit(app.exec_())

在另一篇文章中,eyllanesc 为我设置了信号和插槽,我需要将信号显示到我的 gui lcd 上,但我不太了解它,不知道他做了什么。 在过去的几天里,我一直在阅读有关此内容的文章,终于看到他做了什么。 一切都像我想要的那样工作。

对于任何可能有同样困惑的人,这是我的主要问题:

def onChangeValue(self, values):
o2_volts = values

我对此很陌生,以至于我没有意识到我需要实际将我指定的值放在上面的代码中代替"值"一词。 有点尴尬,但我想是学习的一部分。 另一个问题在这里:

o2_concentration = QtCore.pyqtSignal(int)

我没有意识到,但是在我修复"值"后,液晶屏正在工作,但读数为0,我认为它不起作用。使用光电管获得电压,我在打印到终端时得到 .25,但到 LCD 时得到 0。 再次作为新人,我没有考虑(int)不适合我想要的东西。 将其更改为(浮动)解决了问题。一切都很好。

我的脚本自原始帖子以来已经增长,但如果有人想看它,我很乐意发布它。

这是一个很棒的网站。 谢谢一切。

最新更新