petalinux_zynq7 驱动DAC以及ADC模块之六:qt显示adc波形

news2024/9/22 7:34:16

前文:

petalinux_zynq7 C语言驱动DAC以及ADC模块之一:建立IPicon-default.png?t=N7T8https://blog.csdn.net/qq_27158179/article/details/136234296petalinux_zynq7 C语言驱动DAC以及ADC模块之二:petalinuxicon-default.png?t=N7T8https://blog.csdn.net/qq_27158179/article/details/136236138petalinux_zynq7 C语言驱动DAC以及ADC模块之三:实现C语言API并编译出库被python调用icon-default.png?t=N7T8https://blog.csdn.net/qq_27158179/article/details/136238093petalinux_zynq7 C语言驱动DAC以及ADC模块之四:python实现http_apiicon-default.png?t=N7T8https://blog.csdn.net/qq_27158179/article/details/136239572petalinux_zynq7 C语言驱动DAC以及ADC模块之五:nodejs+vue3实现web网页波形显示icon-default.png?t=N7T8https://blog.csdn.net/qq_27158179/article/details/136240421本文:ubuntu18搭建zynq qt开发环境。

0. 环境

mizar z7010
vivado 2018.3
petalinux 2018.3
ubuntu18

1. 获取linux-qt

1.1 下载

petalinux2018.3配套的qt版本是5.9.6。

下载地址:

https://download.qt.io/new_archive/qt/5.9/5.9.6/

下载
qt-opensource-linux-x64-5.9.6.run
qt-everywhere-opensource-src-5.9.6.tar.xz

1.2 安装

sudo chmod 777 qt-opensource-linux-x64-5.9.6.run
./qt-opensource-linux-x64-5.9.6.run

-> Next
-> 这里需要注册一个账号,并登录
-> Next
-> Installation Folder:    /home/xxjianvm/Qt5.9.6 -> Next
-> Select Components -> 勾选 Desktop gcc 64-bit,勾选 Qt Charts,勾选 Developer and Designer Tools -> Next
-> License Agreement -> Next
-> Install

1.3 界面 helloworld

通过开始界面打开 Qt Creator

1.3.1 创建工程

Qt Creator -> File -> New File or Project -> Application -> Qt Widgets Application -> choose

Location
-> Name:         hello_qt
-> Create in:     /home/xxjianvm/work/workspace_qt/
-> Next

Details
-> Class Information:    hello_qt -> Next

Summary -> Finish

1.3.2 编译

问题:Could not determine which "make" command to run
解决办法:sudo apt install make

问题:/bin/sh: 1: g++: not found
解决办法:sudo apt install g++

问题:/usr/bin/ld: cannot find -lGL
解决办法:find /usr/lib/ -name "libGL*" 
sudo ln -s /usr/lib/x86_64-linux-gnu/libGL.so.1 /usr/lib/libGL.so

1.3.2 修改界面

双击 hello_qt/Forms/hello_qt.ui

添加 Push Button -> 
-> objectName: Btn_Hello
-> 右键 -> Go to slot... -> clicked() -> OK

修改 hello_qt.cpp:
#include <QtWidgets/QMessageBox>

void hello_qt::on_Btn_Hello_clicked()
{
    QMessageBox msgBox;
    msgBox.setText("Hello");
    msgBox.exec();
}

编译运行

2. 安装sdk

前文petalinux篇生成了sdk。

/home/dell/work/mizar/linux_sd_adda/images/linux/sdk.sh


拷贝到

/home/xxjianvm/work/mizar/sdk.sh

安装

chmod +x sdk.sh
./sdk.sh


安装到

/opt/petalinux/2018.3

测试

source /opt/petalinux/2018.3/environment-setup-cortexa9hf-neon-xilinx-linux-gnueabi
arm-xilinx-linux-gnueabi-gcc -v

打开 qtcreator

