淺談飛凌嵌入式RK3399開發(fā)板試用體驗(yàn)
在一半的開發(fā)平臺(tái)中,實(shí)驗(yàn)逐漸加深,我也在考慮用這個(gè)小項(xiàng)目開發(fā)板做點(diǎn)什么。
選擇這個(gè)項(xiàng)目呢需要準(zhǔn)備點(diǎn)東西。我這邊為了開發(fā)方便選擇了是單片機(jī)開發(fā)板,板載兩個(gè)傳感器一個(gè)SHT20和一個(gè)光照度傳感器,通過串口和我們的OK3399之間傳輸數(shù)據(jù),后續(xù)有機(jī)會(huì),最方便的就是在Linux底層加入驅(qū)動(dòng),寫Linux驅(qū)動(dòng)方式來讀傳感器數(shù)據(jù),有機(jī)會(huì)會(huì)寫一篇體驗(yàn)的。
OK3399這邊也是處理好了底層串口驅(qū)動(dòng),我使用的是與SPI口復(fù)用的串口4,設(shè)備名稱ttyS4,有這個(gè)我們就可以在QT中寫串口程序了。
接下來就是接好線,注意TX和RX交叉和共地,基本就可以完成數(shù)據(jù)傳輸。
上面就是串口接收程序,目前主要是采用定時(shí)器和一個(gè)槽函數(shù)完成定時(shí)接收數(shù)據(jù)解析。
寫完這個(gè)程序后我測(cè)試了下打印。
通過usb轉(zhuǎn)TTL的模塊把電腦端的數(shù)據(jù)傳送到底層調(diào)試串口上打印出來,效果就是這樣。
單片機(jī)這邊也同樣是初始化傳感器和串口,以及一個(gè)定長數(shù)組包就可以完成三組數(shù)據(jù)的同時(shí)傳輸。兩邊串口設(shè)置需要相同。
接下來就是把剩余程序編寫完成。然后傳輸?shù)较挛粰C(jī)上,具體可以看我體驗(yàn)二的文章,里面有具體步驟。然后就是運(yùn)行,效果如下。
我在這里使用了一個(gè)開源的QT繪制曲線庫,QCustomPlot,這個(gè)庫功能強(qiáng)大,太多的我也沒深入研究,這里就貼上我的代碼。
QFontfont;//font.setPointSize(12);/*實(shí)例化,設(shè)置位置、背景顏色*/QBrushbrush(QColor(50,50,50));dataCustomPlot=newQCustomPlot(ui->widget);dataCustomPlot->setGeometry(0,0,880,440);dataCustomPlot->setBackground(brush);//設(shè)定右上角圖形標(biāo)注可見dataCustomPlot->legend->setVisible(true);dataCustomPlot->legend->setFont(QFont("HelveTIca",9));dataCustomPlot->legend->setRowSpacing(-3);dataCustomPlot->installEventFilter(ui->widget);QVector shapes;shapes<se TIn teractions(QCP::iRangeDrag|QCP::iRangeZoom);//可拖拽+可滾輪縮放dataCustomPlot->xAxis->setLabelColor(QColor(Qt::white));//X軸上標(biāo)識(shí)label字體顏色dataCustomPlot->yAxis->setLabelColor(QColor(Qt::white));dataCustomPlot->xAxis->setTickPen(pen);//設(shè)置x軸上坐標(biāo)點(diǎn)上對(duì)應(yīng)的刻度線的顏色dataCustomPlot->xAxis->setTickLabelRotation(60);//設(shè)置標(biāo)簽角度旋轉(zhuǎn)dataCustomPlot->yAxis->setTickPen(pen);dataCustomPlot->xAxis->setBasePen(pen);//設(shè)置x軸軸線本身的顏色dataCustomPlot->yAxis->setBasePen(pen);dataCustomPlot->xAxis->setTickLabelColor(QColor(Qt::white));//設(shè)置x軸刻度值文本的顏色dataCustomPlot->yAxis->setTickLabelColor(QColor(Qt::white));dataCustomPlot->xAxis->setSubTicks(false);//隱藏x軸刻度線dataCustomPlot->yAxis->setSubTicks(false);//隱藏y軸刻度線dataCustomPlot->xAxis->setLabelFont(font);//設(shè)置x軸標(biāo)識(shí)label文本字體大小dataCustomPlot->yAxis->setLabelFont(font);//設(shè)置y軸標(biāo)識(shí)label文本字體大小font.setPointSize(10);dataCustomPlot->xAxis->setTickLabelFont(font);dataCustomPlot->yAxis->setTickLabelFont(font);dataCustomPlot->xAxis->setLabel("時(shí)間");QSharedPointer dateTicker(newQCPAxisTickerDateTime);//得到DateTime的dateTicker->setDateTimeFormat("hh:mm:ss");dataCustomPlot->xAxis->setTicker(dateTicker);dataCustomPlot->xAxis->setRange(20170101011234,20300228235959);dataCustomPlot->yAxis->setRange(0,100);//設(shè)置y軸數(shù)據(jù)范圍/*增加一個(gè)數(shù)據(jù)曲線*/pen.setColor(Qt::blue);//設(shè)置畫筆的顏色dataCustomPlot->addGraph();//增加曲線圖//設(shè)置右上角顯示名稱dataCustomPlot->graph(0)->setName("溫度");//設(shè)置曲線的名字dataCustomPlot->graph(0)->setPen(pen);//設(shè)置曲線畫筆的顏色dataCustomPlot->graph(0)->setLineStyle(QCPGraph::lsLine);//設(shè)置連接線的類型兩點(diǎn)直線連接dataCustomPlot->graph(0)->setScatte rStyle(QCPScatterStyle(shapes.at(3),10));pen.setColor(Qt::green);//設(shè)置畫筆的顏色dataCustomPlot->addGraph();//增加曲線圖dataCustomPlot->graph(1)->setPen(pen);//設(shè)置曲線畫筆的顏色dataCustomPlot->graph(1)->setName("濕度");//設(shè)置曲線的名字dataCustomPlot->graph(1)->setLineStyle(QCPGraph::lsLine);//設(shè)置連接線的類型兩點(diǎn)直線連接dataCustomPlot->graph(1)->setScatterStyle(QCPScatterStyle(shapes.at(5),10));pen.setColor(QColor(250,168,140));//設(shè)置畫筆的顏色dataCustomPlot->addGraph();//增加曲線圖dataCustomPlot->graph(2)->setPen(pen);//設(shè)置曲線畫筆的顏色dataCustomPlot->graph(2)->setName("光照度");//設(shè)置曲線的名字dataCustomPlot->graph(2)->setLineStyle(QCPGraph::lsLine);//設(shè)置連接線的類型兩點(diǎn)直線連接dataCustomPlot->graph(2)->setScatterStyle(QCPScatterStyle(shapes.at(7),10));/*刷新顯示*/dataCustomPlot->replot();
以上是初始化繪制背景和三個(gè)曲線的樣式。
ucharFHone=buf.at(0);ucharFHtwo=buf.at(1);ucharFTone=buf.at(8);ucharFTtwo=buf.at(9);if(FHone==0x11&&FHtwo==0x22&&FTone==0xff&&FTtwo==0xee){tempreture=(buf.at(2)<<8|buf.at(3))/10.0;????????humidity???=?(buf.at(4)<<8|buf.at(5))/10.0;????????Light_Value?=?buf.at(6)<<8|buf.at(7);?????????QString?tmp?=QString::number(tempreture,?'f',?1);????????QString?hum?=QString::number(humidity,?'f',?1);????????QString?Light_value?=?QString("%1").arg(Light_Value);???????//光照度????????ui->label_2->setText(tmp+"℃");ui->label_4->setText(hum+"%");ui->label_6->setText(Light_value+"LX");dataCustomPlot->graph(0)->addData(now,tempreture);dataCustomPlot->graph(1)->addData(now,humidity);dataCustomPlot->graph(2)->addData(now,Light_Value);dataCustomPlot->xAxis->setRange(now,5,Qt::AlignRight);dataCustomPlot->replot();}
下面的這個(gè)是具體的解析數(shù)據(jù),讓其顯示的過程。 至此搭建完硬件和軟件就能實(shí)現(xiàn)具體數(shù)據(jù)的顯示了,當(dāng)然在Linux上直接做驅(qū)動(dòng)是很好的,但是這種方式也比較適用專門用QT開發(fā)界面,用其他平臺(tái)搭建硬件環(huán)境的。驅(qū)動(dòng)就能少關(guān)心一些。后面我也將繼續(xù)學(xué)習(xí)下OK3399的其他玩法。
對(duì)官方網(wǎng)站感興趣