Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qserialport Arduino garbage data
Forum Updated to NodeBB v4.3 + New Features

Qserialport Arduino garbage data

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 814 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.
  • D Offline
    D Offline
    danieldil
    wrote on last edited by danieldil
    #1

    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
    0
    • K Offline
      K Offline
      kolegs
      wrote on last edited by
      #2

      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
      0

      • Login

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