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):
My Arduino Code lookes like this:
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):
.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:
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 InputsI hope some of you can understand my topic and maybe help me. Wish you a great Week!
-
@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:
- Use
canReadLine()
in a loop readLine()
- splite the line into the two number, convert them separately
- use the extracted numbers to generate your plot
Regards
- Use