Processing IDE code not working(not receiving data from arduino)

Without checking what the Arduino is doing it is impossible to tell, and the last time you posted the Arduino end it was far from working.

What is sure is that Processing is still expecting one of two data sets.

Also what makes you think that data.substring(7) is going to recover the data you are expecting? All this does is create a string which is the first seven characters of the message. Well the 7 first characters of the message is "Angle: ", which as Processing correctly tells you is Not A Number.

The substring you have to create needs to start at 7 and then cover all the numbers in that message. Then you have the problem of further parsing a string of comer separated numbers into individual values.

Again the print statement will help you look at what you are actually getting.

1 Like

the arduino is giving me this result which is perfectly when i move sensor the angle and h_dot changing

sorry for image

to make sure that arduino printing on serial i modify code usin these lines

 // Print the data being sent
 String data = "Angle: " + String(angleZ) + ", h_dot: " + String(h_dot, 2);
 Serial.println("Data sent: " + data);

Are you actually reading my replies?

The print statement I was referring to is the use of a print statement in the serialEvent function.

very much confused

some changes in arduino code i did please than now in processing i get this , apologize for picture

import processing.serial.*;

Serial port;
float angle;
float h_dot;
void setup() {
  size(400, 300);
  printArray(Serial.list());  // Print available serial ports in the console
  port = new Serial(this, "COM5", 9600);  // Replace "COM5" with the appropriate port name
  port.bufferUntil('\n');  // Set the character to buffer until newline
}

void draw() {
  background(255);
  
  // Draw X-axis
  stroke(0);
  line(50, height/2, width-50, height/2);
  fill(0);
  textAlign(CENTER, CENTER);
  text("Angle", width/2, height/2 + 30);
  
  // Draw Y-axis
  stroke(0);
  line(width/2, 50, width/2, height-50);
  fill(0);
  textAlign(CENTER, CENTER);
  text("h_dot", width/2 + 30, height/2);
  
  // Draw angle value
  fill(255, 0, 0);
  textAlign(CENTER, TOP);
  text(angle, width/2, height/2 + 50);
  
  // Draw h_dot value
  fill(0, 0, 255);
  textAlign(RIGHT, CENTER);
  text(h_dot, width/2 - 50, height/2);
}


void serialEvent(Serial port) {
  String data = port.readStringUntil('\n');  // Read the received data until newline character
  if (data != null) {
    data = data.trim();
    println("Data received: " + data);
  }
}

Capture

OK so what you have to do is to parse the data out of the string you received into real numbers so you can use them to change the Processing display.

parsing done

Capture

now next step is to work on display ??? , the expecting display should be like this

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.