0

Im creating a GUI (graphical user interface) that read 3 sensors and display 2 as lcd and plot the other. I have been able to create the GUI with the elements required and start measuring when I press a botton. But it only work with the plotting system. I have not been able to make the other 2 displays work. In resume I have not been able to understand how the update system work. Note, By now everything is working with random numbers then i will change the update to take the elements that I need.

from PyQt4 import QtCore, QtGui
import pyqtgraph as pg
import random
from math import*
class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.central_widget = QtGui.QStackedWidget()
        self.setCentralWidget(self.central_widget)
        self.login_widget = LoginWidget(self)
        self.login_widget.button.clicked.connect(self.plotter)
        self.central_widget.addWidget(self.login_widget)
    def plotter(self):
        self.data =[0]
        self.start = time.time()
        self.curve = self.login_widget.plot.getPlotItem().plot()
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.updater)
        self.timer.start(0)
    def updater(self):
        self.data.append(self.data[-1]+0.2*(0.5-random.random()))
        self.curve.setData(self.data)
        self.end = time.time()
        self.login_widget.Temperatura.display(self.data[-1])
        self.login_widget.etanol.display(self.end-self.start)
class LoginWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        super(LoginWidget, self).__init__(parent)
        layout = QtGui.QVBoxLayout()
        hbox1 = QtGui.QHBoxLayout()
        hbox2 = QtGui.QHBoxLayout()
        hbox3 = QtGui.QHBoxLayout()
        self.button = QtGui.QPushButton('Start')
        self.button2 = QtGui.QPushButton('Save')
        self.plot = pg.PlotWidget()
        self.setLayout(layout)
        self.Temperatura = QtGui.QLCDNumber(self)
        self.Temperatura.setStyleSheet("QWidget { background-color: rgb(100, 100, 255) }")
        self.etanol = QtGui.QLCDNumber(self)
        self.WindowSize = QtGui.QLabel("Temperature")
        self.SampPts = QtGui.QLabel("% Ethanol")
        layout.addLayout(hbox1)
        hbox1.addWidget(self.button2)
        hbox1.addWidget(self.button)
        layout.addLayout(hbox2)
        hbox2.addWidget(self.WindowSize)
        hbox2.addWidget(self.SampPts)
        layout.addLayout(hbox3)
        hbox3.addWidget(self.Temperatura)
        hbox3.addWidget(self.etanol)
        layout.addWidget(self.plot)
if __name__ == '__main__':
    app = QtGui.QApplication([])
    window = MainWindow()
    window.show()
    app.exec_()

The expected result is that wen i press the button all the elements should show different random numbers and start plotting. by now it's only start plotting. I don't like the LCD Widget, if you know another please tell me.

thank!

PBocca
  • 1
  • 2

2 Answers2

0

If you are just trying to add the data that is being added in the self.data list to the LCD, you can add this to your updater() method.

self.login_widget.Temperatura.display(self.data[-1])
self.login_widget.etanol.display((self.data[-1]*100))

If you are looking to send data from arduino to python take a look at this; Sending Data From Arduino to Python

If this is not the desired result, can you please be more specific on what you want showing?

Drees
  • 688
  • 1
  • 6
  • 21
  • Hi, It worked. I update the fixed version on the code, maybe it can help someone else. I Will check the link to add that function. When I finish I will upgrade the final version of the code. With the save function and all. Thanks a lot! – PBocca Aug 06 '19 at 21:13
  • @PBocca Glad to help. – Drees Aug 06 '19 at 21:32
0

Interesting I will try it but I whant to add 3 different data’s, one come from an analog censor (accelerometer), that is what I wont to plot, the other 2, come from serial, I have an arduino connected to a sensor that measure the temperature and the percentage of ethanol in fuel. Both of them I want to display them in the lcd widget. By now instead of the analog input a use a random number, and the other 2 can show any other thing like sine or cosine, but the 3 elements show different things. I will try the line of code that you have show me creating 2 other variables like slef.datatemp and self.dataethanol. I will coment if it work. The reason that I use random numbers is because it let me execuite the code in eny computer and fix the mistakes, then I will chane de data for what I whant. it was too long for a comment. Thanks!

PBocca
  • 1
  • 2
  • Check my edited answer as it contains a link to transferring data from arduino to python, also it is better to just create two separate comments instead of posting a comment as an answer. – Drees Aug 02 '19 at 19:44