I am using an arduino uno and a thermistor to measure the current temperature. I have been using re.findall to find the matching string in line 4, is there an alternative instead of using re.findall that has the same function? as I am not allowed to use re in my project. Thanks
def my_function(port):
# Set COM Port.....
ser = serial.Serial(port, 9600, timeout=0,
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, rtscts=0)
my_function('COM3')
# Set path to my Arduino device
# portPath = my_function
baud = 9600
sample_time = 1 # Takes temperature every 1 second
sim_time = 1 # Graphs 5 data points
# Initializing Lists
# Data Collection
data_log = []
line_data = []
# Establishing Serial Connection
connection = serial.Serial("com3", baud)
# Calculating the length of data to collect based on the
# sample time and simulation time (set by user)
max_length = sim_time / sample_time
# Collecting the data from the serial port
while True:
line = connection.readline()
line_data = re.findall('\d*\.\d*', str(line))
line_data = filter(None, line_data)
line_data = [float(x) for x in line_data]
line_data = [(x - 32) * 0.5556 for x in line_data] # list comprehension to convert line_data temp to celsius
line_data = [round(elem, 2) for elem in line_data] # round temp to 2 dp
if len(line_data) > 0:
print("The current temperature is:" + str(line_data[0]) + " celsius")
break