-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
calibrate example for Servo #49
base: master
Are you sure you want to change the base?
calibrate example for Servo #49
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is essentially a duplicate of #44
Please add a comment to the top of the sketch that explains the purpose of the sketch and the required circuit. Check the existing examples of this repository to see the format the comment should follow. DONE
Please do a Tools > Auto Format if using the Arduino IDE or Ctrl + B if using the Arduino Web Editor to make the formatting of your sketch match that of the other official example sketches. DONE
|
||
void loop() { | ||
if (Serial.available() > 0) { | ||
input = Serial.parseInt(); // reads the value from Serial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the line ending menu of Serial Monitor set to anything other than "No line ending", there is an issue. For example, if I enter 42 in the Serial Monitor input field, I get this output:
Servo set to 42 degree
Servo set to 0 degree
"Newline" is the default setting of this menu, so it's likely many users will encounter this problem.
The easiest solution would be to document the required line ending setting. Of course, many users won't read the directions, so they will still have the problem.
There is also the issue of the 1 s delay before the input takes effect. Not a huge issue, but it doesn't provide a very responsive feeling to the interface.
I explained the cause and described the fix for these issues here: #44 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok ill look into your suggestions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@per1234 should I mention in the document to use no line ending or should I try improvising code to work for newline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue still occurs with the line ending menu set to "Both NL & CR". DONE
The reason is because serial communication is relatively slow. Serial.parseInt()
returns as soon as it encounters a non-digit. So when Serial.parseInt()
returns the NL has already been received, but the CR has not. The "remove the line endings" code you added removes the NL, then Serial.available()
returns 0 so the while
loop exits. On the next time through the loop
function the CR is in the receive buffer, so Serial.parseInt()
returns 0 (because that's what it does when it doesn't encounter any digits).
The solution is to add a short delay before the "remove the line endings" code to allow the CR to be received, as I demonstrated in #44 (comment).
Ok this updated code integrates all the changes you requested |
You haven't done the auto format.
There was no change to the code. You only made the suggested changes to the comments (thanks!). |
auto format done 👍 |
|
||
void loop() { | ||
if (Serial.available() > 0) { | ||
input = Serial.parseInt(); // reads the value from Serial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue still occurs with the line ending menu set to "Both NL & CR". DONE
The reason is because serial communication is relatively slow. Serial.parseInt()
returns as soon as it encounters a non-digit. So when Serial.parseInt()
returns the NL has already been received, but the CR has not. The "remove the line endings" code you added removes the NL, then Serial.available()
returns 0 so the while
loop exits. On the next time through the loop
function the CR is in the receive buffer, so Serial.parseInt()
returns 0 (because that's what it does when it doesn't encounter any digits).
The solution is to add a short delay before the "remove the line endings" code to allow the CR to be received, as I demonstrated in #44 (comment).
thanks, @per1234 for your suggestions. I have implemented fixes for newline and carriage return |
|
Calibrate Example for the Servo Motor.
User needs to input the angle to set from the serial Monitor.
Many times this situation arises when the user needs to set the servo to say 90 or 0 to fix it in the project. Instead of writing the code over and over again for this, this example will add to the User Experience and feasibility.
Consider this as my contribution to the Portenta Project.
I have already given my introduction in the issue tracker at #114
@alranel @agdl