Skip to content

Commit

Permalink
Update source code
Browse files Browse the repository at this point in the history
  • Loading branch information
n-yoshikawa committed May 1, 2023
1 parent 79778c1 commit bf0b7ee
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
36 changes: 25 additions & 11 deletions src/controller.py
Original file line number Diff line number Diff line change
@@ -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()
39 changes: 17 additions & 22 deletions src/pipette.ino
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
#include <Servo.h>

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);
myServo.writeMicroseconds(len0);
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);
}
}

0 comments on commit bf0b7ee

Please sign in to comment.