2017-03-03 130 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,我们可以从那里开始。祝你好运。