This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Servo MG996R With nRF52840

Hi,


I am working on the MG996R servo and MG90S with nRF52840.

I am using the following delay logic to operate MG90S. (As per datasheet)

For 0 Angle

NRF_LOG_INFO("0 Angle");
nrf_gpio_pin_set(Lock_PIN);
nrf_delay_us(1000);
nrf_gpio_pin_clear(Lock_PIN);

nrf_delay_ms(1000);

For 90 Angle

NRF_LOG_INFO("90 Angle");
nrf_gpio_pin_set(Lock_PIN);
nrf_delay_us(1500);
nrf_gpio_pin_clear(Lock_PIN);
nrf_delay_ms(1000);

For 180 Angle

NRF_LOG_INFO("180 Angle");
nrf_gpio_pin_set(Lock_PIN);
nrf_delay_us(2000);
nrf_gpio_pin_clear(Lock_PIN);
nrf_delay_ms(1000);


MG90S is working perfectly fine. But MG996R create some issues (not moving correctly).

So is there any servo library or .h file so we can use angle logic as available in Arduino.

////////  Available in Arduino

for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
                                                          // in steps of 1 degree
myservo.write(pos);                           // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos);                          // tell servo to go to position in variable 'pos'
delay(15);                                          // waits 15ms for the servo to reach the position
}



Thanks in advance.

  • But MG996R create some issues (not moving correctly).

    What "issues", exactly?

    In what way(s) is it not "correct"?

    What have you done to verify that your code is actually generating the correct timings?

    Have you looked at the Arduino code to see what it actually does?

  • Hello,

    I have to echo what @awneil already has said here; could you elaborate what you mean when you say that it is 'creating some issue ( not moving correctly )'? How is it moving, and how does it differ from what you would have expected?
    Could you also upload the specific datasheets you are referencing? Just to make sure that we are on the same page about this.

    Without having seen the datasheets; is the control of these different servos exactly the same? Is their period / frequency the same, for example? My hunch is that this could differ between the two different motors. 

    So is there any servo library or .h file so we can use angle logic as available in Arduino.

    Unfortunately we do not provide arduino-style code libraries for specific components, no. However, most of these libraries are in really just a general peripheral library - like the ones we provide in our SDK - configured to the specific component.
    Have you seen the PWM Library, as demonstrated in the PWM Library example, or the PWM Driver as demonstrated in the PWM driver example?
    I highly recommend making use of either the library or driver directly, to control your servos - instead of toggling pins with nrf_delays.
    Your above approach will not generate a stable waveform, especially not if you intend to combine it with BLE.
    There are also many posts on the forum already, describing how to control servos using either the library or driver - I highly recommend taking a look at either of these, to see how it can be done.

    Please do not hesitate to ask if anything should be unclear, or if you encounter any issues or questions!

    Best regards,
    Karl

Related