nv7
July 30, 2023, 9:41am
1
I called write(90) on a Servo object that was attached, but when I call read() on this object it returns -52. Any ideas why? I am using an Arduino Nano 33 BLE.
I don't have a physical Servo connected to the header, but I don't think that could be causing this issue.
Please post the sketch that you used
Not having a servo actually connected will make no difference but I assume that you have used the attach() function for the servo
J-M-L
July 30, 2023, 12:12pm
4
without your code it's hard to say.
Note that here is the servo code
on AVR
int Servo::read() // return the value as degrees
{
return map( this->readMicroseconds()+1, SERVO_MIN(), SERVO_MAX(), 0, 180);
}
int Servo::readMicroseconds()
{
unsigned int pulsewidth;
if( this->servoIndex != INVALID_SERVO )
pulsewidth = ticksToUs(servos[this->servoIndex].ticks) + TRIM_DURATION ; // 12 aug 2009
else
pulsewidth = 0;
return pulsewidth;
}
on NRF52
int Servo::read() // return the value as degrees
{
return map(readMicroseconds(), MIN_PULSE, MAX_PULSE, 0, 180);
}
int Servo::readMicroseconds()
{
uint8_t channel, instance;
uint8_t pin=servos[this->servoIndex].Pin.nbr;
instance=(g_APinDescription[pin].ulPWMChannel & 0xF0)/16;
channel=g_APinDescription[pin].ulPWMChannel & 0x0F;
// remove the 16th bit we added before
return seq_values[instance][channel] & 0x7FFF;
}
they are quite different, so if you don't have a bug in your code, may be there is some bug in the way readMicroseconds() works?
nv7
July 30, 2023, 8:05pm
5
Yes, I did use the attach() function
nv7
July 30, 2023, 8:05pm
6
I'm just trying to increment my servo position by 1every few milliseconds. I know that I can just use another variable for it, but I was hoping I could use Servo.read()
As previous requested, please post your sketch
system
Closed
January 26, 2024, 8:14pm
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.