source /opt/petalinux/2018.3/environment-setup-cortexa9hf-neon-xilinx-linux-gnueabi
/home/xxjianvm/Qt5.9.6/Tools/QtCreator/bin/qtcreator

注意打开qtcreator前需要source SDK的交叉编译环境。 

3. 添加Kit

Qt Creator -> Tools -> Options -> Build & Run

3.1 Compilers

-> Build & Run -> Compilers -> Manual -> C -> Add -> GCC -> C
    -> Name:            arm-xilinx-linux-gnueabi-gcc
    -> Compiler path:    /opt/petalinux/2018.3/sysroots/x86_64-petalinux-linux/usr/bin/arm-xilinx-linux-gnueabi/arm-xilinx-linux-gnueabi-gcc
-> Kits -> Compilers -> Manual -> C++ -> Add -> GCC -> C++
    -> Name:            arm-xilinx-linux-gnueabi-g++
    -> Compiler path:    /opt/petalinux/2018.3/sysroots/x86_64-petalinux-linux/usr/bin/arm-xilinx-linux-gnueabi/arm-xilinx-linux-gnueabi-g++

3.2 Debuggers

-> Build & Run -> Debuggers -> Manual -> Add -> 
    -> Name:    arm-xilinx-linux-gnueabi-gdb
    -> Path:    /opt/petalinux/2018.3/sysroots/x86_64-petalinux-linux/usr/bin/arm-xilinx-linux-gnueabi/arm-xilinx-linux-gnueabi-gdb

3.3 Qt Versions


-> Build & Run -> Qt Versions -> Manual -> Add -> 
    -> Version name:    Qt %{Qt:Version} (zynq7)
    -> qmake location:    /opt/petalinux/2018.3/sysroots/x86_64-petalinux-linux/usr/bin/qt5/qmake

3.4 Kits


-> Build & Run -> Kits -> Manual -> Add
    -> Name:    zynq7
    -> Sysroot:            /opt/petalinux/2018.3/sysroots/cortexa9hf-neon-xilinx-linux-gnueabi
    -> Compiler C:        arm-xilinx-linux-gnueabi-gcc
    -> Compiler C++:    arm-xilinx-linux-gnueabi-g++
    -> Debugger:        arm-xilinx-linux-gnueabi-gdb
    -> Qt version:        Qt 5.9.6 (zynq7)


4. 界面 helloworld

通过开始界面打开 Qt Creator

4.1 创建工程

Qt Creator -> File -> New File or Project -> Application -> Qt Widgets Application -> choose

Location
-> Name:         hello2_qt
-> Create in:     /home/xxjianvm/work/workspace_qt/
-> Next

Kits ->
-> 全选 -> Next

Build System:
-> Build System: qmake -> Next

Details
-> Class Information:    hello2_qt -> Next

-> Finish

4.2 修改界面

双击 helloworld_ui/Forms/hello_qt.ui

添加 Push Button -> 
-> objectName: Btn_Hello
-> 右键 -> Go to slot... -> clicked() -> OK

修改 hello2_qt.cpp:
#include <QtWidgets/QMessageBox>

void hello2_qt::on_Btn_Hello_clicked()
{
    QMessageBox msgBox;
    msgBox.setText("Hello.");
    msgBox.exec();
}

4.3 编译

左下角可以切换kit,切换后编译。可以分别编译出本机可以运行的程序,和zynq运行的。

4.4 运行[ZYNQ]

拷贝
/home/xxjianvm/work/workspace_qt/build-hello2_qt-zynq7-Debug/hello2_qt
到板子上的
/root/hello2_qt

配置QT程序的启动的方式 
(如果没有配置X11,环境变量使用export QT_QPA_PLATFORM=linuxfb)
export DISPLAY=:0.0
export QT_QPA_PLATFORM=linuxfb
chmod +x hello2_qt
./hello2_qt

5. adda_qt

5.1 打开 qtcreator

