Aparna B
Aparna B

Reputation: 163

how to store serial data sent by arduino as buffer and print in processing?

I have written a code in arduino which sends string of data Arduino code lines:

 int analog_value = analogRead(A0);//reading forward voltage
  int analog_valuer = analogRead(A1);//reading reverse voltage
 fwd_voltage = (analog_value * 5.0) / 1024.0; 
  rev_voltage = (analog_valuer * 5.0) / 1024.0;
 fpower =  ((fwd_voltage)*(fwd_voltage)*10000);
rpower = ((rev_voltage)*(rev_voltage)*10000);
String fp = String(fpower);
String rp =String(rpower);

 Serial.println("REV");
 Serial.println(rp);
Serial.println("W \n");
Serial.println("FWD");

 Serial.println(fp);
 Serial.println("W");

I want to print the data in processing console like this

REV [some value] W

FWD [some value] W

This is my processing code

void serialEvent(Serial myPort) {
while(port.available()>0){
val = port.readString();
 }
if (val!=null)
{
 println(val);

 }

 }

Upvotes: 0

Views: 1552

Answers (1)

George Profenza
George Profenza

Reputation: 51837

You can start with the Processing Serial library and the serialEvent() example. This shows you how to buffer a string of characters until the LineFeed(\n) character is received.

From there you should able to parse (trim, split, etc.) the string received over serial and extract the rp/fp values as needed.

Upvotes: 2

Related Questions