When I run These Code (I got from The Bored Robot In youtube) for import output from arduino IDE to plot. It’s not respond, It’s just show only white fleeze window.
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
def handle_missing_data(data):
ser = serial.Serial(SERIAL_PORT, BAUD_RATE)
def read_and_process_data():
line = ser.readline().decode('utf-8').strip()
sensorValues = line.split(', ')
time_value = handle_missing_data(sensorValues[0])
celsius_value = handle_missing_data(sensorValues[1])
fahrenheit_value = handle_missing_data(sensorValues[2])
x_vals.append(time_value)
celsius_data.append(celsius_value)
fahrenheit_data.append(fahrenheit_value)
print(f'Time: {time_value}, Celsius: {celsius_value}, Fahrenheit: {fahrenheit_value}')
plt.plot(x_vals, celsius_data, label='Celsius')
plt.plot(x_vals, fahrenheit_data, label='Fahrenheit')
plt.ylabel('Temperature')
with open('sensor_data.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Time', 'Celsius', 'Fahrenheit'])
for x, c, f in zip(x_vals, celsius_data, fahrenheit_data):
writer.writerow([x, c, f])
fig.canvas.mpl_connect('close_event', on_close)
ani = FuncAnimation(fig, update_plot, interval=10)
<code>import serial
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import csv
plt.show(block=True)
SERIAL_PORT = 'COM3'
BAUD_RATE = 9600
def handle_missing_data(data):
try:
return float(data)
except ValueError:
return 0.0
ser = serial.Serial(SERIAL_PORT, BAUD_RATE)
x_vals = []
celsius_data = []
fahrenheit_data = []
def read_and_process_data():
line = ser.readline().decode('utf-8').strip()
sensorValues = line.split(', ')
time_value = handle_missing_data(sensorValues[0])
celsius_value = handle_missing_data(sensorValues[1])
fahrenheit_value = handle_missing_data(sensorValues[2])
x_vals.append(time_value)
celsius_data.append(celsius_value)
fahrenheit_data.append(fahrenheit_value)
print(f'Time: {time_value}, Celsius: {celsius_value}, Fahrenheit: {fahrenheit_value}')
def update_plot(frame):
read_and_process_data()
plt.cla()
plt.plot(x_vals, celsius_data, label='Celsius')
plt.plot(x_vals, fahrenheit_data, label='Fahrenheit')
plt.xlabel('Time')
plt.ylabel('Temperature')
plt.legend()
def on_close(event):
with open('sensor_data.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Time', 'Celsius', 'Fahrenheit'])
for x, c, f in zip(x_vals, celsius_data, fahrenheit_data):
writer.writerow([x, c, f])
fig, ax = plt.subplots()
fig.canvas.mpl_connect('close_event', on_close)
ani = FuncAnimation(fig, update_plot, interval=10)
plt.show()
</code>
import serial
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import csv
plt.show(block=True)
SERIAL_PORT = 'COM3'
BAUD_RATE = 9600
def handle_missing_data(data):
try:
return float(data)
except ValueError:
return 0.0
ser = serial.Serial(SERIAL_PORT, BAUD_RATE)
x_vals = []
celsius_data = []
fahrenheit_data = []
def read_and_process_data():
line = ser.readline().decode('utf-8').strip()
sensorValues = line.split(', ')
time_value = handle_missing_data(sensorValues[0])
celsius_value = handle_missing_data(sensorValues[1])
fahrenheit_value = handle_missing_data(sensorValues[2])
x_vals.append(time_value)
celsius_data.append(celsius_value)
fahrenheit_data.append(fahrenheit_value)
print(f'Time: {time_value}, Celsius: {celsius_value}, Fahrenheit: {fahrenheit_value}')
def update_plot(frame):
read_and_process_data()
plt.cla()
plt.plot(x_vals, celsius_data, label='Celsius')
plt.plot(x_vals, fahrenheit_data, label='Fahrenheit')
plt.xlabel('Time')
plt.ylabel('Temperature')
plt.legend()
def on_close(event):
with open('sensor_data.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Time', 'Celsius', 'Fahrenheit'])
for x, c, f in zip(x_vals, celsius_data, fahrenheit_data):
writer.writerow([x, c, f])
fig, ax = plt.subplots()
fig.canvas.mpl_connect('close_event', on_close)
ani = FuncAnimation(fig, update_plot, interval=10)
plt.show()
And this is code in Arduino IDE
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
Serial.println("Adafruit MLX90614 test");
Serial.print("Ambient = ");
Serial.print(mlx.readAmbientTempC());
Serial.print("*CtObject = ");
Serial.print(mlx.readObjectTempC()); Serial.println("*C");
Serial.print("Ambient = ");
Serial.print(mlx.readAmbientTempF());
Serial.print("*FtObject = ");
Serial.print(mlx.readObjectTempF()); Serial.println("*F");
<code>#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
void setup() {
Serial.begin(9600);
Serial.println("Adafruit MLX90614 test");
mlx.begin();
}
void loop() {
Serial.print("Ambient = ");
Serial.print(mlx.readAmbientTempC());
Serial.print("*CtObject = ");
Serial.print(mlx.readObjectTempC()); Serial.println("*C");
Serial.print("Ambient = ");
Serial.print(mlx.readAmbientTempF());
Serial.print("*FtObject = ");
Serial.print(mlx.readObjectTempF()); Serial.println("*F");
Serial.println();
delay(500);
}
</code>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
void setup() {
Serial.begin(9600);
Serial.println("Adafruit MLX90614 test");
mlx.begin();
}
void loop() {
Serial.print("Ambient = ");
Serial.print(mlx.readAmbientTempC());
Serial.print("*CtObject = ");
Serial.print(mlx.readObjectTempC()); Serial.println("*C");
Serial.print("Ambient = ");
Serial.print(mlx.readAmbientTempF());
Serial.print("*FtObject = ");
Serial.print(mlx.readObjectTempF()); Serial.println("*F");
Serial.println();
delay(500);
}
enter image description here
Help me to fix it, I need to finished it
And after I run it in Arduino IDE told me A fatal esptool.py error occurred: could not open port ‘COM3’: PermissionError(13, ‘Access is denied.’, None, 5)esptool.py v3.0
Serial port COM3