-->
Page 1 of 1

UART receiving problem

PostPosted: Tue Oct 05, 2021 2:11 am
by john77
I see all prints outside like
Code: Select allSerial.println("UDP OK");

Now I want to receive a char from a terminal
Code: Select allvoid UART_Get()
{
     char chr;
    if (Serial.available() > 0)
    {
        chr = Serial.read();

        //for debug
        Serial.print(chr);
    }
}

and I put it in a loop
Code: Select allvoid loop()
{
     UART_Get();
}

But I get nothing.
I test the RX pin with a scope and I see incoming signals on the pin.
What can be wrong?

Re: UART receiving problem

PostPosted: Tue Oct 05, 2021 10:20 am
by prgvitor
john77 wrote:I see all prints outside like
Code: Select allSerial.println("UDP OK");

Now I want to receive a char from a terminal
Code: Select allvoid UART_Get()
{
     char chr;
    if (Serial.available() > 0)
    {
        chr = Serial.read();

        //for debug
        Serial.print(chr);
    }
}

and I put it in a loop
Code: Select allvoid loop()
{
     UART_Get();
}

But I get nothing.
I test the RX pin with a scope and I see incoming signals on the pin.
What can be wrong?


Check the baudRate value in "Serial.begin(value);" in "void setup()". The value must be the same as configured with another device. For ESP8266 the values ​​can be 115200 or 78880, try changing the baudRate.

Also check the RX (Arduino) -> TX (Modulo), TX (Arduino) -> RX (Modulo) connections.

You can also concatenate characters into a String:

String dataRec = "";

void UART_Get()
{
char chr;
if (Serial.available() > 0)
{
chr = Serial.read();

dataRec.concat(chr);

Serial.print(dataRec);

}
}