Unsolved Arduino & Qt
-
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.
-
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.
-
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. -
Hi
you understanded right.
I want to read in Qt my "INT_TEST" value (witch its in Arduino).
I don't know how. -
@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...
-
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 ... -
@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 2in 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
-
@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
-
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. -
@NotYourFan @SGaist already suggested to use readyRead() signal to read from the serial port - did you try? What exactly is the problem?