We decided to provide our machine with a custom GUI written in python, using the QT framework. Thanks to QT designer we can quickly outline our GUI in a graphical editor that lets us place the various widget and, later on, I wrote the logic in python
#!/usr/bin/env python3
import sys
import serial
import time
from PyQt5 import uic
from PyQt5.QtCore import QDateTime
from PyQt5.QtWidgets import QApplication, QWidget, QDialog, QMessageBox
values = {}
def completed():
completed = QMessageBox()
completed.setWindowTitle('Completed')
completed.setText('I love it when a plan comes together')
completed.setStandardButtons(QMessageBox.Ok)
completed.exec_()
def spill_warning():
warning = QMessageBox()
warning.setWindowTitle('Warning')
warning.setText('Thou shalt not spill')
warning.setStandardButtons(QMessageBox.Ok)
warning.exec_()
def bad_communication():
bad_communication = QMessageBox()
bad_communication.setWindowTitle('Halt')
bad_communication.setText('Something went awry')
bad_communication.setStandardButtons(QMessageBox.Ok)
bad_communication.exec_()
#################
## UI ##
#################
class MyWin(QDialog):
def __init__(self, parent=None):
super(MyWin, self).__init__(parent)
self.initUI()
def initUI(self):
uic.loadUi('ui.ui', self)
self.setWindowTitle('titolone a caso')
self.pushButton.clicked.connect(self.grab_data)
self.show()
def grab_data(self):
values['t01_a'] = self.spinBox01a.value()
values['t01_b'] = self.spinBox01b.value()
values['t02_a'] = self.spinBox02a.value()
values['t02_b'] = self.spinBox02b.value()
values['t03_a'] = self.spinBox03a.value()
values['t03_b'] = self.spinBox03b.value()
self.ser = serial.Serial(self.lineEdit.text(), int(self.lineEdit_2.text()), timeout=2)
self.check_data()
def check_data(self):
for x in range(1, 4):
if values['t{0:02d}_a'.format(x)] + values['t{0:02d}_b'.format(x)] > 100:
return self.spill_warning()
self.send_data()
def send_data(self):
print('sending data')
for x in range(1, 4):
print('invio num {}'.format(x))
self.ser.write('{} {} {}\n'.format('{num:02d}'.format(num=x), values['t{num:02d}_a'.format(num=x)], values['t{num:02d}_b'.format(num=x)]).encode('ascii'))
time.sleep(5)
self.ser.flush()
try:
response = int(self.ser.readline())
except ValueError:
print('farlocco')
response = 1
print(response)
if response == 1:
print('pass')
else:
#self.ser.close()
#return self.bad_communication()
print('non pass')
self.ser.close()
completed()
################
## Start it ##
################
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyWin()
sys.exit(app.exec_())
Since we used Pietro's PowerNodes as our machine brain and brawns we had to make the various nodes communicate via the I2C bus. Here are the sketches for both the master node and the single slave (the pump and platform libraries were written by Pietro, here is his github repo, if you want to check his work):
#include < Wire.h >
#include "Pump.h"
#include "Platform.h"
#define DRIVER_ENABLE 5
#define DRIVER_STEP 6
#define DRIVER_DIR 7
#define LED 2
#define SERVO_1 9
#define SERVO_2 10
#define THERMISTOR A1
#define MAX_TUBES 18
#define STEPS_PER_TUBE 33
Platform platform(DRIVER_ENABLE, DRIVER_STEP, DRIVER_DIR, MAX_TUBES, STEPS_PER_TUBE);
int tube_number = 0;
int pump_one = 0;
int pump_two;
void setup() {
Serial.begin(9600);
Wire.begin();
}
void blink_led(int numb) {
for (int i=0; i 0) {
int tube_number = Serial.parseInt();
int pump_one = Serial.parseInt();
int pump_two = Serial.parseInt();
Serial.println("prese variabili");
if (Serial.read() == '\n') {
Serial.println("inizio trasmissione");
platform.goTo(tube_number);
Wire.beginTransmission(8);
Wire.write(pump_one);
Wire.endTransmission();
blink_led(2);
delay(100);
Wire.requestFrom(8, 2);
if (Wire.available()) {
int r = Wire.read();
Serial.println(r);
}
}
}
}
#include < Wire.h >
#include "Pump.h"
#define DRIVER_ENABLE 5
#define DRIVER_STEP 6
#define DRIVER_DIR 7
#define LED 2
#define SERVO_1 9
#define SERVO_2 10
#define THERMISTOR A1
Pump pump(DRIVER_ENABLE,DRIVER_STEP,DRIVER_DIR);
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(data_from_master);
Wire.onRequest(data_to_master);
}
void loop() {
delay(100);
}
void data_from_master(int num_bytes) {
pump.flow(200);
Serial.println("bella");
}
void data_to_master () {
Wire.write(1);
}