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. Raspberry pi Qt plotting with high CPU usage
QtWS25 Last Chance

Raspberry pi Qt plotting with high CPU usage

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
qt 5.4cross compileqcustomplotraspberry pilow 2d render
2 Posts 2 Posters 2.7k 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.
  • Q Offline
    Q Offline
    Qudor Eng
    wrote on 3 Mar 2016, 14:15 last edited by tekojo 3 Apr 2016, 07:54
    #1

    I use Qt creator cross-compile on Raspberry pi B+ to develope an App that plot data from file. The program work fine on my laptop but the plot use hi processing on pi B+. when I run the program on my laptop it work with less than 1% of CPU and on pi with 1-2% CPU, when I start the plotting on my Laptop it take about 13% CPU but on pi it take about 95-99% cpu!!!. Plotting on my laptop rich more than 60 frame per second but on pi just 14-16 frame per second and when I overclocked the pi I got about 35 frame per second. my laptop run Ubuntu 14.04 with gnome shell and the CPU is intel centrino core 2 Dou 2 GHz with 4 GB RAM and NVIDIA. This is the source code of my Qt App

    #include "mainwindow.h"
        #include "ui_mainwindow.h"
    
    
        ///*********** STARTING THE CLASS **************************///
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
    
            MainWindow::plotting();
        //********************* Read File **************************//
            QFile inputFile("ECG_Data.txt");
            if (inputFile.open(QIODevice::ReadOnly))
            {
               QTextStream in(&inputFile);
               int i=0;
               while (!in.atEnd())
               {
                  QString line = in.readLine();
                  fileData[i]=line.toDouble();
                  i++;
               }
               inputFile.close();
            }
    
        }
    
    
        ///**************** START BUTTON *************************///
        void MainWindow::on_pushButton_clicked()
        {
            stop= true;
        }
        ///***************** STOP BUTTON **************************///
        void MainWindow::on_pushButton_2_clicked()
        {
            stop = false;
    
        }
    
        ///**************** PLOTTING *******************************///
        void MainWindow::plotting()
        {
        //***** set plot parameters *******************************//
            ui->customPlot->addGraph();
            ui->customPlot->graph(0)->setPen(QPen(Qt::yellow)); //set plot line color
            ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
            ui->customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
            ui->customPlot->xAxis->setAutoTickStep(false);
            ui->customPlot->xAxis->setTickStep(2);
            ui->customPlot->axisRect()->setupFullAxesBox();
    
        //***** set plot background color ****************************//
            QLinearGradient plotGradient;
            plotGradient.setStart(0, 0); //set start point
            plotGradient.setFinalStop(0, 350); //set final point
            plotGradient.setColorAt(1, QColor(100, 100, 100)); // set background color
            ui->customPlot->setBackground(plotGradient);
    
        //***** creat connection for plot Axes *************************//
            // make left and bottom axes transfer their ranges to right and top axes:
            connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
            connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));
    
    
        //***** creat connection for plot founction *********************//
            // setup a timer that repeatedly calls MainWindow::realtimeDataSlot();
            connect(&dataTimer, SIGNAL(timeout()), this, SLOT(readResponse()));
            dataTimer.start(10); // Interval 0 means to refresh as fast as possible
    
        }
    
    ///**************** REAL TIME PLOTTING SLOT *********************///
        void MainWindow::readResponse()
    
        { if(j==500){j=0;}
    
            double value0 = fileData[j];
            if (stop)
            {j++;
        //***** calculate two new data points: **************************//
            double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0; //first data point of plot from time
            static double lastPointKey = 0;
            if (key-lastPointKey > 0.01) // at most add point every 10 ms
            { //emit plottingData(rx);
            //  double value0 = rxplot; // convert string data of serial port to Double to be the second data point of plot
    
        //***** add data to lines: *****************************//
              ui->customPlot->graph(0)->addData(key, value0);
              // remove data of lines that's outside visible range:
              ui->customPlot->graph(0)->removeDataBefore(key-2);
              ui->customPlot->graph(0)->rescaleValueAxis();
              lastPointKey = key;
            }
    //make key axis range scroll with the data (at a constant range size of 8):
            ui->customPlot->xAxis->setRange(key+0.25, 2, Qt::AlignRight);
            ui->customPlot->replot();
    
    //***** calculate frames per second: *********************************//
            static double lastFpsKey;
            static int frameCount;
            ++frameCount;
             if (key-lastFpsKey > 2) // average fps over 2 seconds
             { ui->statusBar->showMessage(QString("%1 FPS, Total Data points: %2").arg(frameCount/(key-lastFpsKey), 0, 'f', 0).arg(ui->customPlot->graph(0)->data()->count()), 0 );
              lastFpsKey = key;
              frameCount = 0;
             }
             }
    
        }
    
        ///****************** DESTRUCTOR ****************************///
        MainWindow::~MainWindow()
        {
            delete ui;
    
        }
    

    The App work with full screen on pi "this is the second problem" and don't receive touch event from the touchscreen. I use Qt 5.4 and on pi the operating system is Raspbian Wheezy. I fllowed this instractions to configure the cross-compile on pi here.

    This is the photo of App window on pi screen

    Please help me :(

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Mar 2016, 23:03 last edited by
      #2

      Hi and welcome to devnet,

      Don't get me wrong but are you aware that you are comparing a Dual Core 2GHz (so 2 Core at 2GHz) with 4GB of RAM and a low power ARM processor at 700MHz with 512MB or RAM ? Not to mention the GPU power levels that are also pretty different.

      The first thing I'd check is how much data you are trying to process and show and optimize that.

      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

      2/2

      3 Mar 2016, 23:03

      • 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