Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Communication between Raspberry Pico and QtSerialPort not working on Windows
Forum Updated to NodeBB v4.3 + New Features

Communication between Raspberry Pico and QtSerialPort not working on Windows

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 502 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dragoner
    wrote on last edited by Dragoner
    #1

    I have a Raspberry Pico connect via USB to my Windows Computer. On the Pico the following program is running:

    int main() {
    
        stdio_init_all();
    
        while(true) {
            printf("HelloWorld");
            sleep_ms(1000);
        }
     }
    

    I try to read the output via QSerialPort. My Qt program is:

    int main(int argc, char *argv[])
    {
        QSerialPort serialPort("COM3");
    
        qDebug() << "Opening";
        if (!serialPort.open(QIODevice::ReadWrite)) {
            qDebug() << "Failed to open " << serialPort.portName();
            exit(-1);
        }
    
        qDebug() << "Open!";
        while (true) {
            if (serialPort.waitForReadyRead(2000)) {
                QByteArray response = serialPort.readAll();
                qDebug().noquote() << "R: " << response;
            } else {
                qDebug() << "Got Nothing";
            }
        }
    }
    

    If I plug in the Pico via USB and start the Qt program, the output I get is:

    Opening
    Open!
    Got Nothing
    Got Nothing
    Got Nothing
    ...
    

    But, If I open the COM port using a different tool, in my case the SerialMonitor from the Arudino IDE, I see

    HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorld
    

    as excpected. If I start my Qt program after I opened the COM port with the Arudio IDE, I can also see the output:

    Opening        
    Open!
    R:  HelloWorld
    R:  HelloWorld
    R:  HelloWorld
    

    The same issue is also reported on Stackoverflow, but using PyQt.
    This issue appears only with Windows. On a Raspberry Pi everything works as expected.

    • Why does QtSerialPort works as expected if I open the Port with a different tool before?
    • What does the Arudino IDE do, that QtSerialPort is (maybe) missing?
    J.HilkJ 1 Reply Last reply
    0
    • D Dragoner

      I have a Raspberry Pico connect via USB to my Windows Computer. On the Pico the following program is running:

      int main() {
      
          stdio_init_all();
      
          while(true) {
              printf("HelloWorld");
              sleep_ms(1000);
          }
       }
      

      I try to read the output via QSerialPort. My Qt program is:

      int main(int argc, char *argv[])
      {
          QSerialPort serialPort("COM3");
      
          qDebug() << "Opening";
          if (!serialPort.open(QIODevice::ReadWrite)) {
              qDebug() << "Failed to open " << serialPort.portName();
              exit(-1);
          }
      
          qDebug() << "Open!";
          while (true) {
              if (serialPort.waitForReadyRead(2000)) {
                  QByteArray response = serialPort.readAll();
                  qDebug().noquote() << "R: " << response;
              } else {
                  qDebug() << "Got Nothing";
              }
          }
      }
      

      If I plug in the Pico via USB and start the Qt program, the output I get is:

      Opening
      Open!
      Got Nothing
      Got Nothing
      Got Nothing
      ...
      

      But, If I open the COM port using a different tool, in my case the SerialMonitor from the Arudino IDE, I see

      HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorld
      

      as excpected. If I start my Qt program after I opened the COM port with the Arudio IDE, I can also see the output:

      Opening        
      Open!
      R:  HelloWorld
      R:  HelloWorld
      R:  HelloWorld
      

      The same issue is also reported on Stackoverflow, but using PyQt.
      This issue appears only with Windows. On a Raspberry Pi everything works as expected.

      • Why does QtSerialPort works as expected if I open the Port with a different tool before?
      • What does the Arudino IDE do, that QtSerialPort is (maybe) missing?
      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Dragoner you fail to specify baudrate, parity, data & stopbit, flow control etc of your QSerialPort, maybe thats the issue here.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dragoner
        wrote on last edited by Dragoner
        #3

        @J-Hilk While searching for proof that values like baudrate are irrelevant for USB-CDC (e. g. here ), I found a thread shows the answer: Windows COM access to PICO via USB trouble.

        The Data-Terminal-Ready flag needs to be set to DTR_CONTROL_ENABLE.

        This can be done via

        QSerialPort::setDataTerminalReady(true)
        

        after opening the Port.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved