Hi everyone
I'm trying to create a program that has an Arduino and JME sending data back and forth. The Arduino is supposed to send data to the computer, which interprets it and sends back a value for a servo on the Arduino. It’s basically simulating a servo rotating that matches the servo rotation in real life. The servo’s rotation is based on force-sensitive resistors. The data transfer is like so:
Value of FSR is sent to Java program from Arduino ---> Java program calculates value for servo ---> value for servo is sent to arduino ---> value is written to servo.
The values are being written to the virtual servo correctly, which I think rules out a problem in the Java program or in the initial data transfer of the FSR data. So there is probably a problem with the data being sent back to the Arduino.
I think this is the Arduino code that is causing the problem:
if (abs(servoval) >= 360)servoval = 0;
Serial.println(servoval);
servoval = ((float)Serial.read())/100;
myservo.write(servoval);
When this code is implemented, only the change in the servo value is written to the servo. This leads me to the conclusion that there is a disconnection between the cycles per second of the Arduino and the computer running the Java code.
I’m honestly not sure, and any input is welcomed.
Thanks.