diff --git a/DopplerSignal/DopplerSignal.ino b/DopplerSignal/DopplerSignal.ino index 356288e..b392519 100644 --- a/DopplerSignal/DopplerSignal.ino +++ b/DopplerSignal/DopplerSignal.ino @@ -2,29 +2,45 @@ const int DOPPLER_0_PIN = A0; const int DOPPLER_1_PIN = A1; -const int MEAN_SIZE = 10; +// const int MEAN_SIZE = 10; int gDoppler0 = 0; // value read from the doppler 0 int gDoppler1 = 0; // value read from the doppler 1 -int gSum0 = 0; -int gSum1 = 0; +// int gSum0 = 0; +// int gSum1 = 0; +struct repeating_timer st_timer; + +/* タイマー割り込み処理 */ +bool Timer(struct repeating_timer *t) { + gDoppler0 = analogRead(DOPPLER_0_PIN); + gDoppler1 = analogRead(DOPPLER_1_PIN); + + Serial.print(millis()); + Serial.print(","); + Serial.print(gDoppler0); + Serial.print(","); + Serial.println(gDoppler1); + + return true; +} void setup() { Serial.begin(115200); + add_repeating_timer_us(-10000, Timer, NULL, &st_timer); } void loop() { - gSum0 = 0; - gSum1 = 0; - for (int i = 0; i < MEAN_SIZE; i++){ - gDoppler0 = analogRead(DOPPLER_0_PIN); - gDoppler1 = analogRead(DOPPLER_1_PIN); - gSum0 += gDoppler0; - gSum1 += gDoppler1; - delay(1); - } + // gSum0 = 0; + // gSum1 = 0; + // for (int i = 0; i < MEAN_SIZE; i++){ + // gDoppler0 = analogRead(DOPPLER_0_PIN); + // gDoppler1 = analogRead(DOPPLER_1_PIN); + // gSum0 += gDoppler0; + // gSum1 += gDoppler1; + // delay(1); + // } - // print the results to the Serial Monitor: - Serial.print((float)gSum0 / MEAN_SIZE); - Serial.print(","); - Serial.println((float)gSum1 / MEAN_SIZE); + // // print the results to the Serial Monitor: + // Serial.print((float)gSum0 / MEAN_SIZE); + // Serial.print(","); + // Serial.println((float)gSum1 / MEAN_SIZE); } diff --git a/measurement.py b/measurement.py index ae84053..ca7162a 100644 --- a/measurement.py +++ b/measurement.py @@ -86,7 +86,7 @@ def __init__(self, out_filename, port): super().__init__(out_filename) self._serial = serial.Serial(port, 115200, timeout=1) - self._cols = 3 + self._cols = 4 print("Seiral port connected on ", port) def preprocess(self): @@ -95,13 +95,13 @@ def read(self): if not self._serial.is_open: - return [0, 0] + return [0, 0, 0] line = self._serial.readline() if not line: - return [0, 0] + return [0, 0, 0] line2 = line.decode("utf-8").strip() if line2 == "": - return [0, 0] + return [0, 0, 0] return [float(_) for _ in line2.split(",")] def postprocess(self): @@ -123,7 +123,7 @@ # Wait for stop print("measurement start.") - recode_dulation = 15 # sec + recode_dulation = 3 # sec for i in range(recode_dulation): time.sleep(1) print(i + 1, "/", recode_dulation, "sec") @@ -155,7 +155,7 @@ combind, delimiter=",", fmt="%.3f", - header="time(s),IF-I,IF-Q,RespBelt", + header="time(s),device time(ms),IF-I,IF-Q,RespBelt", ) print("Recoding data was saved to ", filename) # print(combind)