Sending values from QT to arduino
-
how do I send a number value from QT to arduino. If I use the sendCommandToArduino("150");, it sends 150 to the arduino but if I use the sendCommandToArduino("force");, it sends force to the arduino but I want it to send the value of the force that is calculated in Qt as a double. F
-
@Goodnews said in Sending values from QT to arduino:
sendCommandToArduino
What is that?
"but I want it to send the value of the force that is calculated in Qt as a double" - depends on what sendCommandToArduino expects. If it only supports string then convert your double to string (https://doc.qt.io/qt-6/qstring.html#number-6).
-
@jsulm this is what it expexts: .......::sendCommandToArduino(const QString& command)
{
qDebug() << "Sending command to Arduino: " << command;
if(arduino->isWritable()){
arduino->write(command.toStdString().c_str());
arduino->waitForBytesWritten(1000);
}else{
qDebug() << "Couldn't write to serial port";
}
} -
@Goodnews
We don't know what you actually want, which depends on whatever your device expects. There are (presumably) only two possibilities:- You send a string of
"150"
, so 3 digit characters,1
,5
and0
. - You send the binary representation of the number
150
as some sequence of bytes (e.g. perhaps 4 for an integer or 8 for a double), in either low-high or high-low order.
Find out which you need to send and do so.
- You send a string of
-
@Goodnews said in Sending values from QT to arduino:
and when I convert the double to a string, it sends the string in words to the Arduino, not the calculated value of the string
I don't know what you mean. If you have
double number = 3.14;
and then want to send it as string you do
QString strNumber = QString::number(number);
you will get string "3.14".
Is this what you want? If not then please explain clearly what your Arduino device expects to receive.... -
@JonB My device expects a value between 0 and 180, so it responds when I send 150 to the Arduino. Instead of sending a constant value, I want to change the 150 to force. The force is a double that is calculated in QT. (so that I have this sendCommandToArduino("force"); instead of this sendCommandToArduino("150"); Now instead of QT to send the numerical value of force like the way it sends 150, it sends "force" like this: Sending command to Arduino: "force"(I added a qdebug to print what is sent to the Arduino). My issue is that QT doesn't send the numerical force value to the Arduino; it just sends force, which does nothing. The expression of force is : double force= =sqrt(mass*acceleration)(as an example). I get the numerical value of force printed per time in the application output and I want QT to send that value to the arduino.
-
@jsulm yes I did and I have these 2 errors: error: C2440: 'initializing' : cannot convert from 'QString' to 'int'
error C2440: 'initializing' : cannot convert from 'QString' to 'int'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called, error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int -
... and the signatures of the send routines you are using.