Problem with using Uduino with Servo motors

Issue #3 resolved
Former user created an issue

Arduino Board: Teensy 3.5 Unity: Unity 5.6.2f1 Operation System: Windows 10

I have encountered a few problems when trying to use Uduino with servo motors.

  1. Servo motor rotates back to 0 degree when I'm not writing an analog value Code for Unity:
public class TestMotor : MonoBehaviour
{
    void Start()
    {
        UduinoManager.Instance.InitPin(2, PinMode.Servo);
        UduinoManager.Instance.analogWrite(2, 90);
    }
}

When executing the code, the servo motor rotates briefly to 90 degrees and then immediately returns back to 0 degree. I can read from the debug log "a 2 0" is sent to the port immediately after "a 2 90", which matches the behavior I observe. However, this is not the behavior I was looking for.

  1. Servo motor makes a lot of noise and gets stuck at a particular degree that is incorrect. This problem has not been consistently reproducible. Sometimes when using Uduino with servo motor, the servo motor does not rotate correctly whether I try controlling it through script or through the slider in the user interface. The motor would get stuck at a particular angle and make very loud noise. Closing the port does not help. The only way to end the connection seems to be unplugging the board from the computer.

Comments (4)

  1. Marc Teys repo owner

    Thanks for your report. The library initialize the pins to zero when the board is connected, but you are right it should not append with servo motors. It's going to be fixed in the next update (soon).

    Concerning the noise of the servo, have you tried using an external power ? Sometimes arduino fails to deliver enough current to move the servo motor. It's a fairly known problem which also depends on the quality of the servo.

  2. Albert

    I too am experiencing a number of problems when it comes to servo motors, similar to those described here. But various other problems as well. For example, every once in a while a servo would just start jitter in one place and not respond to any input from Unity requiring the USB to be disconnected. At other times, it would just move to a random position for absolutely no reason, and then move back to it previous position. It is hard to even pinpoint exactly when some of these problems occur as they appear to be quite stochastic. They are not caused by insufficient power applied to the motors as I am running mine off of 6V 5A power source which is way more power than needed even during stall.

    Servo control is probably one of the most common usecases for Uduino, yet this is currently quite unreliable. If you just spend a couple of hours experimenting with servos you will definitely encounter at least a few of these problems.

    UPDATE: I found what the jitter problem was caused by in my case. I was having two separate scripts attached to different game objects that were trying to drive the same servo motor simultaneously, causing them to both try to move the servo at the same time in different ways resulting in a jitter. This is quite difficult to debug, so I wonder if Uduino can be made to output a message to the console warning the developer to check their scripts if it notices that the same pin is initialized in two separate scripts. Perhaps this is something that should also be mentioned explicitly in the Servo example page to be wary of when developing.

    UPDATE2: Even after fixing this, I am experiencing jitter problems from time to time still. But more importantly, the behavior won't stop even when I press close ports in the Inspector. Why would that be? Why is the only option to unplug the USB cable?

    UPDATE3: When I experience jittering behavior, sometimes the following workaround will allow me to stop the motor without having to unplug the USB cable: 1. Exit out of play mode. 2. Click on the Uduino gameobject in the scene 3. Click on DiscoverPorts 4. Add a Pin and set the pin equal to that to which the servo is connected. 5. Set the output of that pin to something. 6. Only now the motor will stop. 7. This will not always work, however.

    UPDATE4: I enabled Uduino debug mode, and one of the messages I keep seeing is: "You are trying to send the bundle "detroy" but it seems that it's empty."

  3. Log in to comment