Hi,
I'm trying to code a 360 SG90 servo but after typing 180 to the console, most of the cases when I type 90 to stop the servo, the console doesn't log the desired angle and the servo doesn't stop. This is the code:
To the best of my knowledge, 360 degree, or continuous, servos don't allow you to rotate to a specific position. They simply rotate faster or slower depending on the value written.
I know that. The problem is that if I type 180, so the servo moves clockwise, and then I type 90, to stop the servo, the arduino doesn't get the 90 I typed and it just continues moving clockwise.
I modified a 180 degree servo, disconnecting the potentiometer from the shaft and locking it on 90 degrees. That makes the servo turn to either side if it isn't equal to 90. However, this isn't the focus of the problem. The problem is that after typing 180 to the console, it won't get-register any value anymore. If I reset the arduino, the console goes back to normal and I can type 0 and 90 freely, but after typing 180 it "locks".
could it be that when the first byte arrives over Serial it jumps into this event function and tries to read more bytes - readStringUntil() - which generates more events.
Warning: assumptions ahead.
Not worked with them, but I expect serialEvent() is to be handled as an interrupt routine, so it should be short and non blocking. If my assumption is right there should only be the fetching of the buffer from Serial and handle the new characters in loop() somewhere.