-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharduino.py
More file actions
36 lines (29 loc) · 885 Bytes
/
arduino.py
File metadata and controls
36 lines (29 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import serial
from time import sleep
class Arduino:
def __init__(self, port_name):
self.serial = serial.Serial(
port='/dev/' + port_name,
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0.1
)
if not self.serial.isOpen():
print("Couldn't open serial port!")
else:
sleep(1)
def close_connection(self):
self.serial.close()
def send(self, command):
self.serial.write(str.encode(command.__str__()))
def read(self):
return self.serial.read_until('\n').decode("utf-8")
def get_line_sensors(self):
self.send('LINE')
return self.read()
def get_rfid_value(self):
self.send('RFID')
sleep(0.5)
return self.read()