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. Issue with serial communication with Arduino
Forum Updated to NodeBB v4.3 + New Features

Issue with serial communication with Arduino

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 6 Posters 5.4k Views 3 Watching
  • 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.
  • aha_1980A Offline
    aha_1980A Offline
    aha_1980
    Lifetime Qt Champion
    wrote on last edited by
    #9

    Hi @Kira :

    And one more thing when i try to run the application by keeping the baud rate as 1200
    It gives me error of the serial port.

    You will need to show us more (initialization) code and the exact error message here...

    void MainWindow::writeData(const QByteArray &data)
    {
    serial->flush();
    serial->write(data);
    }

    Note: serial->flush() is not needed in most cases (the documentation also states this).

    And if, then it would be more useful to have it after the serial->write(data);.

    Can you verify that the data you send arrives at the Arduino?

    Qt has to stay free or it will die.

    1 Reply Last reply
    1
    • KiraK Offline
      KiraK Offline
      Kira
      wrote on last edited by
      #10

      @aha_1980 : You can refer to the terminal example in the qtcreator's example list
      I am using the same example.
      And i am using arduino leonardo, it program is in the given link.
      Please let me know of any other detail if required

      aha_1980A 1 Reply Last reply
      0
      • KiraK Kira

        @aha_1980 : You can refer to the terminal example in the qtcreator's example list
        I am using the same example.
        And i am using arduino leonardo, it program is in the given link.
        Please let me know of any other detail if required

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #11

        @Kira

        You will need to show us [...] the exact error message here...

        Can you verify that the data you send arrives at the Arduino?

        Qt has to stay free or it will die.

        1 Reply Last reply
        0
        • KiraK Offline
          KiraK Offline
          Kira
          wrote on last edited by
          #12

          @aha_1980 : I was searching on internet and came across an topic which co-relates to my issue.
          Please have a look on the given link:
          https://stackoverflow.com/questions/31560694/qt-serial-port-not-working

          The serial error which i get when i connect with baud rate 1200 is as follows:

          Critical Error: The I/0 operation has been aborted because of either a thread exit or an application request.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #13

            Hi,

            You should connect the errorOccured signal of your serial port and handle QSerialPort::ResourceError which would likely be close the port and open it again. Note that your arduino serial device might have had its name changed depending on the system.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • KiraK Offline
              KiraK Offline
              Kira
              wrote on last edited by
              #14

              @SGaist : One more thing i tried to communicate the same program using arduino uno and there is no issue with the program it works fine without any error any issue.
              Currently i am using arduino leonardo for my project and i need to move on with the same device.
              My python program and serial simulator program works fine with the board without giving any error and this scenario occur with qt program so just not able to figure out where exactly the problem is.

              1 Reply Last reply
              0
              • KiraK Offline
                KiraK Offline
                Kira
                wrote on last edited by
                #15

                @SGaist : Thanks for your response. I tried to play with the terminal examples in qt example set and got the stuff working.
                Following are the observations:

                1. First you have to configure the port in the settings and set the flow control to RTS/CTS.
                  Earlier was set to noflowcontrol.
                2. Connect the port
                  3.Disconnect the port
                  4.Reconnect the port
                  Note: The above approach implies when arduino is disconnected and reconnected or fresh program is burned into the arduino.
                  Apart from that only step 1 and 2 was sufficient.

                In case of Arudino uno only step 1 & 2 were required even after reconnecting and burning fresh program. May be because of the hardware specifications.
                Wondering why i have to connect, disconnect and again reconnect to get it working and only hardware flow control is working.

                1 Reply Last reply
                1
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #16

                  For the control flow, check your Arduino documentation regarding the serial port settings.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • KiraK Offline
                    KiraK Offline
                    Kira
                    wrote on last edited by
                    #17

                    Ohk thanks a lot

                    1 Reply Last reply
                    0
                    • KiraK Kira

                      Hello i am written a program to send and receive data through serial port.
                      On arduino there is program which receives the serial data and send some response.
                      My problem is that when i connect arduino to my pc and send data directly I do not get any response.
                      But when i open the serial monitor program and send data it works fine. After that when i try to send and receive the data from my program it also work. Irrespective of how many times i restart the program. But when i remove the arduino and connect again I have to go through the same process again.
                      I am using arduino leonardo

                      KerrySelectK Offline
                      KerrySelectK Offline
                      KerrySelect
                      wrote on last edited by
                      #18
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        JensenPitt
                        wrote on last edited by
                        #19
                        This post is deleted!
                        1 Reply Last reply
                        -1

                        • Login

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