source /opt/petalinux/2018.3/environment-setup-cortexa9hf-neon-xilinx-linux-gnueabi
/home/xxjianvm/Qt5.9.6/Tools/QtCreator/bin/qtcreator


5.2 创建工程

Qt Creator -> File -> New File or Project -> Application -> Qt Widgets Application -> choose

Location
-> Name:         adda_qt
-> Create in:     /home/xxjianvm/work/workspace_qt/
-> Next

Kits ->
-> 全选 -> Next

Build System:
-> Build System: qmake -> Next

Details
-> Class Information:    adda_qt -> Next

-> Finish

5.3 添加模块

修改 adda_qt.pro
添加:
QT       += widgets
QT       += charts

5.4. 修改界面


双击 adda_qt/Forms/adda_qt.ui

采样频率:
添加 Label -> text: frequency: 
添加 Line Edit ->
    -> objectName: LEdit_AdcFrequency

采样长度:
添加 Line Edit ->
-> objectName: LEdit_AdcLength


采样配置:
添加 Push Button -> 
-> objectName: Btn_AdcSample
-> text:        AdcStart
-> 右键 -> Go to slot... -> clicked() -> OK

采样开始:
添加 Push Button -> 
-> objectName: Btn_AdcDataRequest
-> text:        AdcStart
-> 右键 -> Go to slot... -> clicked() -> OK

图表
添加 Containers 的 Widget 到窗口 -> 
-> objectName: Chart_data
-> 右键 widget -> promote to...
-> Promoted class name:    QChartView 
-> Add -> Promote


5.5 添加源码


/home/xxjianvm/work/mizar/code/adda.c
/home/xxjianvm/work/mizar/code/adda.h
拷贝到
/home/xxjianvm/work/workspace_qt/adda_qt/adda.cpp
/home/xxjianvm/work/workspace_qt/adda_qt/adda.h

5.6 修改源码

5.6.1 adda_qt.h

#ifndef ADDA_QT_H
#define ADDA_QT_H

#include <QMainWindow>
#include <QtCharts>
QT_CHARTS_USE_NAMESPACE

namespace Ui {
class adda_qt;
}

class adda_qt : public QMainWindow
{
    Q_OBJECT

public:
    explicit adda_qt(QWidget *parent = 0);
    ~adda_qt();

private slots:
    void on_Btn_DataRequest_clicked();

    void on_Btn_AdcConfig_clicked();

    void timer1_period();

private:
    Ui::adda_qt *ui;
};

#endif // ADDA_QT_H

5.6.2 adda_qt.cpp

#include "adda_qt.h"
#include "ui_adda_qt.h"
#include "adda.h"


QChart* m_chart;
QLineSeries* m_lineSeries_1;
QList<QPointF> listForChartLine_1;
QList<QPointF> listForChartLineHistory_1;
int AXIS_MAX_X = 300;

adda_qt::adda_qt(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::adda_qt)
{
    ui->setupUi(this);


    m_chart = new QChart();
    m_lineSeries_1 = new QLineSeries();
    m_lineSeries_1->setName("ch1");
    ui->Chart_data->setChart(m_chart);  // 将图表绑定到视图


    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(timer1_period()));
    timer->start(1000);
}

adda_qt::~adda_qt()
{
    delete ui;
}
bool flag_RequestDataStart = false;
void adda_qt::on_Btn_DataRequest_clicked()
{
    setbuf(stdout,NULL);
    if(flag_RequestDataStart){
        flag_RequestDataStart = false;
        ui->Btn_DataRequest->setText("AdcStart");
        printf("[on_Btn_DataRequest_clicked]start");
    }
    else{
        flag_RequestDataStart = true;
        ui->Btn_DataRequest->setText("AdcStop");
        printf("[on_Btn_DataRequest_clicked]stop");
        demo_dac_sin();
    }
}

