-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Describe the bug
Serial data is not received by Serial Studio on Windows when sent from certain microcontrollers, even though the port is successfully opened.
- Serial Port Connections in Windows 11 #124
- Pi Pico USB serial port reconnect issue #135
- Strange Serial Port behavior with Arduino Nano Every #98
- Not receiving data in terminal #172
The fix:
This appears to be due to Data Terminal Ready (DTR) not being set. Adding the one line of code below solves the issue for me:
// src/IO/Divers/Serial.cpp
//...
// Open device
if (port()->open(mode))
{
connect(port(), &QIODevice::readyRead, this,
&IO::Drivers::Serial::onReadyRead);
+ port()->setDataTerminalReady(true);
return true;
}
//...I arrived at this conclusion by first confirming QT's Serial Port example has the same issue, and found this forum post suggesting the issue was DTR.
I know nothing about working with QT, nor the inner workings of serial communication, and as such I do not know if this solution would be unsafe; but what I do know is that this one line of code fixes the problem for me with my Raspberry Pi Pico on Windows.
Things to consider from my outside perspective:
- Does the DTR flag need to be set to false upon closing?
- Should this behaviour be Windows-specific?
- Should this be hard-coded in, or an additional option in "Flow control"?
Upload minimal Arduino Raspberry Pi Pico program to replicate your issue
On a Raspberry Pi Pico, build and upload the UF2 of:
// main.c
#include <stdio.h>
#include "pico/stdlib.h"
#define PIN_LED 25
int main() {
stdio_init_all();
gpio_init(PIN_LED);
gpio_set_dir(PIN_LED, GPIO_OUT);
while (1) {
printf("Hello, world!\n");
gpio_put(PIN_LED, true);
sleep_ms(100);
gpio_put(PIN_LED, false);
sleep_ms(100);
}
}# CMakeLists.txt
# This is the version Raspberry Pi uses, no explicit reasoning provided
cmake_minimum_required(VERSION 3.13)
# Pre-initialize the Pico SDK
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
# Set PROJECT_NAME
project(hello-world)
# Invoke the Pico SDK's CMakeLists.txt to import build settings and definitions
pico_sdk_init()
# Tell CMake what/where our executable source file is
add_executable(${PROJECT_NAME} main.c)
# Link the project to pico_stdlib as defined by the SDK
target_link_libraries(${PROJECT_NAME} pico_stdlib)
# Enable UART stdio output
pico_enable_stdio_usb(${PROJECT_NAME} ON)
# Create map/bin/hex/uf2 files, in addition to ELF
pico_add_extra_outputs(${PROJECT_NAME})See here if you need a (messy) step-by-step example to setting up a Raspberry Pi Pico build environment on Windows.
(You can probably much more easily set up a build environment with Raspberry Pi's Pico extension for VSCode)
Serial Studio settings:
| . | . |
|---|---|
| Communication mode: | No parsing |
| Data source: | Serial port |
| Baud rate: | 115200 |
| Auto-reconnect: | [ ] |
| Data bits: | 8 |
| Parity: | None |
| Stop bits: | 1 |
| Flow control: | None |