diff --git a/src/controller.py b/src/controller.py index d281e6e..10e2355 100644 --- a/src/controller.py +++ b/src/controller.py @@ -1,15 +1,29 @@ import serial +import time +# Open a serial port ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1) -ser.readline() - -up = True -while True: - data = ser.readline() - if up: - command = 'a' - else: - command = '0' - ser.write(bytes(command, 'utf-8')) - up = not up +time.sleep(1) +print(ser.readline()) + +# Length that corresponds each volume +len_0mL = '1820' +len_1mL = '1755' +len_5mL = '1528' +len_10mL = '1286' + +# Initialize +ser.write(bytes(len_0mL, 'ascii')) +time.sleep(5) +print(ser.readline()) + +for _ in range(5): + # Aspirate 5 mL + ser.write(bytes(len_5mL, 'ascii')) + time.sleep(5) + print(ser.readline()) + # Dispense liquid + ser.write(bytes(len_0mL, 'ascii')) + time.sleep(5) + print(ser.readline()) ser.close() diff --git a/src/pipette.ino b/src/pipette.ino index 88d40e8..2dd627b 100644 --- a/src/pipette.ino +++ b/src/pipette.ino @@ -1,14 +1,11 @@ #include - Servo myServo; -int len0 = 1820; -int len5 = 1522; -int len10 = 1286; - +#define len0 (1820) #define PIN_SERVO (8) -void setup() { +void setup() +{ Serial.begin(9600); Serial.println("Start!"); myServo.attach(PIN_SERVO); @@ -16,22 +13,20 @@ void setup() { delay(5000); } -void loop() { - char key; - if (Serial.available()) { - key = Serial.read(); - Serial.println(key); - switch (key) { - case 'a': - myServo.writeMicroseconds(len10); - break; - case '5': - myServo.writeMicroseconds(len5); - break; - case '0': - myServo.writeMicroseconds(len0); - break; + +void loop() +{ + if ( Serial.available() ) { + String len_str = Serial.readString(); + Serial.print("Received Value: "); + Serial.println(len_str); + int len = len_str.toInt(); + if (len >= 1000 && len <= 2000) + { + Serial.println("Valid value"); + myServo.writeMicroseconds(len); + } else { + Serial.println("Invalid value"); } - delay(1000); } }