I am new to arduino and coding in general. I am trying to get a real time plot to graph the analog values from my arduino. Looking at several examples online I got some code that will try to pull up a graph but states 'str' does not support the buffer interface. Also when I open the arduino program to run on the COM3 port, the Python code says it cannot open port COM3.
Here is my Arduino Code
float Concentration=0;
int val = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
val = analogRead(3);
Concentration = log ((val)/486.771)/-3.478;
Serial.println(Concentration);
Serial.print("\n");
delay(100);
And here is my Python code
import serial
import numpy as np
from matplotlib import pyplot as plt
ser = serial.Serial('COM3', 9600)
plt.ion() # set plot to animated
ydata = [0] * 50
ax1=plt.axes()
# make plot
line, = plt.plot(ydata)
plt.ylim([100,400])
# start data collection
while True:
data = ser.readline().rstrip() # read data from serial
# port and strip line endings
if len(data.split(".")) == 2:
ymin = float(min(ydata))-10
ymax = float(max(ydata))+10
plt.ylim([ymin,ymax])
ydata.append(data)
del ydata[0]
line.set_xdata(np.arange(len(ydata)))
line.set_ydata(ydata) # update the data
plt.draw() # update the plot
plt.pause(3)