uint32_t AdcParam_SampleFrequency = 100000;
uint32_t AdcParam_SampleLength = 100;
void adda_qt::on_Btn_AdcConfig_clicked()
{
    setbuf(stdout,NULL);
    AdcParam_SampleFrequency = ui->LEdit_AdcFrequency->text().toInt();
    AdcParam_SampleLength = ui->LEdit_AdcLength->text().toInt();
    printf("[on_Btn_AdcConfig_clicked]AdcParam_SampleFrequency = %d\r\n", AdcParam_SampleFrequency);
    printf("[on_Btn_AdcConfig_clicked]AdcParam_SampleLength = %d\r\n", AdcParam_SampleLength);
}
void adda_qt::timer1_period(){
    if(flag_RequestDataStart){
        printf("ticks");

        // demo
//        printf("listForChartLINE1.size() = %d\r\n", listForChartLine_1.size());
//        if(listForChartLine_1.size() >= AXIS_MAX_X){
//            listForChartLine_1.removeAt(0);
//        }
//        double value = sin(static_cast<double>(0.5f * listForChartLineHistory_1.size()));
//        int current_size1 = listForChartLineHistory_1.size();
//        listForChartLineHistory_1.append(QPointF(current_size1, value));

        //require adc data
        // init
        adda_open();
        // 设置采样频率
        adda_AdcSetSampleFrequency(AdcParam_SampleFrequency);
        // 开始采样
        uint8_t adc_buff[10240];
        uint16_t adc_buff_length = AdcParam_SampleLength;
        adda_AdcSampleData(adc_buff, adc_buff_length);
        // close
        adda_close();
        // 打印结果
//        printf("adc_buff[%d]: ", adc_buff_length);
//        for(int i =0;i<adc_buff_length;i++){
//            printf("%02X ", adc_buff[i]);
//        }
//        printf("\r\n");
        for (int i = 0; i < adc_buff_length; i++)
        {
            double ch1_value = adc_buff[i];
            int current_size1 = listForChartLineHistory_1.size();
            listForChartLineHistory_1.append(QPointF(current_size1, ch1_value));
        }



        listForChartLine_1.clear();
        if(listForChartLineHistory_1.size() <= AXIS_MAX_X){
            listForChartLine_1.append(listForChartLineHistory_1);
        }
        else{
            long long listForChartLineHistory_1_size = listForChartLineHistory_1.size();
            for(int i = 0; i < AXIS_MAX_X; i++){
                listForChartLine_1.append(listForChartLineHistory_1[listForChartLineHistory_1_size - AXIS_MAX_X + i]);
            }
        }

        m_lineSeries_1 = new QLineSeries();
        m_lineSeries_1->append(listForChartLine_1);//在serial中添加数据
        m_lineSeries_1->setName("test1");

        m_chart = new QChart();
        //m_chart->removeAllSeries(); //清除即可,重要操作,QChart刷新的必要操作
        m_chart->addSeries(m_lineSeries_1);   // 将系列添加到图表
        m_chart->createDefaultAxes();       // 基于已添加到图表的 series 来创建默认的坐标轴

        ui->Chart_data->setChart(m_chart);  // 将图表绑定到视图
    }
}

5.7 编译

5.7.1 上位机运行测试界面

切换KIT

编译

运行查看界面

5.7.2 交叉编译出ZYNQ版本

 切换KIT

 编译

6. 板子运行测试

 用winscp拷贝adda_qt到板子上 

export DISPLAY=:0.0
export QT_QPA_PLATFORM=linuxfb
chmod +x adda_qt
./adda_qt

参考

[1]【正点原子FPGA连载】第十章Petalinux构建Qt和OpenCV交叉编译开发环境 摘自【正点原子】DFZU2EG_4EV MPSoC之嵌入式Linux开发指南,https://blog.csdn.net/weixin_55796564/article/details/128615252
 

好了,本系列暂告一段落。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1464448.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

C# .Net 发布后,把dll全部放在一个文件夹中,让软件目录更整洁

