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. Qt - Serialport : Read multiple Analog Inputs from Arduino at the same time

Qt - Serialport : Read multiple Analog Inputs from Arduino at the same time

Scheduled Pinned Locked Moved Solved General and Desktop
qt serialportarduinoread serialqcustomplotplot
4 Posts 3 Posters 1.9k 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.
  • S Offline
    S Offline
    Suneclipt
    wrote on 25 Jul 2019, 10:13 last edited by
    #1

    Hi all,
    im having following issue and couldnt find a fitted solution/project for it:

    Im trying to read two sensoric-datas from my Arduino and display them to my Qt interface.
    The Arduino sends the data as numbers like this (Serial Monitor):
    0_1564048141183_Qt Forum1.jpg

    My Arduino Code lookes like this:
    0_1564047999724_qt forum 2.PNG

    On Arduino side the Serial-Plotter displays two different graphs.

    On my qt Side i implemented a timer which calls as fast as possible this method (after arduino is connected via Serialport):
    0_1564048268644_qt forum 3.PNG .

    So i try to get the data as a string and display it. But this doesnt work well. The problem is that on Qt side i cant differ Sensor1-Data from Sensor2-Data. I tried to split the incoming data but qt messes somehow up and my plot (on qt side) seem to mix both values:
    0_1564048725811_collage.jpg

    I basically want to read the two values from Arduino and display them into two different plot by teaching my qt program to split these incoming data and then separate them.
    For 1 Sensoric data everything works fine. Its because with serialport->readAll() only the data of one sensor will be read and i dont need to split them.

    So i guess there must be a better way to read the data for two sensors.

    To my enviroment:
    Windows 10 64bit
    Qt Creator + QCustomPlot (libary for plotting)
    Arduino Uno + Two Sensors on Analog Inputs

    I hope some of you can understand my topic and maybe help me. Wish you a great Week!

    J A 2 Replies Last reply 25 Jul 2019, 10:24
    0
    • S Suneclipt
      25 Jul 2019, 10:13

      Hi all,
      im having following issue and couldnt find a fitted solution/project for it:

      Im trying to read two sensoric-datas from my Arduino and display them to my Qt interface.
      The Arduino sends the data as numbers like this (Serial Monitor):
      0_1564048141183_Qt Forum1.jpg

      My Arduino Code lookes like this:
      0_1564047999724_qt forum 2.PNG

      On Arduino side the Serial-Plotter displays two different graphs.

      On my qt Side i implemented a timer which calls as fast as possible this method (after arduino is connected via Serialport):
      0_1564048268644_qt forum 3.PNG .

      So i try to get the data as a string and display it. But this doesnt work well. The problem is that on Qt side i cant differ Sensor1-Data from Sensor2-Data. I tried to split the incoming data but qt messes somehow up and my plot (on qt side) seem to mix both values:
      0_1564048725811_collage.jpg

      I basically want to read the two values from Arduino and display them into two different plot by teaching my qt program to split these incoming data and then separate them.
      For 1 Sensoric data everything works fine. Its because with serialport->readAll() only the data of one sensor will be read and i dont need to split them.

      So i guess there must be a better way to read the data for two sensors.

      To my enviroment:
      Windows 10 64bit
      Qt Creator + QCustomPlot (libary for plotting)
      Arduino Uno + Two Sensors on Analog Inputs

      I hope some of you can understand my topic and maybe help me. Wish you a great Week!

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 25 Jul 2019, 10:24 last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • S Suneclipt
        25 Jul 2019, 10:13

        Hi all,
        im having following issue and couldnt find a fitted solution/project for it:

        Im trying to read two sensoric-datas from my Arduino and display them to my Qt interface.
        The Arduino sends the data as numbers like this (Serial Monitor):
        0_1564048141183_Qt Forum1.jpg

        My Arduino Code lookes like this:
        0_1564047999724_qt forum 2.PNG

        On Arduino side the Serial-Plotter displays two different graphs.

        On my qt Side i implemented a timer which calls as fast as possible this method (after arduino is connected via Serialport):
        0_1564048268644_qt forum 3.PNG .

        So i try to get the data as a string and display it. But this doesnt work well. The problem is that on Qt side i cant differ Sensor1-Data from Sensor2-Data. I tried to split the incoming data but qt messes somehow up and my plot (on qt side) seem to mix both values:
        0_1564048725811_collage.jpg

        I basically want to read the two values from Arduino and display them into two different plot by teaching my qt program to split these incoming data and then separate them.
        For 1 Sensoric data everything works fine. Its because with serialport->readAll() only the data of one sensor will be read and i dont need to split them.

        So i guess there must be a better way to read the data for two sensors.

        To my enviroment:
        Windows 10 64bit
        Qt Creator + QCustomPlot (libary for plotting)
        Arduino Uno + Two Sensors on Analog Inputs

        I hope some of you can understand my topic and maybe help me. Wish you a great Week!

        A Offline
        A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on 25 Jul 2019, 10:24 last edited by
        #3

        @Suneclipt said in Qt - Serialport : Read multiple Analog Inputs from Arduino at the same time:

        The problem is that on Qt side i cant differ Sensor1-Data from Sensor2-Data.

        Why not? You already know that there are ASCII numbers coming in, separated by space and newline.

        Now all you need to do is to extract them from an endless incoming stream.

        Note: readAll() does not respect line endings, it just gives you what is there. That might be in the middle of a line.

        So what you should do:

        1. Use canReadLine() in a loop
        2. readLine()
        3. splite the line into the two number, convert them separately
        4. use the extracted numbers to generate your plot

        Regards

        Qt has to stay free or it will die.

        S 1 Reply Last reply 29 Jul 2019, 09:07
        7
        • A aha_1980
          25 Jul 2019, 10:24

          @Suneclipt said in Qt - Serialport : Read multiple Analog Inputs from Arduino at the same time:

          The problem is that on Qt side i cant differ Sensor1-Data from Sensor2-Data.

          Why not? You already know that there are ASCII numbers coming in, separated by space and newline.

          Now all you need to do is to extract them from an endless incoming stream.

          Note: readAll() does not respect line endings, it just gives you what is there. That might be in the middle of a line.

          So what you should do:

          1. Use canReadLine() in a loop
          2. readLine()
          3. splite the line into the two number, convert them separately
          4. use the extracted numbers to generate your plot

          Regards

          S Offline
          S Offline
          Suneclipt
          wrote on 29 Jul 2019, 09:07 last edited by
          #4

          @aha_1980 Thank you alot Sir your answer was correct and helped to clean up the problem!

          Regards

          1 Reply Last reply
          3

          1/4

          25 Jul 2019, 10:13

          • Login

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