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

write() on Arduino Uno Rev4 Wifi only works with angle #133

Open
thomashargrove opened this issue Sep 27, 2024 · 0 comments · May be fixed by #135
Open

write() on Arduino Uno Rev4 Wifi only works with angle #133

thomashargrove opened this issue Sep 27, 2024 · 0 comments · May be fixed by #135
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@thomashargrove
Copy link

The Servo.h header file has this comment for write():

// if value is < 200 it's treated as an angle, otherwise as pulse width in microseconds

This is true for AVR boards:

void Servo::write(int value)
{
  if(value < MIN_PULSE_WIDTH)
  {  // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
    if(value < 0) value = 0;
    if(value > 180) value = 180;
    value = map(value, 0, 180, SERVO_MIN(),  SERVO_MAX());
  }
  this->writeMicroseconds(value);
}

But the Uno Rev4 implementation seems to only work with angles:

void Servo::write(int angle)
{
    if (servoIndex != SERVO_INVALID_INDEX) {
        ra_servo_t *servo = &ra_servos[servoIndex];
        angle = constrain(angle, 0, 180);
        writeMicroseconds(map(angle, 0, 180, servo->period_min, servo->period_max));
    }
}

From a quick scan of the different implementations:

  1. Avr, mbed, megaavr, sam, samd, xmc - Supports angles and microseconds
  2. nrf52, renesas, stm32f4 - Only works with angles

Should be an easy fix, happy to send a PR if someone will approve it.

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Sep 27, 2024
@per1234 per1234 linked a pull request Oct 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants