Shake on standstill when angle comes from UART


I am using the closed Loop control loop with an encoder.
When i give the Traget Angle via Serial from the laptop everything works fine.
But as soon as I am sending the Traget Angle via UART to the B_G431_esc the BLDC shakes a lot when no new Traget Angle is send.

I tried tuning some parameters including velocity_ramp, P gain for velocity and angle and also angle filter but nothing helped.

Does anybody of you have an idea where the problem is ?

Kind regards


Hard to say from this description, but the questions that come to mind are:

  • is there a difference in the code between these two setups, in particular a reason why the hardware UART should be slower or blocking compared to the other version?

  • is there a difference electrically when you connect the UART version? Are the grounds connected properly, is there perhaps a ground loop introducing noise? Is the hardware UART sending noise on the data line that is keeping the MCU busy?

Are you just switching from Serial2 to Serial3 or are there more changes involved?

@runger, there is no difference in the code. I am sending the Target angle from an Arduino Mega with Serial2.print(). And down below is the code that revieves the angle on the B_G431_esc.
Regarding the elecrtical connection. With the UART version I am Using the RX/TX pins from the B_G431_esc. I have designed a PCB that does the DC/DC converting I need for the project and also hosts the Logic level converter(5V/3.3V) needed for the communication between Arduino and B_G431_esc. I am new to designing stuff liek that, maybe there is a fault there.
I also included a sketch of that down below.

//function for recieving string 
void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
    while (Serial.available() > 0 && newData == false) {
        rc =;

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;

        else if (rc == startMarker) {
            recvInProgress = true;
//complimentary function for void recvWithStartEndMarkers()
void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        newData = false;

@Grizzly I am just using Serial with a baudrate of 115200. Both for the Target Angle from Laptop and also over UART.

Your code looks ok - the important thing is not to “busy wait” on the IO, but you read one byte at a time, only if one is available.
Of course I can’t see from this code what you do subsequently with the values, but this part looks ok.

From the PCB layout I can’t really tell much about the circuit, do you have a schematic for the board you designed?

Do you have access to an oscilloscope to check the serial lines for electrical problems?

Is the baud rate set to 115200 on both sides of the communication? And are the RX/TX lines crossed exactly once, so Ardunio TX goes to B-G431 RX and vice versa?

In the code I the just set the target angle with and then let the motor move with motor.move(target_angle).
I unfortunatly dont have acces to an oscilloscope.
I checked the baud rate and the connection of the UART again and it is right.
Here is the schematic of the board. The right dc/dc converter(7V Out) is for the supply of the arduino and the B-G431 gets supplied in parallel from the 12 volt cables that are then connected to the 12V IN connector on the board. The 3.3V is connected to the 3.3V and Ground Pin of the Arduino.

I fixed it by changing the baudrate for the UART to 500 kbaud. Now there is no shake at all.
Thanks for the help :slight_smile:

1 Like