简体   繁体   English

将无穷循环EKG数据另存为.txt文件

[英]Saving endless loop EKG data as .txt file

I am using Olimex EKG Shield with Arduino Uno. 我正在将Olimex EKG Shield与Arduino Uno一起使用。

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);

}

With this code provided here, I am getting a voltage value from 0-5V. 使用此处提供的代码,我得到的电压值为0-5V。 Since its a loop, the data keep shows in the serial monitor until it is disconnected. 由于循环,数据保持显示在串行监视器中,直到断开连接为止。

So, what I am trying to do is that measure ECG for a certain amount of time (let's say 5 min) or data points (let's say a million points), and then save this data into a .txt file. 因此,我想做的是测量一定时间(例如5分钟)或数据点(例如一百万点)的ECG,然后将这些数据保存到.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(); 
  }

I found this processing code that imports data from Arduino serial monitor and saves as a .txt file, but it doesn's work somehow. 我发现此处理代码从Arduino串行监视器导入数据并将其另存为.txt文件,但它以某种方式无法工作。

I think I need to make some change to the code on Arduino side and also on Processing side. 我想我需要在Arduino端和处理端对代码进行一些更改。

If anyone can help with me, I would really appreciate. 如果有人可以帮助我,我将不胜感激。

Thank you. 谢谢。

You need to be more specific than saying "it doesn't work somehow" - we have no idea what that means. 您需要比说“以某种方式不起作用”更具体-我们不知道这意味着什么。 What exactly did you expect this code to do? 您究竟期望该代码执行什么操作? What exactly does it do instead? 相反,它到底是做什么的?

You also need to split this up into smaller problems . 您还需要将其分解为较小的问题

  • Can you create a simple example program that simply sends the values to Processing? 您可以创建一个简单的示例程序,将值简单地发送到Processing吗? Just print them to the console for now. 暂时将它们打印到控制台。
  • Can you create a separate example program that stores values in a text file? 您可以创建一个单独的示例程序来将值存储在文本文件中吗? Just use hard-coded values or random values for now- don't worry about the arduino yet. 现在就使用硬编码值或随机值-不必担心arduino。

When you have both of those working perfectly, then you can think about combining them into one program that does both: sends values from the arduino and saves those values to a text file. 当这两个功能都可以正常工作时,您可以考虑将它们组合到一个可以同时完成这两个功能的程序中:从arduino发送值并将这些值保存到文本文件中。

You can't just "find code" and expect it to work. 您不能只是“查找代码”并期望它能工作。 You have to break your problem down and then approach each individual step by itself. 您必须分解问题,然后自己逐步解决每个步骤。 Then if you get stuck on a specific step, you can post a MCVE and we can go from there. 然后,如果您陷于特定步骤,则可以发布MCVE ,我们可以从那里开始。 Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM