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. Arduino & Qt
Forum Updated to NodeBB v4.3 + New Features

Arduino & Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 6 Posters 1.3k 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.
  • A arsinte_andrei
    22 Jun 2019, 22:10

    also please consider adding in your loop in the arduino code a function to send the status of the pin only when asked else it will trigger the emit in Qt few million times a second - witch you do not want

    pseudo code

    in Qt
    void askForPinStatus(int pinNo) {
    serial.write(statuscommand.append(pinNo));
    }
    
    in constructor {
    connect seria, &serialClass::readyRead, this, &thisClassName::thisSlotProcessing);
    }
    
    thisSlotProcessing(QByteArray data){
    pinstatus.pinNo = data.first4bytes
    pinstatus.pinStatus = data.nextBytes
    }
    

    keep in mind that this is just pseudocode and is without any check - you should implement a lot of checks like to see is data received complete or it is not corrupted, ....... hope you've got the idea

    in arduino jest read in the loop all the serial and if you get a command from the serial then make a software interrupt and execute it

    hope that helps...

    A Offline
    A Offline
    aha_1980
    Lifetime Qt Champion
    wrote on 23 Jun 2019, 04:36 last edited by aha_1980
    #4

    @arsinte_andrei

    it will trigger the emit in Qt few million times a second - witch you do not want

    Rather a few hundred times a second. Serial ports are really slow compared to modern computation speed.

    Qt has to stay free or it will die.

    1 Reply Last reply
    3
    • N Offline
      N Offline
      NotYourFan
      wrote on 23 Jun 2019, 10:51 last edited by
      #5

      okay thank you for the answers.

      I want to read for example my integers value in Qt not the serial.

      Arduino:

      float INT_TEST = 23.3; 
      

      this float I will read in Qt and show it on lcd for example.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 23 Jun 2019, 11:18 last edited by mrjj
        #6

        Hi
        Well if your
        float INT_TEST = 23.3;
        lives in Arduino and you want to show it in another app, then you
        will have to sent the value over say serial to the "lcd" app.

        If the INT_TEST is already where you want to display it, im not sure i understand what
        you ask.

        1 Reply Last reply
        2
        • N Offline
          N Offline
          NotYourFan
          wrote on 23 Jun 2019, 12:16 last edited by NotYourFan
          #7

          Hi
          you understanded right.
          I want to read in Qt my "INT_TEST" value (witch its in Arduino).
          I don't know how.

          A 1 Reply Last reply 23 Jun 2019, 12:51
          0
          • N NotYourFan
            23 Jun 2019, 12:16

            Hi
            you understanded right.
            I want to read in Qt my "INT_TEST" value (witch its in Arduino).
            I don't know how.

            A Offline
            A Offline
            arsinte_andrei
            wrote on 23 Jun 2019, 12:51 last edited by
            #8

            @NotYourFan you have to understand that Qt is not running in Arduino (or better sad in MCU) so what you have to do is to send that variable with serial.write(int_test) to serial and then use a program made in Qt to read it...

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NotYourFan
              wrote on 23 Jun 2019, 13:10 last edited by
              #9

              I understand that Qt is not running in Arduino ... that's why I have one code für my MCU and one Code for the GUI ....
              The question was how to send the data from my MCU to Qt and read the float in Qt ...

              A 2 Replies Last reply 23 Jun 2019, 18:34
              0
              • N NotYourFan
                23 Jun 2019, 13:10

                I understand that Qt is not running in Arduino ... that's why I have one code für my MCU and one Code for the GUI ....
                The question was how to send the data from my MCU to Qt and read the float in Qt ...

                A Offline
                A Offline
                arsinte_andrei
                wrote on 23 Jun 2019, 18:34 last edited by
                #10

                @NotYourFan using the serial - that is very easy
                firstly you have to design a protocol between your computer and Arduino using the serial interface.
                like: [command][parameter]
                then all you have to do is just to communicate between them based on commands sent from your computer software and not from Arduino - except for some critical errors if you want to - else you will have many messages coming in that you have to process - depending on the serial speed.

                so basically in your loop in Arduino, you should have a function that reads the serial and process it

                pseudo code

                void process|Incomming Serial(serial message){
                if (message.startsWith(command1)){
                do command 1
                } else if (message.startsWith(command2)){
                process command 2;
                read the parameter of the command 2
                }
                // and so on
                }
                

                in Qt you do something very similar

                onReadyRead(){
                QByteArray myMessaage = seriall.readAll;
                if myMessage.startsWith("command1"){
                do command 1 read parameter 1 and so on
                }
                }
                

                and the communication between them should be something like
                [command].[parameter] // or depending on your wish
                pinNo.1.1 // could mean switch pin 1 to 1 -On
                readValue.2 // could mean that the Arduino to reply back what is the value of the pin 2

                in order to unload the serial traffic I do recommend you to use not strings as commands but hex codes - anyway start first with strings until you get pretty confident in what are you doing and then switch to hex

                1 Reply Last reply
                3
                • N NotYourFan
                  23 Jun 2019, 13:10

                  I understand that Qt is not running in Arduino ... that's why I have one code für my MCU and one Code for the GUI ....
                  The question was how to send the data from my MCU to Qt and read the float in Qt ...

                  A Offline
                  A Offline
                  arsinte_andrei
                  wrote on 23 Jun 2019, 18:36 last edited by
                  #11

                  @NotYourFan oh, I've forgotten to add that you need a serial port on your computer and in Qt, you have to select that com / or a USB serial adaptor and to be 100% sure that your operating system have the drivers loaded up first

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    NotYourFan
                    wrote on 23 Jun 2019, 19:23 last edited by
                    #12

                    my Serial communication works perfect (look at the code on the Top that I posted)

                    I can actually control gpios with buttons.

                    In short time I will install a temperature sensor and read the float in Arduino.
                    Thats the reason I posted here the question.

                    J 1 Reply Last reply 24 Jun 2019, 05:04
                    0
                    • N NotYourFan
                      23 Jun 2019, 19:23

                      my Serial communication works perfect (look at the code on the Top that I posted)

                      I can actually control gpios with buttons.

                      In short time I will install a temperature sensor and read the float in Arduino.
                      Thats the reason I posted here the question.

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 24 Jun 2019, 05:04 last edited by
                      #13

                      @NotYourFan @SGaist already suggested to use readyRead() signal to read from the serial port - did you try? What exactly is the problem?

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

                      1 Reply Last reply
                      0

                      13/13

                      24 Jun 2019, 05:04

                      • Login

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