Draw wave with serial data Using Processing

I aim to measure heart rates through the arduino using an infra red led and a IR phototransistor to detect the pulse in my finger. This creates a data list in the serial window. From there i need to transform the data into a visually identifiable wave form using processing, send the wave to Max/ Msp which can analyse the waves for peaks and troughs, and then control the speed of a captured sound file of waves crashing against the beach using the frequency of the heart beat. There is 10 days to do this. I am sort of hoping that its not quite as difficult as it sounds. I have discovered pachube. Any help or advice would be gold dust, thanks everyone.

From there i need to transform the data into a visually identifiable wave form using processing, send the wave to Max/ Msp which can analyse the waves for peaks and trough

What does "visually identifiable wave form" mean? How will you send this "visual" to Max/Msp?

Hi Paul, I dont know how i will send it as of yet but i am sure it can be done. The data collected from the heart rate monitor should be quite easily converted into a wave. The arduino captures the analogue input, and the serial monitor is set to its fastest rate, 115200 baud. here is the source code for the arduino patch so far.

int ledPin = 13; int sensorPin = 0;

double alpha = 0.75; int period = 20; double change = 0.0;

void setup() { pinMode(ledPin, OUTPUT); Serial.begin(115200); }

void loop() { static double oldValue = 0; static double oldChange = 0; int rawValue = analogRead(sensorPin); double value = alpha * oldValue + (1 - alpha) * rawValue;

Serial.print(rawValue); Serial.print(","); Serial.println(value);

oldValue = value; delay(period); }

Do you think getting Max Msp to communicate would be difficult? Would an Xml file be a valid solution or am i barking up the wrong tree altogether so to speak? Thanks for your response

this line of code is a smoothing function which makes the analogue signal more intelligible as a wave

double value = alpha * oldValue + (1 - alpha) * rawValue;

Hi Paul, I dont know how i will send it as of yet but i am sure it can be done.

I love optimism, but I think you need to temper it with a dose of reality.

You need to figure out what MaxMsp needs in order to do whatever it is you want it to do.

I aim to measure heart rates through the arduino using an infra red led and a IR phototransistor to detect the pulse in my finger.

Show the sketch that does this.

This creates a data list in the serial window.

Hard to know whether this is true, or not, without seeing any code.

From there i need to transform the data into a visually identifiable wave form using processing

Still have no idea what a "visually identifiable wave form" is. You can create a real-time plot of the input data (value vs. time) as an aid to visualizing the numbers.

send the wave to Max/ Msp which can analyse the waves for peaks and troughs

So, Processing needs to send something (it isn't clear what) to Max/Msp so that Max/Msp can do something that Processing could do.

and then control the speed of a captured sound file of waves crashing against the beach using the frequency of the heart beat.

Well, I'll admit that I think this is beyond the capabilities of Processing, but, it really seems like the Arduino could calculate the frequency, and send that to Max/Msp directly, and Processing could be eliminated from the picture altogether.

Heres a few posts I have found to help me with the processing/ arduino side of things.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1233536778
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286747908

i’ve also been looking at jitter tutorial 28 which looks at tracking msp sound waves amplitudes. Hopefully i’m going down the right track with this

The sketch that measures heart rate is the one posted above, thanks

i have posted on the max msp forum and someone has said the same thing; no need for processing

This is a copy of the post, I am going to look into his suggestions now;

"nice project, it is more or less exactly what I did, although I used synthesis to create the waves instead of a .wav and using vbap to spatialize the sound. I'm not sure why you want to include processing and not take the whole thing into max though. just ask if you need more help "

thanks for responding

this is the arduino sketch

int ledPin = 13; int sensorPin = 0;

double alpha = 0.75; int period = 20; double change = 0.0;

void setup() { pinMode(ledPin, OUTPUT); Serial.begin(115200); }

void loop() { static double oldValue = 0; static double oldChange = 0; int rawValue = analogRead(sensorPin); double value = alpha * oldValue + (1 - alpha) * rawValue;

Serial.print(rawValue); Serial.print(","); Serial.println(value);

oldValue = value; delay(period); }

Where do change and oldChange get used? ledPin?

Why are some variables global and some static?

hey pin 13 the led pin was unnecessary as this is for a second patch which turns the pulse rate into a blinking led rather than a data stream in the serial interface. This program creates a data stream in the serial window like follows; 1023, 1023, 00 1023, 1023, 00 1023, 1023, 00 ..................... .......... ... which is part of the problem as the data out put is at its maximum all the time for some reason, light conditions dont seem to effect the photo transistor.

The book doesn't explain about the the static or global variables. I think it is definately something to do with how the data is displayed in the serial interface. I do know that the following is a smoothing operation to get rid of noise. from the wave produced.

double value = alpha * oldValue + (1 - alpha) * rawValue;

You are advised to take the data from the serial interface and past it into a spreadsheet in order to check it and reset the alpha value if necessary so you are picking up a steady heartbeat.

http://cycling74.com/forums/topic.php?id=29965&replies=9#post-148358

hey my circuit is set up here. Its a very simple circuit with a IR led and a IR photo transistor. Ive since removed the Led and the resistor as its unnecessary.there is only 1 data input to analogue A0.

I have made alot of progress since I last posted but am having some real issues. The max msp patch is not recognising the list i'm sending and i think its something to do with the delimiter (,) used in the serial data. What I am wondering is in the arduino sketch, does anyone know what the serial data for "value" and "raw value" represent in layman's terms. I dont think that the multislider object I am using in max/msp will be able to interpret it properly as doesnt use x, y axis. Am I right? forgive me if i'm wrong, for I know not lol Thanks Chris http://cycling74.com/forums/topic.php?id=29965&replies=18#post-148910

What I am wondering is in the arduino sketch, does anyone know what the serial data for "value" and "raw value" represent in layman's terms.

Without seeing the code, no.

Hey paul, the code is the sketch above on this thread. The link above your last post also shows the work ive been doing on the max/msp side of things, thanks I just deleted two of the data streams which were going to the serial interface. Wasnt really sure what the were doing. Max msp is only receiving the raw value now which seems to work although the heart beat is very subtle. It only varies over 3- 5 digits but does seem to be picking up a pulse