Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Sending values from QT to arduino

Sending values from QT to arduino

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
12 Posts 4 Posters 1.6k 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.
  • G Offline
    G Offline
    Goodnews
    wrote on last edited by
    #1

    how do I send a number value from QT to arduino. If I use the sendCommandToArduino("150");, it sends 150 to the arduino but if I use the sendCommandToArduino("force");, it sends force to the arduino but I want it to send the value of the force that is calculated in Qt as a double. F

    jsulmJ 1 Reply Last reply
    0
    • G Goodnews

      how do I send a number value from QT to arduino. If I use the sendCommandToArduino("150");, it sends 150 to the arduino but if I use the sendCommandToArduino("force");, it sends force to the arduino but I want it to send the value of the force that is calculated in Qt as a double. F

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Goodnews said in Sending values from QT to arduino:

      sendCommandToArduino

      What is that?

      "but I want it to send the value of the force that is calculated in Qt as a double" - depends on what sendCommandToArduino expects. If it only supports string then convert your double to string (https://doc.qt.io/qt-6/qstring.html#number-6).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 2 Replies Last reply
      0
      • jsulmJ jsulm

        @Goodnews said in Sending values from QT to arduino:

        sendCommandToArduino

        What is that?

        "but I want it to send the value of the force that is calculated in Qt as a double" - depends on what sendCommandToArduino expects. If it only supports string then convert your double to string (https://doc.qt.io/qt-6/qstring.html#number-6).

        G Offline
        G Offline
        Goodnews
        wrote on last edited by
        #3

        @jsulm this is what it expexts: .......::sendCommandToArduino(const QString& command)
        {
        qDebug() << "Sending command to Arduino: " << command;
        if(arduino->isWritable()){
        arduino->write(command.toStdString().c_str());
        arduino->waitForBytesWritten(1000);
        }else{
        qDebug() << "Couldn't write to serial port";
        }
        }

        jsulmJ 1 Reply Last reply
        0
        • G Goodnews

          @jsulm this is what it expexts: .......::sendCommandToArduino(const QString& command)
          {
          qDebug() << "Sending command to Arduino: " << command;
          if(arduino->isWritable()){
          arduino->write(command.toStdString().c_str());
          arduino->waitForBytesWritten(1000);
          }else{
          qDebug() << "Couldn't write to serial port";
          }
          }

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Goodnews Then convert your double to string as I wrote above

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • jsulmJ jsulm

            @Goodnews said in Sending values from QT to arduino:

            sendCommandToArduino

            What is that?

            "but I want it to send the value of the force that is calculated in Qt as a double" - depends on what sendCommandToArduino expects. If it only supports string then convert your double to string (https://doc.qt.io/qt-6/qstring.html#number-6).

            G Offline
            G Offline
            Goodnews
            wrote on last edited by
            #5

            @jsulm and when I convert the double to a string, it sends the string in words to the Arduino, not the calculated value of the string

            JonBJ jsulmJ 2 Replies Last reply
            0
            • G Goodnews

              @jsulm and when I convert the double to a string, it sends the string in words to the Arduino, not the calculated value of the string

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Goodnews
              We don't know what you actually want, which depends on whatever your device expects. There are (presumably) only two possibilities:

              • You send a string of "150", so 3 digit characters, 1, 5 and 0.
              • You send the binary representation of the number 150 as some sequence of bytes (e.g. perhaps 4 for an integer or 8 for a double), in either low-high or high-low order.

              Find out which you need to send and do so.

              G 1 Reply Last reply
              0
              • G Goodnews

                @jsulm and when I convert the double to a string, it sends the string in words to the Arduino, not the calculated value of the string

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Goodnews said in Sending values from QT to arduino:

                and when I convert the double to a string, it sends the string in words to the Arduino, not the calculated value of the string

                I don't know what you mean. If you have

                double number = 3.14;
                

                and then want to send it as string you do

                QString strNumber = QString::number(number);
                

                you will get string "3.14".
                Is this what you want? If not then please explain clearly what your Arduino device expects to receive....

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • JonBJ JonB

                  @Goodnews
                  We don't know what you actually want, which depends on whatever your device expects. There are (presumably) only two possibilities:

                  • You send a string of "150", so 3 digit characters, 1, 5 and 0.
                  • You send the binary representation of the number 150 as some sequence of bytes (e.g. perhaps 4 for an integer or 8 for a double), in either low-high or high-low order.

                  Find out which you need to send and do so.

                  G Offline
                  G Offline
                  Goodnews
                  wrote on last edited by
                  #8

                  @JonB My device expects a value between 0 and 180, so it responds when I send 150 to the Arduino. Instead of sending a constant value, I want to change the 150 to force. The force is a double that is calculated in QT. (so that I have this sendCommandToArduino("force"); instead of this sendCommandToArduino("150"); Now instead of QT to send the numerical value of force like the way it sends 150, it sends "force" like this: Sending command to Arduino: "force"(I added a qdebug to print what is sent to the Arduino). My issue is that QT doesn't send the numerical force value to the Arduino; it just sends force, which does nothing. The expression of force is : double force= =sqrt(mass*acceleration)(as an example). I get the numerical value of force printed per time in the application output and I want QT to send that value to the arduino.

                  jsulmJ 1 Reply Last reply
                  0
                  • G Goodnews

                    @JonB My device expects a value between 0 and 180, so it responds when I send 150 to the Arduino. Instead of sending a constant value, I want to change the 150 to force. The force is a double that is calculated in QT. (so that I have this sendCommandToArduino("force"); instead of this sendCommandToArduino("150"); Now instead of QT to send the numerical value of force like the way it sends 150, it sends "force" like this: Sending command to Arduino: "force"(I added a qdebug to print what is sent to the Arduino). My issue is that QT doesn't send the numerical force value to the Arduino; it just sends force, which does nothing. The expression of force is : double force= =sqrt(mass*acceleration)(as an example). I get the numerical value of force printed per time in the application output and I want QT to send that value to the arduino.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Goodnews Come on, did you even try what I suggested?

                    double force = 12345.0;
                    sendCommandToArduino(QString::number(force));
                    

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    G 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @Goodnews Come on, did you even try what I suggested?

                      double force = 12345.0;
                      sendCommandToArduino(QString::number(force));
                      
                      G Offline
                      G Offline
                      Goodnews
                      wrote on last edited by
                      #10

                      @jsulm yes I did and I have these 2 errors: error: C2440: 'initializing' : cannot convert from 'QString' to 'int'
                      error C2440: 'initializing' : cannot convert from 'QString' to 'int'
                      No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called, error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int

                      jsulmJ 1 Reply Last reply
                      0
                      • G Goodnews

                        @jsulm yes I did and I have these 2 errors: error: C2440: 'initializing' : cannot convert from 'QString' to 'int'
                        error C2440: 'initializing' : cannot convert from 'QString' to 'int'
                        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called, error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @Goodnews Please post your code...

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        Christian EhrlicherC 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @Goodnews Please post your code...

                          Christian EhrlicherC Online
                          Christian EhrlicherC Online
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          ... and the signatures of the send routines you are using.

                          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
                          0

                          • Login

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