Ok ya se lo muestro estés es el de Arduino aquí solo está lee la señales
void setup(){
Serial.begin(9600);//Inicialice la comunicación serial a 9600 bits por segundo:
}
void loop(){
int sensorValue = analogRead(A0); //Leer los electrodos
// lectura analógica (que va de 0 - 1023) a un voltaje (0 - 5V)
//float voltage = sensorValue * (100.0 / 1023.0);
//Enviar las lecturas filtradas por Serial
Serial.println(sensorValue); //Enviar las lecturas filtradas por Serial
delay(100);
}
Aquí está el de python
%matplotlib notebook
#
http://pyserial.readthedocs.org/en/latest/pyserial_api.htmlimport serial
import numpy as np
import xlsxwriter
from matplotlib import pyplot as plt
from time import time
# dando la ruta específica para guardar los datos en excel
workbook = xlsxwriter.Workbook('C:/Users/water/OneDrive/Documentos/MATLAB/proyecto/SENSORMIOELECTRICO1/TOMA DE DATOS/prebadepythonexcel.xlsx')
worksheet = workbook.add_worksheet()
ser = serial.Serial('COM5', 9600)
# configurado trama para animar
plt.ion()
start_time = time()
timepoints = []
ydata = []
yrange = [4.5,6.1]
view_time =2 # segundos de datos para ver a la vez
duration = 25 # segundos totales para recopilar datos
fig1 = plt.figure()
#
http://matplotlib.org/users/text_props.htmlfig1.suptitle('live updated data', fontsize='18', fontweight='bold')
plt.xlabel('time, seconds', fontsize='14', fontstyle='italic')
plt.ylabel('potential, volts', fontsize='14', fontstyle='italic')
plt.axes().grid(True)
#line1, = plt.plot(ydata,marker='o',markersize=4,linestyle='none',markerfacecolor='red')
line1, = plt.plot(timepoints, ydata,'b-')
plt.ylim(yrange)
plt.xlim([0,view_time])
# vaciar cualquier basura que quede en el búfer serial
ser.flushInput()
run = True
# collect the data and plot a moving frame
while run:
ser.reset_input_buffer()
data = ser.readline()#.split(' ')
# sometimes the incoming data is garbage, so just 'try' to do this
try:
# almacenar el conjunto de datos completo para más tarde.
ydata.append(float(data[0])*100.0/1023.0)
timepoints.append(time()-start_time)
current_time = timepoints[-1]
# actualizar los datos trazados.
line1.set_xdata(timepoints)
line1.set_ydata(ydata)
#print (data)
print (ydata)
# guarda los datos en una hoja de excel
worksheet.write_row(
"A1:A100",
ydata
)
# deslice el marco de visualización a lo largo.
if current_time > view_time:
plt.xlim([current_time-view_time,current_time])
# cuando se acabe el tiempo, mata el ciclo de recolección + trazado.
if timepoints[-1] > duration: run=False
# si la instrucción try produce un error, simplemente no haga nada
except: pass
# actualizar la trama
fig1.canvas.draw()
# traza todos los datos que has recopilado
fig2 = plt.figure()
#
http://matplotlib.org/users/text_props.htmlfig2.suptitle('complete data trace', fontsize='18', fontweight='bold')
plt.xlabel('time, seconds', fontsize='14', fontstyle='italic')
plt.ylabel('potential, volts', fontsize='14', fontstyle='italic')
plt.axes().grid(True)
#plt.plot(timepoints, ydata,marker='o',markersize=4,linestyle='none',markerfacecolor='red')
plt.plot(timepoints, ydata,'b-')
plt.ylim(yrange)
fig2.show()
ser.close()
workbook.close()