plot - Python ser.readline() not reading incoming data from arduino via usb -
first time posting here apologize if posted incorrectly.
so i'm trying make digital stethoscope , plot data live via python. have stethoscope mic shoved inside hooked breadboard mic test circuit. goes arduino sends data via usb laptop. python code can display incoming data live awesome. problem when tap on stethoscope, incoming data should change. if i'm displaying serial data via arduino or minicom, data change when hit stethoscope. when @ python plot data doesn't change , can't figure out why. here code;
arduino
int sensorvalue = 0; //value read pot void setup() { //init serial communications @ 115200 bps; serial.begin(9600); } void loop() { //read a0 sensorvalue = analogread(a0); //serial.write(sensorvalue); //serial.print("the voltage is: "); serial.println(sensorvalue); //serial.println("v"); }
python
import serial import numpy np import matplotlib.pyplot plt drawnow import * voltarray = [] count = 0 arduinodata = serial.serial('/dev/ttyacm0',9600) plt.ion() def makefig(): plt.title('stethascope data') plt.plot(voltarray,'bo-') plt.grid(true) plt.ylabel('voltage (v)') plt.ylim(0,5) while true: while (arduinodata.inwaiting()==0): #wait here until there data pass #do nothing arduinostring = arduinodata.readline() print arduinostring try: volt = float(arduinostring) except valueerror: # pass print 'valueerror' print 'pin value: ', volt volt = volt*(5.0/1024.0) #arduino reads 0-5v, 10bit resolution #2^10 = 1024, arduino outputs 0-1023 print 'voltage: ', volt voltarray.append(volt) #append volt value array drawnow(makefig) count = count + 1 if (count > 50): voltarray.pop(0) print 'end loop' print
anybody have ideas?
Comments
Post a Comment