0

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

 }

 }

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

:I'll try. and do i need to change the way i write serial.println function in arduino for my desired output shown in question?
It totally depends on what you need out of that output. Currently, yes it looks like you do need to change the calls in Arduino if you want REV [some value] W to be output for example to something like: Serial.print("REV"); Serial.print(rp); Serial.println("W \n"); (e.g. output a new line only when you need it). Give it a go, it might not be as complex as you think :)
OK thanks. also I've seen the examples you suggested. I'll just try .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.