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. How to Receive the data as a String in pc From Arduino
Forum Updated to NodeBB v4.3 + New Features

How to Receive the data as a String in pc From Arduino

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 5 Posters 678 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.
  • sankarapandiyanS Offline
    sankarapandiyanS Offline
    sankarapandiyan
    wrote on last edited by
    #1

    Here , I have receive the data in QByte array ,
    the input data is

     if (Serial.available() > 0) {
        // read the incoming byte:
        incomingByte = Serial.read();
    
        // say what you got:
        Serial.print("I received: "); // This is the what i want to receive from the Arduino 
        Serial.println(incomingByte, DEC);
    

    But in PC , Its came as a byte array Even i have changed as a QString .
    I got a output like this
    I
    rec
    eive
    d: 1
    08
    I re
    cei
    ved:
    105
    I
    rece
    ive
    d: 1
    10
    I re
    ceiv
    ed:
    101

    Its split into Pieces ..

    I want to get a output as what i gave in Arduino , I mean
    Serial.print("I received: ");

    I want a output as "I received:"

    This is my Qt code

      connect(serial, &QSerialPort::readyRead, this, &MainWindow::serialReceived);
    
    void MainWindow::serialReceived() //
    {
    
        QString glen = serial->readAll().trimmed();
    
    
         if (glen.length() > 0) {
             ui->receive->append(glen);
        }
        checkAndSendData();
    }
    

    Thanks in Advance

    J.HilkJ 1 Reply Last reply
    0
    • sankarapandiyanS sankarapandiyan

      Here , I have receive the data in QByte array ,
      the input data is

       if (Serial.available() > 0) {
          // read the incoming byte:
          incomingByte = Serial.read();
      
          // say what you got:
          Serial.print("I received: "); // This is the what i want to receive from the Arduino 
          Serial.println(incomingByte, DEC);
      

      But in PC , Its came as a byte array Even i have changed as a QString .
      I got a output like this
      I
      rec
      eive
      d: 1
      08
      I re
      cei
      ved:
      105
      I
      rece
      ive
      d: 1
      10
      I re
      ceiv
      ed:
      101

      Its split into Pieces ..

      I want to get a output as what i gave in Arduino , I mean
      Serial.print("I received: ");

      I want a output as "I received:"

      This is my Qt code

        connect(serial, &QSerialPort::readyRead, this, &MainWindow::serialReceived);
      
      void MainWindow::serialReceived() //
      {
      
          QString glen = serial->readAll().trimmed();
      
      
           if (glen.length() > 0) {
               ui->receive->append(glen);
          }
          checkAndSendData();
      }
      

      Thanks in Advance

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #4

      @sankarapandiyan said in How to Receive the data as a String in pc From Arduino:

      Its split into Pieces ..

      of course, there's no guarantee that all send data arrives at the same time.
      Each time you new data is available, readyRead is emitted it's your job as programmer to store the bytes and decide when the frame is complete.

      That said, increasing the baud rate would probably help, at least for such small data packages


      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.

      sankarapandiyanS 1 Reply Last reply
      4
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        The QTextEdit just does what you told it to do - see QTextEdit::append():

        Appends a new paragraph with text to the end of the text edit.

        So you should use maybe QTextEdit::setPlaintText() instead.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        5
        • YunusY Offline
          YunusY Offline
          Yunus
          wrote on last edited by Yunus
          #3
          This post is deleted!
          aha_1980A sankarapandiyanS 2 Replies Last reply
          0
          • sankarapandiyanS sankarapandiyan

            Here , I have receive the data in QByte array ,
            the input data is

             if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();
            
                // say what you got:
                Serial.print("I received: "); // This is the what i want to receive from the Arduino 
                Serial.println(incomingByte, DEC);
            

            But in PC , Its came as a byte array Even i have changed as a QString .
            I got a output like this
            I
            rec
            eive
            d: 1
            08
            I re
            cei
            ved:
            105
            I
            rece
            ive
            d: 1
            10
            I re
            ceiv
            ed:
            101

            Its split into Pieces ..

            I want to get a output as what i gave in Arduino , I mean
            Serial.print("I received: ");

            I want a output as "I received:"

            This is my Qt code

              connect(serial, &QSerialPort::readyRead, this, &MainWindow::serialReceived);
            
            void MainWindow::serialReceived() //
            {
            
                QString glen = serial->readAll().trimmed();
            
            
                 if (glen.length() > 0) {
                     ui->receive->append(glen);
                }
                checkAndSendData();
            }
            

            Thanks in Advance

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #4

            @sankarapandiyan said in How to Receive the data as a String in pc From Arduino:

            Its split into Pieces ..

            of course, there's no guarantee that all send data arrives at the same time.
            Each time you new data is available, readyRead is emitted it's your job as programmer to store the bytes and decide when the frame is complete.

            That said, increasing the baud rate would probably help, at least for such small data packages


            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.

            sankarapandiyanS 1 Reply Last reply
            4
            • YunusY Yunus

              This post is deleted!

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

              @Yunus said in How to Receive the data as a String in pc From Arduino:

                      QString command = "something";
                      arduino->write(command.toStdString().c_str());
              

              No! Never ever! toStdCString() ist the worst choice ever as you don't specify an encoding. Most often you have to use toUtf8().

              QString command = "something";
              // expecting arduino->write(const char *); function signature
              arduino->write(command.toUtf8().constData()); // or toLatin1() or toLocal8Bit()
              

              Regards

              Qt has to stay free or it will die.

              1 Reply Last reply
              6
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @Yunus said in How to Receive the data as a String in pc From Arduino:

                Maybe this conversion could work while reading too.

                First - why to you convert a QString into a std::string into a char* array just to create a QByteArray out of it? QString has functions to directly create a QByteArray.
                Second - it's not the way you send the data, it's the function you use to insert the incoming data into a QTextEdit - the documentation clearly states that a new paragraph is started, so a newline will be added...

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                6
                • J.HilkJ J.Hilk

                  @sankarapandiyan said in How to Receive the data as a String in pc From Arduino:

                  Its split into Pieces ..

                  of course, there's no guarantee that all send data arrives at the same time.
                  Each time you new data is available, readyRead is emitted it's your job as programmer to store the bytes and decide when the frame is complete.

                  That said, increasing the baud rate would probably help, at least for such small data packages

                  sankarapandiyanS Offline
                  sankarapandiyanS Offline
                  sankarapandiyan
                  wrote on last edited by
                  #7

                  @J-Hilk Wow impressed, Thanks for your reply
                  .. now i have increased the Baud rate , Now my output is
                  I received: 108
                  I received: 10
                  5
                  I received: 110
                  I received: 101
                  I received:
                  32
                  I received: 49
                  I received: 13
                  I received:

                  1 Reply Last reply
                  0
                  • YunusY Yunus

                    This post is deleted!

                    sankarapandiyanS Offline
                    sankarapandiyanS Offline
                    sankarapandiyan
                    wrote on last edited by
                    #8

                    @Yunus Ok fine thanks

                    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