-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadSerial.py
More file actions
31 lines (22 loc) · 1.03 KB
/
Copy pathreadSerial.py
File metadata and controls
31 lines (22 loc) · 1.03 KB
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
# Receives a string from Arduino using readline()
# Requires PySerial
# (c) www.xanthium.in 2021
# Rahul.S
import serial
import time
SerialObj = serial.Serial('/dev/ttyACM0',9600) # COMxx format on Windows
# /dev/ttyUSBx format on Linux
#
# Eg /dev/ttyUSB0
# SerialObj = serial.Serial('/dev/ttyUSB0')
time.sleep(3) # Only needed for Arduino,For AVR/PIC/MSP430 & other Micros not needed
# opening the serial port from Python will reset the Arduino.
# Both Arduino and Python code are sharing Com11 here.
# 3 second delay allows the Arduino to settle down.
while True:
SerialObj.timeout = 3 # set the Read Timeout
ReceivedString = SerialObj.readline() #readline reads a string terminated by \n
print(ReceivedString)
with open('readme.txt', 'a') as f:
f.writelines(ReceivedString)
SerialObj.close() # Close the port