PublishFolderCleaner – Github 测试环境: .Net 8 Program.cs 代码 // https://github.com/dotnet-campus/dotnetcampus.DotNETBuildSDK/tree/master/PublishFolderCleanerusing System.Diagnostics; using System.Text;// 名称, 不用写 .exe var exeName "AbpDemo&…

.Net8.0 WebApi 发布到 IIS 详细步骤

.NET 8 是微软于2021年8月24日宣布的下一代编程语言和框架&#xff0c;它是 .NET 的一部分&#xff0c;与 C# (Common Language Infrastructure) 紧密集成。.NET 8 引入了许多新功能&#xff0c;如原生编译、值类型 (Value Types)、结构化并发 (structured concurrency) 和快速…

Window部署Exceptionless

Exceptionless Elasticsearch 版本&#xff1a; Exceptionless&#xff1a;8.1.0 Elasticsearch&#xff1a;7.17.5 JDK&#xff1a;11.0.10 目录 一、Elasticsearch运行 二、 Exceptionless 一、Elasticsearch运行 bin目录下elasticsearch.bat 直接运行 访问 http://lo…

【AIGC】基于深度学习的图像生成与增强技术

摘要&#xff1a; 本论文探讨基于深度学习的图像生成与增强技术在图像处理和计算机视觉领域的应用。我们综合分析了主流的深度学习模型&#xff0c;特别是生成对抗网络&#xff08;GAN&#xff09;和变分自编码器&#xff08;VAE&#xff09;等&#xff0c;并就它们在实际应用中…

Python Web开发记录 Day2:CSS

名人说&#xff1a;莫道桑榆晚&#xff0c;为霞尚满天。——刘禹锡&#xff08;刘梦得&#xff0c;诗豪&#xff09; 创作者&#xff1a;Code_流苏(CSDN)&#xff08;一个喜欢古诗词和编程的Coder&#x1f60a;&#xff09; 目录 二、CSS1、CSS-初始入门①快速了解②CSS应用方式…

(3)llvm ir转换过程

&#xff08;1&#xff09;DAG Lowering 输入的IR转换成SelectionDAG的过程被称作lowering 就是把llvm ir转成这种 &#xff08;2&#xff09;DAG legalization "DAG legalization"&#xff08;有向无环图合法化&#xff09;是编译器后端&#xff0c;特别是在LLVM中…

React18源码: reconciler执行流程

reconciler执行流程 1 &#xff09;概述 此处先归纳一下react-reconciler包的主要作用&#xff0c;将主要功能分为4个方面&#xff1a; 输入&#xff1a;暴露api函数&#xff08;如&#xff1a;scheduleUpdateOnFiber&#xff09;, 供给其他包&#xff08;如react包&#xff0…

《数字通信世界》杂志社数字通信世界杂志社2024年第1期目录

技术研究 基于B/S架构的海量空间数据并行上传方法研究 刘春伟; 1-348 城市轨道交通工程建设安全数据融合路径及方法 刘魁刚;张瑜;毕鹏;赵智涛;王春勇; 4-6 信息化背景下智慧社区的建设研究 崔宏尧;刘敏智;于志宏;李杰;殷秀莉; 7-9 基于数字孪生技术的工业机器人…

通俗易懂理解G-GhostNet轻量级神经网络模型

一、参考资料 原始论文&#xff1a;[1] IJCV22 | 已开源 | 华为GhostNet再升级&#xff0c;全系列硬件上最优极简AI网络 二、G-GhostNet相关介绍 G-GhostNet 又称为 GhostNetV1 的升级版&#xff0c;是针对GPU优化的轻量级神经网络。 1. 摘要 GhostNetV1 作为近年来最流行…

力扣随笔之通过删除字母匹配到字典里最长单词(中等524)

