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. Cant read strings with Raspberry via QtSerial
Forum Updated to NodeBB v4.3 + New Features

Cant read strings with Raspberry via QtSerial

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 3 Posters 1.3k Views 3 Watching
  • 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.
  • B Offline
    B Offline
    bladekel
    wrote on last edited by bladekel
    #1

    Hello to all,
    I'am trying to read string coming from arduino to my raspberry. On raspberry pi2, I'm using qt4 with jessie and connecting raspberry with arduino via usb.

    I send data from arduino like;

    void setup(){
      Serial.begin(9600);
    }
    
    void loop(){
    Serial.println("123456789");
    delay(2000);
    }
    

    On the raspberry I'm trying to read like;

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        serial = new QSerialPort(this);
        serial->setPortName("ttyACM0");
        serial->setBaudRate(QSerialPort::Baud9600);
        serial->setDataBits(QSerialPort::UnknownDataBits);
        serial->setParity(QSerialPort::NoParity);
        serial->setStopBits(QSerialPort::OneStop);
        serial->setFlowControl(QSerialPort::NoFlowControl);
        serial->open(QIODevice::ReadWrite);
        connect(serial,SIGNAL(readyRead()),this,SLOT(data_received()));
    
    }
    
    void MainWindow::data_received()
    {
        QByteArray incomingData;
        incomingData=serial->readAll();
        qDebug(incomingData);
    }
    

    With qt terminal example, I read the data perfect.
    But with my code above;

    12
    1
    2345
    6789
    
    
    123
    4567
    89
    
    12
    3456
    789
    
    
    1
    2345
    678
    9
    
    123
    4567
    89
    
    

    What must I do? Any suggests?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      qDebug by default will add a new line at destruction hence what you see.

      If you want to modify that behaviour, take a look at this.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      B 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        qDebug by default will add a new line at destruction hence what you see.

        If you want to modify that behaviour, take a look at this.

        B Offline
        B Offline
        bladekel
        wrote on last edited by bladekel
        #3

        @SGaist
        Thanks for your reply.
        But when I tried to change the text of a label, or check the received data, I couldnt success.
        When I update the text of a label, I got 6789, 23456789, 123456 etc.
        And after those tries I saw that with qdebug I couldnt read the data clearly.

        And as I sad before , I can read the data clearly with QtSerial terminal example.

        What I'm trying to do is, checking the received data and updating the gpio pins...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The terminal example does only one thing: it appends whatever is received to the Console widget.

          The usual way to ensure good communication on a serial port is to have a protocol in place that helps you know when you have received a "full frame" of data.

          Then on the receiving part, you accumulate the data in a buffer until you have enough to recreate that frame and then process it.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          B 1 Reply Last reply
          0
          • SGaistS SGaist

            The terminal example does only one thing: it appends whatever is received to the Console widget.

            The usual way to ensure good communication on a serial port is to have a protocol in place that helps you know when you have received a "full frame" of data.

            Then on the receiving part, you accumulate the data in a buffer until you have enough to recreate that frame and then process it.

            B Offline
            B Offline
            bladekel
            wrote on last edited by
            #5

            @SGaist
            Can you suggest me an example ?

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kuzulis
              Qt Champions 2020
              wrote on last edited by
              #6

              serial->setDataBits(QSerialPort::UnknownDataBits);

              It is best solution! ))

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                What kind of example are you looking for ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                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