Browse Source

provide loggingh

Tobias Simetsreiter 3 năm trước cách đây
mục cha
commit
61eb3d464e
2 tập tin đã thay đổi với 33 bổ sung15 xóa
  1. 6 2
      main.ino
  2. 27 13
      plot.py

+ 6 - 2
main.ino

@@ -51,7 +51,7 @@ void setup() {
     // .onPress( led1, led1.EVT_TOGGLE );
 
   
-  dial.begin(dial_pin_1, dial_pin_2)
+  dial.begin(dial_pin_1, dial_pin_2, 1)
     .range( 1, 120 )
     .onChange( [] (int idx, int v, int up ) {
       shouldTemp = (float)v;
@@ -125,13 +125,17 @@ void wpsSetup(){
   }
 }
 
+unsigned long lastCheck;
 void checkTemp(){
   if (isTemp < shouldTemp){
     led1.on();
   } else {
     led1.off();
   }
-  Serial.printf("%10d,%.10f,%.10f\n", millis(),shouldTemp,isTemp);
+  if ((millis() - lastCheck) > 1000) {
+    Serial.printf("%d,%.10f,%.10f\n", millis(),shouldTemp,isTemp);
+    lastCheck = millis();
+  }
 }
 
 String boolToString(bool in){

+ 27 - 13
plot.py

@@ -9,7 +9,8 @@ import serial
 
 #initialize serial port
 ser = serial.Serial()
-ser.port = '/dev/ttyS3' #Arduino serial port
+ser.port = "COM3"
+# ser.port = '/dev/ttyS2' #Arduino serial port
 ser.baudrate = 115200
 ser.timeout = 10 #specify timeout when using readline()
 ser.open()
@@ -20,25 +21,38 @@ if ser.is_open==True:
 # Create figure for plotting
 fig = plt.figure()
 ax = fig.add_subplot(1, 1, 1)
-xs = [] #store trials here (n)
-ys = [] #store relative frequency here
-rs = [] #for theoretical probability
+xs = [] # time 
+ys = [] # shoult temp
+rs = [] # is temp
 
 # This function is called periodically from FuncAnimation
+last_i = 1
 def animate(i, xs, ys):
+    global last_i
 
     #Aquire and parse data from serial port
-    line=ser.readline()      #ascii
+    line=ser.readline()     #ascii
+    try:
+        line.decode()
+    except:
+        return
+
     line_as_list = line.split(b',')
-    i = int(line_as_list[0])
-    relProb = line_as_list[1]
-    relProb_as_list = relProb.split(b'\n')
-    relProb_float = float(relProb_as_list[0])
+    i = int(line_as_list[0].strip())
+
+    if (i-last_i) < 1000:
+        return
+        
+    print(line.decode().strip())
+
+    last_i = i
+    should_float = float(line_as_list[1].strip())
+    is_float = float(line_as_list[2].strip())
 	
 	# Add x and y to lists
     xs.append(i)
-    ys.append(relProb_float)
-    rs.append(0.5)
+    ys.append(should_float)
+    rs.append(is_float)
 
     # Limit x and y lists to 20 items
     #xs = xs[-20:]
@@ -55,9 +69,9 @@ def animate(i, xs, ys):
     plt.title('This is how I roll...')
     plt.ylabel('Relative frequency')
     plt.legend()
-    plt.axis([1, None, 0, 1.1]) #Use for arbitrary number of trials
+    plt.axis([None, None, 0, 120]) #Use for arbitrary number of trials
     #plt.axis([1, 100, 0, 1.1]) #Use for 100 trial demo
 
 # Set up plot to call animate() function periodically
-ani = animation.FuncAnimation(fig, animate, fargs=(xs, ys), interval=1000)
+ani = animation.FuncAnimation(fig, animate, fargs=(xs, ys))
 plt.show()