思路&#xff1a;根据题意有两个问题待解决 1、s字符串中是否可以通过删减得到该英语词语 2、如何找到长度最长且字母序最小的字符串 针对第二个问题可以对词典dictionary进行预处理&#xff1a;根据长度降序和字母序升序来排序 针对第一个问题可以初始化两个指针i&#xff0c;…

Leetcode日记 889. 根据前序和后序遍历构造二叉树

Leetcode日记 889. 根据前序和后序遍历构造二叉树 给定两个整数数组&#xff0c;preorder 和 postorder &#xff0c;其中 preorder 是一个具有 无重复 值的二叉树的前序遍历&#xff0c;postorder 是同一棵树的后序遍历&#xff0c;重构并返回二叉树。 如果存在多个答案&#…

设计模式之委派模式

文章目录 前言正文一、生活中的例子二、Java代码实现2.1 类设计2.2 代码实现2.2.1 Employee2.2.2 ArchitectureDesignEmployer2.2.3 BackEmployer2.2.4 FrontEmployer2.2.5 Leader2.2.6 EmployeeStrongPointEnum2.2.7 Boss 2.3 测试2.3.1 Client2.3.2 测试结果 三、委派模式的优…

Hackme 1

信息收集 Nmap部分 存活扫描&#xff1a; └─# nmap -sn 192.168.10.1/24 Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-02-20 15:00 CST Nmap scan report for 192.168.10.1 (192.168.10.1) Host is up (0.00012s latency). MAC Address: 00:50:56:C0:00:08 (VMwar…

【vue js】将数组元素,按照2个一组,重组为2维数组

实现效果&#xff1a; 要实现上述&#xff0c;2张图片为一个走马灯的内容&#xff0c;而后端传回的数据是一个数组。我采用的是将数据重组为2维数组的方法。 因为没有强制要求展示顺序&#xff0c;我采用将首尾组合的方式组成一个数组元素&#xff1b; 首先判断原始数据长度的…

onnx 1.16 doc学习笔记四:python API-If和Scan

onnx作为一个通用格式&#xff0c;很少有中文教程&#xff0c;因此开一篇文章对onnx 1.16文档进行翻译与进一步解释&#xff0c; onnx 1.16官方文档&#xff1a;https://onnx.ai/onnx/intro/index.html](https://onnx.ai/onnx/intro/index.html)&#xff0c; 如果觉得有收获&am…

$attrs

一、概念 vue官网定义如下: 包含了父作用域中不作为 prop 被识别 (且获取) 的 attribute 绑定 (class 和 style 除外)。当一个组件没有声明任何 prop 时,这里会包含所有父作用域的绑定 (class 和 style 除外),并且可以通过v-bind="$attrs"传入内部组件——在创建…

【高德地图】Android高德地图控件交互详细介绍

&#x1f4d6;第5章 与地图控件交互 ✅控件交互&#x1f9ca;缩放按钮&#x1f9ca;指南针&#x1f9ca;定位按钮&#x1f9ca;地图Logo ✅手势交互&#x1f9ca;缩放手势&#x1f9ca;滑动手势&#x1f9ca;旋转手势&#x1f9ca;倾斜手势&#x1f9ca;指定屏幕中心点的手势操…

无线传感器网络简单介绍

&#xff08;本文为简单介绍&#xff0c;内容来源自网络&#xff09; 无线传感器网络&#xff08;Wireless Sensor Networks&#xff09;是一种创新的传感器网络架构&#xff0c;具有广泛的应用前景和潜力。与传统的有限传感器网络不同&#xff0c;无线传感器网络克服了节点数…

在苹果电脑MAC上安装Windows10(双系统安装的详细图文步骤教程)

在苹果电脑MAC上安装Windows10&#xff08;双系统安装的详细图文步骤教程&#xff09; 一、准备工作准备项1&#xff1a;U盘作为系统安装盘准备项2&#xff1a;您需要安装的系统镜像 二、启动转换助理步骤1&#xff1a;找到启动转换助理步骤2&#xff1a;启动转换助理步骤3&…