Commit b9050ff4 authored by Alisson Claudino's avatar Alisson Claudino

Separação de classes em arquivos e config. serial na interface

parent ffbf973f
#include "HX711.h"
// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0
HX711 channelA(A1, A0,32); //Instancia um objeto da classe HX711 vinculado ao canal A
HX711 channelB(A1, A0,128); //Instancia um objeto da classe HX711 vinculado ao canal B
void setup() {
Serial.begin(115200); //Inicia a Serial com taxa de tranferência de 115200 bps
channelA.set_scale(); //Reseta a escala do canal A
channelA.tare(); //
channelB.set_scale(); //Reseta a escala do canal B
channelB.tare();
Serial.print("Primeira Leitura do Canal A: \t\t");
Serial.print(channelA.read()); // Primeira leitura do canal A
Serial.print("\n\n");
Serial.print("Primeira Leitura do Canal B: \t\t");
Serial.print(channelB.read()); // Primeira leitura do canal B
Serial.print("\n\n");
Serial.print("Primeira média do canal A (20): \t\t");
Serial.print(channelA.read_average(20)); // Imprime a média de 20 leituras do canal A
Serial.print("\n\n");
Serial.print("Primeira média do canal B (20): \t\t");
Serial.print(channelB.read_average(20)); // Imprime a média de 20 leituras do canal B
Serial.print("\n\n");
}
void loop() {
Serial.print("Leitura (Canal A):"); //Realiza uma leitura do canal A e imprime na serial
Serial.print(channelA.read());
Serial.print("\n\n");
delay(200);
Serial.print("Leitura (Canal B):"); //Realiza uma leitura do canal B e imprime na serial
Serial.print(channelB.read());
Serial.print("\n\n");
delay(500);
}
#include "HX711.h"
double a=0,b=0;
// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0
HX711 channelA(A1, A0,32); //Instancia um objeto da classe HX711 vinculado ao canal A
//HX711 channelB(A1, A0,128); //Instancia um objeto da classe HX711 vinculado ao canal B
void setup() {
Serial.begin(9600); //Inicia a Serial com taxa de tranferência de 115200 bps
channelA.set_scale(); //Reseta a escala do canal A
channelA.tare(); //
//channelB.set_scale(); //Reseta a escala do canal B
//channelB.tare();
//channelA.set_offset(0);
//channelB.set_offset(0);
Serial.print("Primeira Leitura do Canal A: \t\t");
Serial.print(channelA.read()); // Primeira leitura do canal A
Serial.print("\n\n");
/*Serial.print("Primeira Leitura do Canal B: \t\t");
Serial.print(channelB.read()); // Primeira leitura do canal B
Serial.print("\n\n");*/
/* Serial.print("Primeira média do canal A (20): \t\t");
Serial.print(channelA.read_average(20)); // Imprime a média de 20 leituras do canal A
Serial.print("\n\n");
Serial.print("Primeira média do canal B (20): \t\t");
Serial.print(channelB.read_average(20)); // Imprime a média de 20 leituras do canal B
Serial.print("\n\n");*/
}
void loop() {
//channelA.set_gain(128);
//Serial.print("\nLeitura (Canal A):"); //Realiza uma leitura do canal A e imprime na serial
a=channelA.read();
Serial.println(a);
while(!channelA.is_ready())
{}
/*if(a<b)
{Serial.print("\n\n");
Serial.print("ESSE:");
Serial.print(b);
Serial.print("\n\n");}*/
//while(millis()%100!=0);
//Serial.println(millis());
/*Serial.print(" ");
Serial.print(millis());
Serial.println();*/
//Serial.print("\n\n");
/*channelA.set_gain(32);
Serial.print("Leitura (Canal B):"); //Realiza uma leitura do canal B e imprime na serial
Serial.print(channelA.read_average(5));*/
/*Serial.print("\n\n");
a=analogRead(A3);
a=a*5/1023;
Serial.println(a);
Serial.println(channelA.get_scale());
//Serial.println(channelB.get_scale());
Serial.println(channelA.get_offset());
//Serial.println(channelB.get_offset());*/
/*channelA.power_down();
delay(500);
channelA.power_up();*/
}
#include <Arduino.h>
#include <HX711.h>
#if ARDUINO_VERSION <= 106
// "yield" is not implemented as noop in older Arduino Core releases, so let's define it.
// See also: https://stackoverflow.com/questions/34497758/what-is-the-secret-of-the-arduino-yieldfunction/34498165#34498165
void yield(void) {};
#endif
HX711::HX711(byte dout, byte pd_sck, byte gain) {
begin(dout, pd_sck, gain);
}
HX711::HX711() {
}
HX711::~HX711() {
}
void HX711::begin(byte dout, byte pd_sck, byte gain) {
PD_SCK = pd_sck;
DOUT = dout;
pinMode(PD_SCK, OUTPUT);
pinMode(DOUT, INPUT);
set_gain(gain);
}
bool HX711::is_ready() {
return digitalRead(DOUT) == LOW;
}
void HX711::set_gain(byte gain) {
switch (gain) {
case 128: // channel A, gain factor 128
GAIN = 1;
break;
case 64: // channel A, gain factor 64
GAIN = 3;
break;
case 32: // channel B, gain factor 32
GAIN = 2;
break;
}
digitalWrite(PD_SCK, LOW);
read();
}
long HX711::read() {
// wait for the chip to become ready
while (!is_ready()) {
// Will do nothing on Arduino but prevent resets of ESP8266 (Watchdog Issue)
yield();
}
unsigned long value = 0;
uint8_t data[3] = { 0 };
uint8_t filler = 0x00;
// pulse the clock pin 24 times to read the data
data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST);
data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST);
data[0] = shiftIn(DOUT, PD_SCK, MSBFIRST);
// set the channel and the gain factor for the next reading using the clock pin
for (unsigned int i = 0; i < GAIN; i++) {
digitalWrite(PD_SCK, HIGH);
digitalWrite(PD_SCK, LOW);
}
// Replicate the most significant bit to pad out a 32-bit signed integer
if (data[2] & 0x80) {
filler = 0xFF;
} else {
filler = 0x00;
}
// Construct a 32-bit signed integer
value = ( static_cast<unsigned long>(filler) << 24
| static_cast<unsigned long>(data[2]) << 16
| static_cast<unsigned long>(data[1]) << 8
| static_cast<unsigned long>(data[0]) );
return static_cast<long>(value);
}
long HX711::read_average(byte times) {
long sum = 0;
for (byte i = 0; i < times; i++) {
sum += read();
yield();
}
return sum / times;
}
double HX711::get_value(byte times) {
return read_average(times) - OFFSET;
}
float HX711::get_units(byte times) {
return get_value(times) / SCALE;
}
void HX711::tare(byte times) {
double sum = read_average(times);
set_offset(sum);
}
void HX711::set_scale(float scale) {
SCALE = scale;
}
float HX711::get_scale() {
return SCALE;
}
void HX711::set_offset(long offset) {
OFFSET = offset;
}
long HX711::get_offset() {
return OFFSET;
}
void HX711::power_down() {
digitalWrite(PD_SCK, LOW);
digitalWrite(PD_SCK, HIGH);
}
void HX711::power_up() {
digitalWrite(PD_SCK, LOW);
}
#ifndef HX711_h
#define HX711_h
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class HX711
{
private:
byte PD_SCK; // Power Down and Serial Clock Input Pin
byte DOUT; // Serial Data Output Pin
byte GAIN; // amplification factor
long OFFSET = 0; // used for tare weight
float SCALE = 1; // used to return weight in grams, kg, ounces, whatever
public:
// define clock and data pin, channel, and gain factor
// channel selection is made by passing the appropriate gain: 128 or 64 for channel A, 32 for channel B
// gain: 128 or 64 for channel A; channel B works with 32 gain factor only
HX711(byte dout, byte pd_sck, byte gain = 128);
HX711();
virtual ~HX711();
// Allows to set the pins and gain later than in the constructor
void begin(byte dout, byte pd_sck, byte gain = 128);
// check if HX711 is ready
// from the datasheet: When output data is not ready for retrieval, digital output pin DOUT is high. Serial clock
// input PD_SCK should be low. When DOUT goes to low, it indicates data is ready for retrieval.
bool is_ready();
// set the gain factor; takes effect only after a call to read()
// channel A can be set for a 128 or 64 gain; channel B has a fixed 32 gain
// depending on the parameter, the channel is also set to either A or B
void set_gain(byte gain = 128);
// waits for the chip to be ready and returns a reading
long read();
// returns an average reading; times = how many times to read
long read_average(byte times = 10);
// returns (read_average() - OFFSET), that is the current value without the tare weight; times = how many readings to do
double get_value(byte times = 1);
// returns get_value() divided by SCALE, that is the raw value divided by a value obtained via calibration
// times = how many readings to do
float get_units(byte times = 1);
// set the OFFSET value for tare weight; times = how many times to read the tare value
void tare(byte times = 10);
// set the SCALE value; this value is used to convert the raw data to "human readable" data (measure units)
void set_scale(float scale = 1.f);
// get the current SCALE
float get_scale();
// set OFFSET, the value that's subtracted from the actual reading (tare weight)
void set_offset(long offset = 0);
// get the current OFFSET
long get_offset();
// puts the chip into power down mode
void power_down();
// wakes up the chip after power down mode
void power_up();
};
#endif /* HX711_h */
const int tensao = A0;
int sensorValue = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while(millis()%20!=0)
{}
sensorValue = analogRead(tensao);
Serial.print("\nSensor_1 :");
Serial.print(sensorValue);
Serial.print(",");
Serial.print(millis());
delay(1);
}
help:
@echo 'Help details:'
@echo 'hex: compile hex file'
@echo 'flash: install hex file'
@echo 'program: compile hex and install'
hex:
avr-gcc -Os -DF_CPU=16000000 -mmcu=atmega328p -c main.cpp
avr-gcc -DF_CPU=16000000 -mmcu=atmega328p -o main.elf main.o
avr-objcopy -O ihex main.elf main.hex
rm main.o
rm main.elf
flash:
avrdude -c arduino -p atmega328p -P /dev/ttyUSB0 -U flash:w:main.hex
......@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'Resources/CalibracaoP.ui'
#
# Created: Fri Nov 10 15:32:01 2017
# Created: Tue Nov 14 12:27:19 2017
# by: PyQt5 UI code generator 5.2.1
#
# WARNING! All changes made in this file will be lost!
......@@ -11,6 +11,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
self.MainWindow=MainWindow
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1366, 695)
MainWindow.setMinimumSize(QtCore.QSize(817, 0))
......@@ -41,9 +42,12 @@ class Ui_MainWindow(object):
self.escalaBox.setObjectName("escalaBox")
self.forcaBox = QtWidgets.QGroupBox(self.escalaBox)
self.forcaBox.setGeometry(QtCore.QRect(10, 30, 181, 101))
self.forcaBox.setStyleSheet("background-color:rgb(53, 53, 53)")
self.forcaBox.setObjectName("forcaBox")
self.f_max = QtWidgets.QLineEdit(self.forcaBox)
self.f_max.setGeometry(QtCore.QRect(80, 30, 61, 21))
self.f_max.setStyleSheet("color:rgb(0,0,0);\n"
"background-color: rgb(158, 151, 151);")
self.f_max.setObjectName("f_max")
self.f_max_label = QtWidgets.QLabel(self.forcaBox)
self.f_max_label.setGeometry(QtCore.QRect(20, 30, 57, 21))
......@@ -55,12 +59,17 @@ class Ui_MainWindow(object):
self.f_min_label.setObjectName("f_min_label")
self.f_min = QtWidgets.QLineEdit(self.forcaBox)
self.f_min.setGeometry(QtCore.QRect(80, 60, 61, 21))
self.f_min.setStyleSheet("color:rgb(0,0,0);\n"
"background-color: rgb(158, 151, 151);")
self.f_min.setObjectName("f_min")
self.pressaoBox = QtWidgets.QGroupBox(self.escalaBox)
self.pressaoBox.setGeometry(QtCore.QRect(200, 30, 181, 101))
self.pressaoBox.setStyleSheet("background-color:rgb(53, 53, 53)")
self.pressaoBox.setObjectName("pressaoBox")
self.p_max = QtWidgets.QLineEdit(self.pressaoBox)
self.p_max.setGeometry(QtCore.QRect(80, 30, 61, 21))
self.p_max.setStyleSheet("color:rgb(0,0,0);\n"
"background-color: rgb(158, 151, 151);")
self.p_max.setObjectName("p_max")
self.p_max_label = QtWidgets.QLabel(self.pressaoBox)
self.p_max_label.setGeometry(QtCore.QRect(20, 30, 57, 21))
......@@ -72,26 +81,33 @@ class Ui_MainWindow(object):
self.p_min_label.setObjectName("p_min_label")
self.p_min = QtWidgets.QLineEdit(self.pressaoBox)
self.p_min.setGeometry(QtCore.QRect(80, 60, 61, 21))
self.p_min.setStyleSheet("color:rgb(0,0,0);\n"
"background-color: rgb(158, 151, 151);")
self.p_min.setObjectName("p_min")
self.forcaBox_2 = QtWidgets.QGroupBox(self.escalaBox)
self.forcaBox_2.setGeometry(QtCore.QRect(100, 140, 171, 81))
self.forcaBox_2.setObjectName("forcaBox_2")
self.f_max_2 = QtWidgets.QLineEdit(self.forcaBox_2)
self.f_max_2.setGeometry(QtCore.QRect(100, 30, 61, 21))
self.f_max_2.setObjectName("f_max_2")
self.f_max_label_2 = QtWidgets.QLabel(self.forcaBox_2)
self.f_max_label_2.setGeometry(QtCore.QRect(10, 30, 81, 21))
self.f_max_label_2.setStyleSheet("border: rgb(255,255,255)")
self.f_max_label_2.setObjectName("f_max_label_2")
self.tempoGBox = QtWidgets.QGroupBox(self.escalaBox)
self.tempoGBox.setGeometry(QtCore.QRect(100, 140, 171, 81))
self.tempoGBox.setStyleSheet("background-color:rgb(53, 53, 53)")
self.tempoGBox.setObjectName("tempoGBox")
self.t_max = QtWidgets.QLineEdit(self.tempoGBox)
self.t_max.setGeometry(QtCore.QRect(100, 30, 61, 21))
self.t_max.setStyleSheet("color:rgb(0,0,0);\n"
"background-color: rgb(158, 151, 151);")
self.t_max.setObjectName("t_max")
self.t_max_label = QtWidgets.QLabel(self.tempoGBox)
self.t_max_label.setGeometry(QtCore.QRect(10, 30, 81, 21))
self.t_max_label.setStyleSheet("border: rgb(255,255,255)")
self.t_max_label.setObjectName("t_max_label")
self.amostragemBox = QtWidgets.QGroupBox(self.centralWidget)
self.amostragemBox.setGeometry(QtCore.QRect(20, 250, 181, 71))
self.amostragemBox.setStyleSheet("border:1px solid rgb(255, 83, 0);\n"
self.amostragemBox.setStyleSheet("background-color:rgb(53, 53, 53);\n"
"border:1px solid rgb(255, 83, 0);\n"
"color: rgb(255,255,255);")
self.amostragemBox.setObjectName("amostragemBox")
self.amostragemCBox = QtWidgets.QComboBox(self.amostragemBox)
self.amostragemCBox.setGeometry(QtCore.QRect(50, 30, 101, 27))
self.amostragemCBox.setStyleSheet("border-color: rgb(255,255,255);\n"
self.amostragemCBox.setStyleSheet("border-color: rgb(0,0,0);\n"
"background-color: rgb(169, 169, 169);\n"
"\n"
"")
self.amostragemCBox.setObjectName("amostragemCBox")
self.amostragemCBox.addItem("")
......@@ -109,40 +125,56 @@ class Ui_MainWindow(object):
self.cronometroBox.setObjectName("cronometroBox")
self.timerOptionButton = QtWidgets.QPushButton(self.cronometroBox)
self.timerOptionButton.setGeometry(QtCore.QRect(140, 130, 61, 31))
self.timerOptionButton.setStyleSheet("background-color:rgb(53, 53, 53)")
self.timerOptionButton.setObjectName("timerOptionButton")
self.initTimerButton = QtWidgets.QPushButton(self.cronometroBox)
self.initTimerButton.setGeometry(QtCore.QRect(140, 30, 61, 31))
self.initTimerButton.setStyleSheet("background-color:rgb(53, 53, 53)")
self.initTimerButton.setObjectName("initTimerButton")
self.cronometroGBox = QtWidgets.QGroupBox(self.cronometroBox)
self.cronometroGBox.setGeometry(QtCore.QRect(10, 30, 120, 131))
self.cronometroGBox.setStyleSheet("background-color:rgb(53, 53, 53)")
self.cronometroGBox.setObjectName("cronometroGBox")
self.cronometroLabel = QtWidgets.QLabel(self.cronometroGBox)
self.cronometroLabel.setGeometry(QtCore.QRect(20, 60, 81, 31))
self.cronometroLabel.setStyleSheet("background-color: rgb(158, 151, 151);\n"
"color:rgb(0, 0, 0);\n"
"font: 75 12pt \"Noto Serif\";")
self.cronometroLabel.setObjectName("cronometroLabel")
self.horaInicGBox = QtWidgets.QGroupBox(self.cronometroBox)
self.horaInicGBox.setGeometry(QtCore.QRect(220, 10, 151, 71))
self.horaInicGBox.setStyleSheet("background-color:rgb(53, 53, 53)")
self.horaInicGBox.setObjectName("horaInicGBox")
self.horaInicLabel = QtWidgets.QLabel(self.horaInicGBox)
self.horaInicLabel.setGeometry(QtCore.QRect(30, 30, 91, 31))
self.horaInicLabel.setStyleSheet("font: 14pt \"Noto Serif\";")
self.horaInicLabel.setStyleSheet("background-color: rgb(158, 151, 151);\n"
"color:rgb(0, 0, 0);\n"
"font: 14pt \"Noto Serif\";")
self.horaInicLabel.setObjectName("horaInicLabel")
self.horaAtualGBox = QtWidgets.QGroupBox(self.cronometroBox)
self.horaAtualGBox.setGeometry(QtCore.QRect(220, 90, 151, 71))
self.horaAtualGBox.setStyleSheet("background-color:rgb(53, 53, 53)")
self.horaAtualGBox.setObjectName("horaAtualGBox")
self.horaAtualLabel = QtWidgets.QLabel(self.horaAtualGBox)
self.horaAtualLabel.setGeometry(QtCore.QRect(30, 30, 91, 31))
self.horaAtualLabel.setStyleSheet("font: 14pt \"Noto Serif\";")
self.horaAtualLabel.setStyleSheet("background-color: rgb(158, 151, 151);\n"
"color:rgb(0, 0, 0);\n"
"font: 14pt \"Noto Serif\";")
self.horaAtualLabel.setObjectName("horaAtualLabel")
self.stopTimerButton = QtWidgets.QPushButton(self.cronometroBox)
self.stopTimerButton.setGeometry(QtCore.QRect(140, 80, 61, 31))
self.stopTimerButton.setStyleSheet("background-color:rgb(53, 53, 53)")
self.stopTimerButton.setObjectName("stopTimerButton")
self.prensaNameGBox = QtWidgets.QGroupBox(self.centralWidget)
self.prensaNameGBox.setGeometry(QtCore.QRect(210, 250, 191, 71))
self.prensaNameGBox.setStyleSheet("border: 1px solid rgb(27, 144, 0);")
self.prensaNameGBox.setStyleSheet("border: 1px solid rgb(27, 144, 0);\n"
"background-color:rgb(53, 53, 53)")
self.prensaNameGBox.setObjectName("prensaNameGBox")
self.prensaName = QtWidgets.QLineEdit(self.prensaNameGBox)
self.prensaName.setGeometry(QtCore.QRect(50, 20, 111, 31))
self.prensaName.setStyleSheet("font: 12pt \"Noto Serif\";")
self.prensaName.setStyleSheet("font: 12pt \"Noto Serif\";\n"
"color:rgb(0,0,0);\n"
"background-color: rgb(158, 151, 151);")
self.prensaName.setObjectName("prensaName")
self.valAbsolGBox = QtWidgets.QGroupBox(self.centralWidget)
self.valAbsolGBox.setGeometry(QtCore.QRect(20, 510, 381, 111))
......@@ -150,17 +182,23 @@ class Ui_MainWindow(object):
self.valAbsolGBox.setObjectName("valAbsolGBox")
self.forcaGBox = QtWidgets.QGroupBox(self.valAbsolGBox)
self.forcaGBox.setGeometry(QtCore.QRect(20, 30, 161, 71))
self.forcaGBox.setStyleSheet("background-color:rgb(53, 53, 53)")
self.forcaGBox.setObjectName("forcaGBox")
self.forcaLabel = QtWidgets.QLabel(self.forcaGBox)
self.forcaLabel.setGeometry(QtCore.QRect(20, 30, 121, 31))
self.forcaLabel.setStyleSheet("font: 14pt \"Noto Serif\";")
self.forcaLabel.setStyleSheet("background-color: rgb(158, 151, 151);\n"
"color:rgb(0, 0, 0);\n"
"font: 14pt \"Noto Serif\";")
self.forcaLabel.setObjectName("forcaLabel")
self.calibranteGBox = QtWidgets.QGroupBox(self.valAbsolGBox)
self.calibranteGBox.setGeometry(QtCore.QRect(200, 30, 161, 71))
self.calibranteGBox.setStyleSheet("background-color:rgb(53, 53, 53)")
self.calibranteGBox.setObjectName("calibranteGBox")
self.calibranteLabel = QtWidgets.QLabel(self.calibranteGBox)
self.calibranteLabel.setGeometry(QtCore.QRect(20, 30, 131, 31))
self.calibranteLabel.setStyleSheet("font: 14pt \"Noto Serif\";")
self.calibranteLabel.setStyleSheet("background-color: rgb(158, 151, 151);\n"
"color:rgb(0, 0, 0);\n"
"font: 14pt \"Noto Serif\";")
self.calibranteLabel.setObjectName("calibranteLabel")
self.arquivoSalvoLabel = QtWidgets.QLabel(self.centralWidget)
self.arquivoSalvoLabel.setGeometry(QtCore.QRect(20, 630, 111, 16))
......@@ -176,6 +214,8 @@ class Ui_MainWindow(object):
self.menuArquivo.setObjectName("menuArquivo")
self.menuEtapa = QtWidgets.QMenu(self.menuBar)
self.menuEtapa.setObjectName("menuEtapa")
self.menuPorta = QtWidgets.QMenu(self.menuBar)
self.menuPorta.setObjectName("menuPorta")
MainWindow.setMenuBar(self.menuBar)
self.menuStatusBar = QtWidgets.QStatusBar(MainWindow)
self.menuStatusBar.setObjectName("menuStatusBar")
......@@ -197,6 +237,8 @@ class Ui_MainWindow(object):
self.botaoSalvar.setObjectName("botaoSalvar")
self.botaoSalvarComo = QtWidgets.QAction(MainWindow)
self.botaoSalvarComo.setObjectName("botaoSalvarComo")
self.selectPortaUSB = QtWidgets.QAction(MainWindow)
self.selectPortaUSB.setObjectName("selectPortaUSB")
self.menuArquivo.addAction(self.botaoAbrir)
self.menuArquivo.addAction(self.botaoSalvar)
self.menuArquivo.addAction(self.botaoSalvarComo)
......@@ -205,6 +247,7 @@ class Ui_MainWindow(object):
self.menuEtapa.addAction(self.alternaProc)
self.menuBar.addAction(self.menuArquivo.menuAction())
self.menuBar.addAction(self.menuEtapa.menuAction())
self.menuBar.addAction(self.menuPorta.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
......@@ -220,8 +263,8 @@ class Ui_MainWindow(object):
self.pressaoBox.setTitle(_translate("MainWindow", "Tensão no Calibrante"))
self.p_max_label.setText(_translate("MainWindow", "Máximo:"))
self.p_min_label.setText(_translate("MainWindow", "Mínimo:"))
self.forcaBox_2.setTitle(_translate("MainWindow", "Tempo"))
self.f_max_label_2.setText(_translate("MainWindow", "Intervalo (s):"))
self.tempoGBox.setTitle(_translate("MainWindow", "Tempo"))
self.t_max_label.setText(_translate("MainWindow", "Intervalo (s):"))
self.amostragemBox.setTitle(_translate("MainWindow", "Amostragem"))
self.amostragemCBox.setItemText(0, _translate("MainWindow", "100 mseg"))
self.amostragemCBox.setItemText(1, _translate("MainWindow", "200 mseg"))
......@@ -253,6 +296,7 @@ class Ui_MainWindow(object):
self.arqSalvoLabel.setText(_translate("MainWindow", "/home/LAPMA/Pressao/1025565.pre"))
self.menuArquivo.setTitle(_translate("MainWindow", "Arquivo"))
self.menuEtapa.setTitle(_translate("MainWindow", "Etapa"))
self.menuPorta.setTitle(_translate("MainWindow", "Porta"))
self.alternaCalibraP.setText(_translate("MainWindow", "Calibração P"))
self.alternaCalibraT.setText(_translate("MainWindow", "Calibração T"))
self.alternaProc.setText(_translate("MainWindow", "Processamento"))
......@@ -261,7 +305,15 @@ class Ui_MainWindow(object):
self.actionSalvar_Como.setText(_translate("MainWindow", "Salvar Como"))
self.botaoSalvar.setText(_translate("MainWindow", "Salvar"))
self.botaoSalvarComo.setText(_translate("MainWindow", "Salvar Como"))
self.selectPortaUSB.setText(_translate("MainWindow", "Selecionar porta USB"))
def sceneSelector(self, scene):
self.CentralGraph.setScene(scene)
self.CentralGraph.setBackgroundBrush(QtCore.Qt.black)
\ No newline at end of file
self.CentralGraph.setBackgroundBrush(QtCore.Qt.black)
def serialListPanel(self, seriaList):
self.usb=[]
for i in range(0, len(seriaList)):
self.usb.append(QtWidgets.QAction(self.MainWindow))
self.usb[i].setText(seriaList[i].device)
self.menuPorta.addAction(self.usb[i])
\ No newline at end of file
from PyQt5 import QtCore,QtGui,QtWidgets # importação de classes
import pyqtgraph
import serial
import time
import sys
from CalibracaoP import Ui_MainWindow
class SerialManager(object):
def __init__(self):
self.ser = serial.Serial('/dev/ttyUSB0', 115200) # Inicialização da Serial com baudrate 115200bps
self.ser.setDTR(False) # Reset do arduino para reinicio da leitura
time.sleep(0.022)
self.ser.setDTR(True)
self.ser.readline() # Primeiro valor da serial sai com lixo
def read(self):
if(self.ser.inWaiting()==0):
pass
return self.ser.readline()
class Graph(pyqtgraph.GraphicsLayout):
......@@ -40,13 +23,13 @@ class Graph(pyqtgraph.GraphicsLayout):
self.x1=[]
self.y1=[]
self.y2=[]
self.timeant=time.time()
#self.p1.enableAutoScale()
def updateGraph(self,y1,y2):
print(time.time()-self.timeant)
self.y1.append(y1)
self.y2.append(y2)
if len(self.y1)>self.x_range+1:
del self.y1[0]
del self.y2[0]
......@@ -57,11 +40,16 @@ class Graph(pyqtgraph.GraphicsLayout):
self.curve1.setData(self.x1, self.y1)
self.curve2.setData(self.x1,self.y2)
self.timeant = time.time()
def setGraphScale(self,x_range,y_range):
if(x_range==0):
x_range=1
def setGraphScale(self,x_range,y_range):
if(y_range==0):
y_range=1
self.x_range=x_range
self.y_range=y_range
self.x1=[]
......@@ -73,43 +61,4 @@ class Graph(pyqtgraph.GraphicsLayout):
self.p1.setXRange(0, self.x_range, padding=0)
self.p1.setYRange(0, self.y_range, padding=0)
self.curve1=self.p1.plot(pen=self.color1)
self.curve2=self.p1.plot(pen=self.color2)
class SystemEngine(object):
def __init__(self):
self.app = QtWidgets.QApplication(sys.argv)
self.dialog = QtWidgets.QMainWindow()
self.ser1 = SerialManager()
self.uiCalibra1 = Ui_MainWindow()
self.uiCalibra1.setupUi(self.dialog)
self.layout = Graph(100, 10230, 900, 600, 'r','g')
self.scene = QtGui.QGraphicsScene()
self.scene.addItem(self.layout)
self.uiCalibra1.sceneSelector(self.scene)
self.dialog.showMaximized()
self.prev_x_scale=100
self.x_scale=100
def updateData(self):
readData = self.ser1.read() # Lê o dado da serial
readData = readData.decode('utf8')
dado = readData.split(' ', 3)
self.x_scale=int(self.uiCalibra1.f_max.text())
if(self.x_scale != self.prev_x_scale):
self.layout.setGraphScale(int(self.x_scale),32700)
self.prev_x_scale = self.x_scale
self.layout.updateGraph(float(dado[0]),float(dado[1]))
if __name__ == '__main__':
engine=SystemEngine()
timer = QtCore.QTimer() #
timer.timeout.connect(engine.updateData) #
timer.start(0)
sys.exit(engine.app.exec_())
self.curve2 = self.p1.plot(pen=self.color2)
\ No newline at end of file
from PyQt5 import QtCore,QtGui,QtWidgets # importação de classes
import pyqtgraph
import serial
import serial.tools.list_ports
import time
import sys
from SerialManager import SerialManager