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. Qserialport does not send a char to arduino
Forum Update on Monday, May 27th 2025

Qserialport does not send a char to arduino

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 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.
  • E Offline
    E Offline
    endure
    wrote on 25 Jan 2014, 04:14 last edited by
    #1

    I'm having a trouble in trying to send a char (i.e. "R") from my qt5 application on WIN7 to comport which is connected to an Arduino. I intend to blink a led on Arduino and my arduino part works OK.

    Here is my qt code:

    @#include <QTextStream>
    #include <QCoreApplication>
    #include <QtSerialPort/QSerialPortInfo>
    #include <QSerialPort>
    #include <iostream>
    #include <QtCore>

    QT_USE_NAMESPACE

    using namespace std;
    QSerialPort serial;

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    QTextStream out(stdout);
    QList<QSerialPortInfo> serialPortInfoList = QSerialPortInfo::availablePorts();

    out << QObject::tr("Total number of ports available: ") << serialPortInfoList.count() << endl;
    
    
    foreach (const QSerialPortInfo &serialPortInfo, serialPortInfoList) {
        out << endl
            << QObject::tr("Port: ") << serialPortInfo.portName() << endl
            << QObject::tr("Location: ") << serialPortInfo.systemLocation() << endl
            << QObject::tr("Description: ") << serialPortInfo.description() << endl
            << QObject::tr("Manufacturer: ") << serialPortInfo.manufacturer() << endl
            << QObject::tr("Vendor Identifier: ") << (serialPortInfo.hasVendorIdentifier() ? QByteArray::number(serialPortInfo.vendorIdentifier(), 16) : QByteArray()) << endl
            << QObject::tr("Product Identifier: ") << (serialPortInfo.hasProductIdentifier() ? QByteArray::number(serialPortInfo.productIdentifier(), 16) : QByteArray()) << endl
            << QObject::tr("Busy: ") << (serialPortInfo.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) << endl;
    }
    
    serial.setPortName("COM5");
    serial.open(QIODevice::ReadWrite);
    serial.setBaudRate(QSerialPort::Baud9600);
    serial.setDataBits(QSerialPort::Data8);
    serial.setParity(QSerialPort::NoParity);
    serial.setStopBits(QSerialPort::OneStop);
    serial.setFlowControl(QSerialPort::NoFlowControl);
    
    
    
    
        if(!serial.isOpen())
        {
          std::cout<<"port is not open"<<endl;
          //serial.open(QIODevice::ReadWrite);
        }
    
    if(serial.isWritable()==true)
    {
        std::cout<<"port writable..."<<endl;
    }
    
    
    
    QByteArray data("R");
    
    serial.write(data);
    serial.flush();
    std::cout<<"value sent!!! "<<std::endl;
    serial.close();
    
    return 0;
    

    }@

    My source code consists of two parts,

    1- serialportinfolist .... which works just fine 2- opening and writing data... I get no issue when running the code and the display shows the result as if nothing has gone wrong!

    HOWEVER, the led on the board does not turn on when I run this code.

    I test this with Arduino Serial Monitor and it turns on but cant turn on from Qt.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gorbatschow
      wrote on 25 Jan 2014, 10:54 last edited by
      #2

      Are you sure that the data is not transmitted? Maybe you have incompatible signals. Than look at something like this (http://en.wikipedia.org/wiki/MAX232)

      1 Reply Last reply
      0

      2/2

      25 Jan 2014, 10:54

      • Login

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