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

Servo movement #8

Closed
CrazyRobMiles opened this issue Jun 22, 2021 · 10 comments
Closed

Servo movement #8

CrazyRobMiles opened this issue Jun 22, 2021 · 10 comments

Comments

@CrazyRobMiles
Copy link
Contributor

The servo is only moving through half its range when on a Connected Little Box.

The ESP8266 servo example works fine, but when the same code runs inside the CLB software it only moves the servo through half its range. This is a new behaviour that has appeared recently.

@BNNorman
Copy link

Is it by design? Sounds like a pulse width/timing issue.

I assume you are referring to the Arduino servo example?

On my ESP8266 CLB V1.0.0.91 servo works and just flashed and tested V1.1.0.0 - is your servo broke?

@CrazyRobMiles
Copy link
Contributor Author

I've tried a couple of different servos and they all perform the same way. They move 180 degrees on the Arduino example and 90 degrees in the CLB. I've tried the Arduino code in the CLB code and it goes wrong, so I'm thinking I might be running ESP32 servo driver code on the ESP8266 for some reason. You might not be seeing this because I think (although I may be wrong) that you are building your code from scratch and might have the libraries installed properly. I'm going to wire up an ESP32 and have a play. I'm also going to make a brand new "empty" install by cloning the CLB code into a new folder and building from that.

@BNNorman
Copy link

Yep, I build my code from scratch. Every time.

@BNNorman
Copy link

On my NodeMCU (ESP32) the servo works fine using V1.0.0.95 and V1.1.0.0 - though its more like 170 degrees.

@CrazyRobMiles
Copy link
Contributor Author

I've just tested the code on an ESP32 and it works fine. It looks like they have changed the limits for the ESP8266 servo movement. It's mentioned here: esp8266/Arduino#8081

@CrazyRobMiles
Copy link
Contributor Author

Yep. It's all down to this: esp8266/Arduino#7023

I'd rather have the range of movement and run the risk of damage than restrict useful behaviour. I've changed the defaults back to the original ones so that ESP8266 and ESP32 now move in the same range.

Fixed.

@dok-net
Copy link

dok-net commented Jul 15, 2021

@CrazyRobMiles It seems from your post that your fix involved modifying the core sources, that's not what's needed. I hope you would agree that preventing damage first, then simply specifying the extended range for a given servo suits everyone.
So, please update your sketch or library to this overload of Servo::attach():

Servo myServo;
constexpr pin = 2; // use your actual servo GPIO
constexpr minUs = 544; // set to your particular pulse width for min. servo position
constexpr maxUs = 2400; // set to your particular pulse width for max. servo position
myServo.attach(pin, minUs, maxUs);

This is safe for everyone and allows you to set the exact timings for each of your servos.

@CrazyRobMiles
Copy link
Contributor Author

@dok-net thanks for your interest. I actually did exactly what you've suggested but my post of "Fixed" didn't make that very clear.

There are a couple of constants in servo.h:

#define SERVO_MIN 544
#define SERVO_MAX 2400

These are used in the attach in servo.cpp in the call of attach:

servo->attach(servoSettings.ServoOutputPin,SERVO_MIN, SERVO_MAX);

I wondered about making these configurable settings (like the output pin) but at the moment they are baked into the code.

@dok-net
Copy link

dok-net commented Jul 18, 2021

@CrazyRobMiles I can't follow your reasoning. The defaults are defined in the code, naturally. Once you by trial-and-error determine the correct limits for your particular servo, you use them in your call to attach(). There is nothing about it that is hard-wired and needs to be made configurable in the current ESP8266 Core for Arduino code base, as it's fully configured through the API as I have detailed. I hope you realize your misconception by looking at the header file and the samples and what has been detailed here, a second time.
That said, it seems from your mention of SERVO_MIN and SERVO_MAX, that you are not really using the current version of the included Servo library... I am referring to anything that is release Arduino Core for ESP8266 3.0.0 and later.

@CrazyRobMiles
Copy link
Contributor Author

@dok-net Hi. Sorry for causing more confusion. I'm talking about my code, not the library. I'm making a device which is software configurable. I've put some fixed values in my code at the moment (the defines that you can see in my file servo.h) with the intention of making them user configurable later (if people ask for it). Then the user can determine the min and max they want to use for their particular servo and configure them in the settings for that device. I've not changed the Arduino servo library at all and I don't intend to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants