2017-03-03 55 views
0

我正在使用Olimex EKG Shield與Arduino Uno。將無限循環EKG數據保存爲.txt文件

void setup() { 
    // put your setup code here, to run once: 
    // initialize serial communication at 9600 bits per second: 
    Serial.begin(115200); 

} 

void loop() { 
    // put your main code here, to run repeatedly: 
    // read the input on analog pin 0: 
    int sensorValue = analogRead(A0); 
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): 
    float value = sensorValue * (5.0/1023.0); 
    // print out the value you read: 
    Serial.println(value); 

} 

有了此處提供的代碼,我正在從0-5V電壓值。 由於它是一個循環,數據保持在串行監視器中顯示,直到斷開連接。因此,我想要做的是測量一段時間的ECG(比方說5分鐘)或數據點(比方說100萬分),然後將這些數據保存到.txt文件中。

//From Arduino to Processing to Txt or cvs etc. 
//import 
import processing.serial.*; 
//declare 
PrintWriter output; 
Serial udSerial; 

void setup() { 
    udSerial = new Serial(this, Serial.list()[0], 115200); 
    output = createWriter ("data.txt"); 
} 

    void draw() { 
    if (udSerial.available() > 0) { 
     String SenVal = udSerial.readString(); 
     if (SenVal != null) { 
     output.println(SenVal); 
     } 
    } 
    } 

    void keyPressed(){ 
    output.flush(); 
    output.close(); 
    exit(); 
    } 

我發現,從Arduino的串口監聽進口數據並保存爲.txt文件該處理的代碼,但它不不知何故工作。

我想我需要對Arduino方面和處理方面的代碼進行一些更改。

如果有人能幫助我,我會很感激。

謝謝。

回答

0

您需要比說「它不能工作」更具體 - 我們不知道這意味着什麼。你期望這個代碼做什麼?它究竟做了什麼呢?您也需要split this up into smaller problems

  • 您可以創建一個簡單的示例程序,只需將值發送到Processing?現在只需將它們打印到控制檯。
  • 您可以創建一個單獨的示例程序來存儲文本文件中的值嗎?現在只需使用硬編碼值或隨機值 - 不用擔心arduino。

當你有兩個完美的工作,那麼你可以考慮將它們組合成一個程序,它同時執行以下操作:從arduino發送值並將這些值保存到文本文件。

你不能只是「找到代碼」,並期望它的工作。你必須打破你的問題,然後逐步接近每一步。然後,如果您遇到特定的步驟,您可以發佈MCVE,我們可以從那裏開始。祝你好運。