From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.


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



  • 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!


  • Qt Champions 2018

    This post is deleted!

  • Qt Champions 2018

    @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



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

    Regards