Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

noob-master147
Copy link

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

Copy link
Contributor

@per1234 per1234 left a 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

examples/Calibrate/Calibrate.ino Outdated Show resolved Hide resolved
examples/Calibrate/Calibrate.ino Outdated Show resolved Hide resolved

void loop() {
if (Serial.available() > 0) {
input = Serial.parseInt(); // reads the value from Serial
Copy link
Contributor

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)

Copy link
Author

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

Copy link
Author

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?

Copy link
Contributor

@per1234 per1234 Mar 25, 2020

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

@noob-master147
Copy link
Author

Ok this updated code integrates all the changes you requested
also, it will work on both: no line endings as well as Newline in the serial monitor.

@per1234
Copy link
Contributor

per1234 commented Mar 25, 2020

this updated code integrates all the changes you requested

You haven't done the auto format.

it will work on both: no line endings as well as Newline in the serial monitor.

There was no change to the code. You only made the suggested changes to the comments (thanks!).

@noob-master147
Copy link
Author

auto format done 👍
also, the code has been updated, you may check
sorry for before😅

examples/Calibrate/Calibrate.ino Outdated Show resolved Hide resolved

void loop() {
if (Serial.available() > 0) {
input = Serial.parseInt(); // reads the value from Serial
Copy link
Contributor

@per1234 per1234 Mar 25, 2020

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

examples/Calibrate/Calibrate.ino Outdated Show resolved Hide resolved
@noob-master147
Copy link
Author

thanks, @per1234 for your suggestions. I have implemented fixes for newline and carriage return

@per1234 per1234 dismissed their stale review March 26, 2020 06:05

Requested changes made. Thanks!

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@per1234 per1234 added type: enhancement Proposed improvement topic: documentation Related to documentation for the project labels Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: documentation Related to documentation for the project type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants