-
Notifications
You must be signed in to change notification settings - Fork 0
/
datafromunor3.py
37 lines (31 loc) · 880 Bytes
/
datafromunor3.py
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
37
'''
Author: Hayat Tamboli
Date: 2024-04-14
Description: This file reads data from the serial port of the Arduino UNO R3 and stores it in a queue.
'''
import serial
import serial.serialutil
import queue
line = ""
words = []
words_queue2 = queue.Queue()
def readDataFromR3():
global line
global words
global words_queue2
ser = None
try:
ser = serial.Serial(port='COM8', baudrate=9600)
except serial.serialutil.SerialException as e:
print("Could not open port: ", str(e))
return
while True:
try:
line = ser.readline().decode('utf-8', errors='replace').strip()
except UnicodeDecodeError as e:
print(f"UnicodeDecodeError: {e}")
line = "Error: Unable to decode"
words = line.split()
# print(words)
words_queue2.put(words)
# readDataFromR3()