0

I'm having some trouble trying to make a simple USB IO demo to test the Pico. Apparently, the USB serial connection seems to be noisy, and always puts something into the UART buffer even though I am not sending anything from my end.
In the following code, I simply try to read something with getchar_timeout, which should return PICO_ERROR_TIMEOUT if nothing was sent through serial, but it's instead just printing random characters (even ilegible ones). What could be the cause of this?

int main() {
    stdio_init_all();
    char PC_input;
    
    while (1) {
        sleep_ms(1000);
        PC_input = getchar_timeout_us(1000);

        if (PC_input == PICO_ERROR_TIMEOUT) {
            printf("Timeour error!\n");
        } else {
            printf("input was %c\n", PC_input);
        }
    }

    return 0;
}

The output I get looks like this (I only typed in 'asd123'):
input was �
input was �
input was a
input was s
input was d
input was 1
input was 2
input was 3
input was �
input was �
input was �
input was �

2 Answers 2

1

Make sure the baud rate in your serial terminal is set to 115200. Also, try a different cable, and if that fails, try a different computer.

2
  • 1
    Yep, I'm calling minicom with minicom -b 115200 -o -D /dev/ttyACM0 And the cable works fine, since it's reading and transmitting just fine. May 22, 2022 at 5:14
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    May 22, 2022 at 6:12
1

Fixed! The problem was that I was storing the return of the getchar_timeout_us function as a char instead of int.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.