Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Unsolved Qserialport Arduino garbage data

    Mobile and Embedded
    2
    2
    627
    Loading More Posts
    • 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.
    • D
      danieldil last edited by danieldil

      I am attempting to read through the serialport from an arduino. I just receive weird characters.
      Here is a screenshot
      http://tinypic.com/r/2vhulae/9

      #include <QCoreApplication>
      #include <QDebug>
      #include <QSerialPort>
      #include <QSerialPortInfo>
      #include <iostream>
      #include <QTimer>
      #include "event.h"
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          QSerialPort *arduino = new QSerialPort();
          //QSerialPortInfo info = new QSerialPortInfo();
          //QSerialPort *arduino;
          static const quint16 arduino_uno_vendor_id = 9025;
          static const quint16 arduino_uno_product_id = 67;
          QString arduino_port_name;
          bool arduino_is_available;
      
      
         qDebug() <<QSerialPortInfo::availablePorts().length();
         //qDebug() <<info.portName();
         arduino_is_available = false;
         arduino_port_name = "";
         arduino = new QSerialPort;
      
        foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
             //if(serialPortInfo.hasVendorIdentifier() && serialPortInfo.hasProductIdentifier()){
                 //if(serialPortInfo.vendorIdentifier() == arduino_uno_vendor_id){
                  //   if(serialPortInfo.productIdentifier() == arduino_uno_product_id){
                         arduino_port_name = serialPortInfo.portName();
                         arduino_is_available = true;
                     }
                 //}
      //       }
      //   }
      
          qDebug()<<arduino_is_available;
         arduino->setPortName(arduino_port_name);
         arduino->open(QSerialPort::ReadOnly);
         arduino->setBaudRate(QSerialPort::Baud115200);
      
         char buf[1024];
             qint64 lineLength = arduino->readLine(buf, sizeof(buf));
             if (lineLength != -1) {
                 // the line is available in buf
             for(int i = 0; i < 1024; i++){
                 qDebug()<<buf[i];
              }
          }
             QString x = QString(arduino->readAll());
             qDebug()<<x;
         //event *j = new event();
      
         //while(true){
        // j->pulse(arduino);
        // QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
        // }
          return a.exec();
      }
      
      
      

      Has anyone seen this before?

      1 Reply Last reply Reply Quote 0
      • K
        kolegs last edited by

        Did you try to read data using putty or other serial port terminal?
        I think its also good idea to set DataBits, FlowControl and StopBits

        1 Reply Last reply Reply Quote 0
        • First post
          Last post