0

I am using Olimex EKG Shield with 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. 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.

 //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.

I think I need to make some change to the code on Arduino side and also on Processing side.

If anyone can help with me, I would really appreciate.

Thank you.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107

1 Answers1

0

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? 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.

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.

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. Good luck.

Community
  • 1
  • 1
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107