How to get the result from Arduino (which use Processing 3), and put that in .txt?

edited March 2017 in Arduino

Hi, I'm a university student. I'm trying to get my degree with doing my thesis. I'm still trying to understand the Arduino's code and the Processing 3's code.

Right now I'm trying to understand it using the heart pulse code. I want to take the result to a .txt so that I can process the result to get a better result. For example, the heart rate will be around 70-80 for 2 minutes and the result that came out will be "You are resting, the average heart pulse is 66-82bpm".

Please help me... thanks

Answers

  • What have you tried so far? Can you provide you heart pulse code, both for processing and arduino? Your question is that you want to save the data from an arduino device? Or you want to read some data and then output that you are "resting, your bpm is ..." or you want to do those two operations live from an arduino unit?

    Kf

  • This is the arduino code

    /* Pulse Sensor Amped 1.5 by Joel Murphy and Yury Gitman http://www.pulsesensor.com

    ---------------------- Notes ---------------------- ---------------------- This code: 1) Blinks an LED to User's Live Heartbeat PIN 13 2) Fades an LED to User's Live HeartBeat PIN 5 3) Determines BPM 4) Prints All of the Above to Serial

    Read Me: https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino/blob/master/README.md ---------------------- ---------------------- ---------------------- */

    define PROCESSING_VISUALIZER 1

    define SERIAL_PLOTTER 2

    // Variables int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0 int blinkPin = 13; // pin to blink led at each beat int fadePin = 5; // pin to do fancy classy fading blink at each beat int fadeRate = 0; // used to fade LED on with PWM on fadePin

    // Volatile Variables, used in the interrupt service routine! volatile int BPM; // int that holds raw Analog in 0. updated every 2mS volatile int Signal; // holds the incoming raw data volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded! volatile boolean Pulse = false; // "True" when User's live heartbeat is detected. "False" when not a "live beat". volatile boolean QS = false; // becomes true when Arduoino finds a beat.

    // SET THE SERIAL OUTPUT TYPE TO YOUR NEEDS // PROCESSING_VISUALIZER works with Pulse Sensor Processing Visualizer // https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer // SERIAL_PLOTTER outputs sensor data for viewing with the Arduino Serial Plotter // run the Serial Plotter at 115200 baud: Tools/Serial Plotter or Command+L static int outputType = PROCESSING_VISUALIZER; //SERIAL_PLOTTER;

    void setup(){ pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat! pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat! Serial.begin(115200); // we agree to talk fast! interruptSetup(); // sets up to read Pulse Sensor signal every 2mS // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE, // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN // analogReference(EXTERNAL); }

    // Where the Magic Happens void loop(){

    serialOutput() ;
    

    if (QS == true){ // A Heartbeat Was Found // BPM and IBI have been Determined // Quantified Self "QS" true when arduino finds a heartbeat fadeRate = 255; // Makes the LED Fade Effect Happen // Set 'fadeRate' Variable to 255 to fade LED with pulse serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial. QS = false; // reset the Quantified Self flag for next time }

    ledFadeToBeat(); // Makes the LED Fade Effect Happen delay(20); // take a break }

    void ledFadeToBeat(){ fadeRate -= 15; // set LED fade value fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers! analogWrite(fadePin,fadeRate); // fade LED }

    And this is the processing code

    /* Pulse Sensor Amped 1.5 by Joel Murphy and Yury Gitman http://www.pulsesensor.com

    ---------------------- Notes ---------------------- ---------------------- This code: 1) Blinks an LED to User's Live Heartbeat PIN 13 2) Fades an LED to User's Live HeartBeat PIN 5 3) Determines BPM 4) Prints All of the Above to Serial

    Read Me: https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino/blob/master/README.md ---------------------- ---------------------- ---------------------- */

    define PROCESSING_VISUALIZER 1

    define SERIAL_PLOTTER 2

    // Variables int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0 int blinkPin = 13; // pin to blink led at each beat int fadePin = 5; // pin to do fancy classy fading blink at each beat int fadeRate = 0; // used to fade LED on with PWM on fadePin

    // Volatile Variables, used in the interrupt service routine! volatile int BPM; // int that holds raw Analog in 0. updated every 2mS volatile int Signal; // holds the incoming raw data volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded! volatile boolean Pulse = false; // "True" when User's live heartbeat is detected. "False" when not a "live beat". volatile boolean QS = false; // becomes true when Arduoino finds a beat.

    // SET THE SERIAL OUTPUT TYPE TO YOUR NEEDS // PROCESSING_VISUALIZER works with Pulse Sensor Processing Visualizer // https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer // SERIAL_PLOTTER outputs sensor data for viewing with the Arduino Serial Plotter // run the Serial Plotter at 115200 baud: Tools/Serial Plotter or Command+L static int outputType = PROCESSING_VISUALIZER; //SERIAL_PLOTTER;

    void setup(){ pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat! pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat! Serial.begin(115200); // we agree to talk fast! interruptSetup(); // sets up to read Pulse Sensor signal every 2mS // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE, // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN // analogReference(EXTERNAL); }

    // Where the Magic Happens void loop(){

    serialOutput() ;
    

    if (QS == true){ // A Heartbeat Was Found // BPM and IBI have been Determined // Quantified Self "QS" true when arduino finds a heartbeat fadeRate = 255; // Makes the LED Fade Effect Happen // Set 'fadeRate' Variable to 255 to fade LED with pulse serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial. QS = false; // reset the Quantified Self flag for next time }

    ledFadeToBeat(); // Makes the LED Fade Effect Happen delay(20); // take a break }

    void ledFadeToBeat(){ fadeRate -= 15; // set LED fade value fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers! analogWrite(fadePin,fadeRate); // fade LED }

    Because this is real-time, I want it to show words on new window, like "Your BPM is xx-xx, that is the average human pulse for resting". something like that.. and i'm thinking that if i want to do that, meaning i have to save the result of the heart pulse in a file.

  • Format your code.
    Select your code and press ctrl + o to indent.
    Leave a line above and below.

Sign In or Register to comment.