用于树莓派的数据采集卡MCC简介及代码_树莓派 4b如何接 mcc118-程序员宅基地

技术标签: 算法  python  硬件  Linux  树莓派  MCC  数据采集  

树莓派(Raspberry)官网https://www.raspberrypi.org/

树莓派在某些小规模的数据采集和显示方面具有笔记本等大型设备所不具有的小巧灵活特性,入门树莓派同时相当于入门linux系统的小型计算机,树莓派的学习应用为后面的嵌入式开发也提供有必要的基础和储备,树莓派用于工业的flagship应用当属数据采集,本文主要介绍使用MCC配合树莓派进行数据的采集,同时使用在树莓派的Python程序来进行数据采集和显示。

MCC介绍

主要的MCC说明信息链接:https://mccdaq.github.io/daqhats/overview.html#functional-block-diagram

MCC的数据采集介绍:https://shumeipai.nxez.com/2018/12/28/raspberry-pi-and-mcc118-for-data-collection.html

树莓派上的Python程序实现数据采集

其相应的参考代码可以通过github 查询MCC工程,里面有详细的不同情况代码,其中实时采集的参考代码如下:

方便用于实时采集的MCC数据采集,显示:

#!/usr/bin/env python3
"""
    MCC 118 Control Panel

    Purpose:
        Display the MCC 118 input voltages

    Description:
        This app reads and displays the input voltages.
"""
from daqhats import hat_list, mcc118, HatIDs, HatError
from tkinter import *
from tkinter import messagebox
import tkinter.font
# matplotlib command
import matplotlib

import matplotlib.pyplot as plt

import numpy as np
# matplotlib command

class ControlApp:

    def __init__(self, master):
        self.master = master
        master.title("MCC 118 Control Panel")

        # Initialize variables
        self.device_open = False
        self.open_address = 0
        self.board = None

        # GUI Setup

        self.BOLD_FONT = tkinter.font.Font(
            family=tkinter.font.nametofont("TkDefaultFont")["family"],
            size=tkinter.font.nametofont("TkDefaultFont")["size"],
            weight="bold")

        # Create and organize frames
        self.top_frame = LabelFrame(master, text="Select Device")
        self.top_frame.pack(side=TOP, expand=False, fill=X)

        self.bottom_frame = LabelFrame(master, text="Analog Inputs")
        self.bottom_frame.pack(side=BOTTOM, expand=True, fill=BOTH)

        # Create widgets

        self.dev_label = Label(self.top_frame, text="MCC 118 address:")
        self.dev_label.grid(row=0, column=0)

        self.open_button = Button(self.top_frame, text="Open", width=6, command=self.pressedOpenButton)

        # Get list of MCC 118 devices for the device list widget
        self.addr_list = self.listDevices()

        if len(self.addr_list) == 0:
            self.device_lister = Label(self.top_frame, text="None found")
            self.open_button.config(state=DISABLED)
        else:
            self.device_variable = StringVar(self.top_frame)
            self.device_variable.set(self.addr_list[0])
            self.device_lister = OptionMenu(self.top_frame, self.device_variable, *self.addr_list)

        self.device_lister.grid(row=0, column=1)
        self.open_button.grid(row=0, column=2)

        self.checkboxes = []
        self.check_values = []
        self.channel_labels = []
        self.voltages = []
        for index in range(mcc118.info().NUM_AI_CHANNELS):
            # Checkboxes
            self.check_values.append(IntVar())
            self.checkboxes.append(Checkbutton(self.bottom_frame, variable=self.check_values[index], command=lambda index=index:self.pressedCheck(index)))
            self.checkboxes[index].grid(row=index, column=0)
            self.checkboxes[index].select()
            # Labels
            self.channel_labels.append(Label(self.bottom_frame, text="Ch {}".format(index), font=self.BOLD_FONT))
            self.channel_labels[index].grid(row=index, column=1)
            self.channel_labels[index].grid_configure(sticky="W")
            # Voltages
            self.voltages.append(Label(self.bottom_frame, text="0.000", font=self.BOLD_FONT))
            self.voltages[index].grid(row=index, column=2)
            self.voltages[index].grid_configure(sticky="E")

            self.bottom_frame.grid_rowconfigure(index, weight=1)

        self.bottom_frame.grid_columnconfigure(1, weight=1)
        self.bottom_frame.grid_columnconfigure(2, weight=1)

        self.bottom_frame.bind("<Configure>", self.resizeText)

        # Disable widgets until a device is opened
        self.disableControls()

        master.protocol('WM_DELETE_WINDOW', self.close) # exit cleanup

        icon = PhotoImage(file='/usr/share/mcc/daqhats/icon.png')
        master.tk.call('wm', 'iconphoto', master._w, icon)

    def resizeText(self, event):
        new_size = -max(12, int(event.height / 12))
        self.BOLD_FONT.configure(size=new_size)

    def pressedCheck(self, index):
        if self.check_values[index].get() == 0:
            self.channel_labels[index].config(state=DISABLED)
            self.voltages[index].config(state=DISABLED)
        else:
            self.channel_labels[index].config(state=NORMAL)
            self.voltages[index].config(state=NORMAL)

    def disableControls(self):
        # Enable the address selector
        self.device_lister.config(state=NORMAL)
        # Disable the board controls
        for child in self.bottom_frame.winfo_children():
            child.config(state=DISABLED)

    def enableControls(self):
        # Disable the address selector
        self.device_lister.config(state=DISABLED)
        # Enable the board controls
        for child in self.bottom_frame.winfo_children():
            child.config(state=NORMAL)

    def listDevices(self):
        self.dev_list = hat_list(HatIDs.MCC_118)
        addr_list = ["{}".format(dev.address) for dev in self.dev_list]
        return addr_list

    def openDevice(self, address):
        try:
            self.board = mcc118(address)
        except:
            return False
        else:
            return True

    def closeDevice(self):
        self.board = None

    def updateInputs(self):
        if self.device_open:
            for channel in range(mcc118.info().NUM_AI_CHANNELS):
                if self.check_values[channel].get() == 1:
                    value = self.board.a_in_read(channel)
                    self.voltages[channel].config(text="{:.3f}".format(value))
                    # corresponing with the channel 1
                    #t = np.arange(1, 10000, 1)
                    s=self.board.a_in_read(1)
                    fig, ax = plt.subplots()

ax.plot( s)




            # schedule another update in 200 ms
            self.master.after(200, self.updateInputs)

    # Event handlers
    def pressedOpenButton(self):
        if self.open_button.cget('text') == "Open":
            # Open the selected device
            address = int(self.device_variable.get())
            if self.openDevice(address):
                self.device_open = True
                self.open_address = address

                self.enableControls()

                # Periodically read the inputs and update controls
                self.updateInputs()

                self.open_button.config(text="Close")
            else:
                messagebox.showerror("Error", "Could not open device.")
        else:
            if self.device_open:
                self.closeDevice()
                self.device_open = False
            self.open_button.config(text="Open")
            self.disableControls()

    def close(self):
        self.master.destroy()


root = Tk()
app = ControlApp(root)
root.mainloop()

该文主要用于MCC的数据采集入门,通过树莓派结合MCC,Python 实现数据的采集,处理,显示等基础功能 

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/soga235/article/details/108864811

智能推荐

机器学习模型评分总结(sklearn)_model.score-程序员宅基地

文章浏览阅读1.5w次,点赞10次,收藏129次。文章目录目录模型评估评价指标1.分类评价指标acc、recall、F1、混淆矩阵、分类综合报告1.准确率方式一:accuracy_score方式二:metrics2.召回率3.F1分数4.混淆矩阵5.分类报告6.kappa scoreROC1.ROC计算2.ROC曲线3.具体实例2.回归评价指标3.聚类评价指标1.Adjusted Rand index 调整兰德系数2.Mutual Informa..._model.score

Apache虚拟主机配置mod_jk_apache mod_jk 虚拟-程序员宅基地

文章浏览阅读344次。因工作需要,在Apache上使用,重新学习配置mod_jk1. 分别安装Apache和Tomcat:2. 编辑httpd-vhosts.conf: LoadModule jk_module modules/mod_jk.so #加载mod_jk模块 JkWorkersFile conf/workers.properties #添加worker信息 JkLogFil_apache mod_jk 虚拟

Android ConstraintLayout2.0 过度动画MotionLayout MotionScene3_android onoffsetchanged-程序员宅基地

文章浏览阅读335次。待老夫kotlin大成,扩展:MotionLayout 与 CoordinatorLayout,DrawerLayout,ViewPager 的 交互众所周知,MotionLayout 的 动画是有完成度的 即Progress ,他在0-1之间变化,一.CoordinatorLayout 与AppBarLayout 交互时,其实就是监听 offsetliner 这个 偏移量的变化 同样..._android onoffsetchanged

【转】多核处理器的工作原理及优缺点_多核处理器怎么工作-程序员宅基地

文章浏览阅读8.3k次,点赞3次,收藏19次。【转】多核处理器的工作原理及优缺点《处理器关于多核概念与区别 多核处理器工作原理及优缺点》原文传送门  摘要:目前关于处理器的单核、双核和多核已经得到了普遍的运用,今天我们主要说说关于多核处理器的一些相关概念,它的工作与那里以及优缺点而展开的分析。1、多核处理器  多核处理器是指在一枚处理器中集成两个或多个完整的计算引擎(内核),此时处理器能支持系统总线上的多个处理器,由总..._多核处理器怎么工作

个人小结---eclipse/myeclipse配置lombok_eclispe每次运行个新项目都需要重新配置lombok吗-程序员宅基地

文章浏览阅读306次。1. eclipse配置lombok 拷贝lombok.jar到eclipse.ini同级文件夹下,编辑eclipse.ini文件,添加: -javaagent:lombok.jar2. myeclipse配置lombok myeclipse像eclipse配置后,定义对象后,直接访问方法,可能会出现飘红的报错。 如果出现报错,可按照以下方式解决。 ..._eclispe每次运行个新项目都需要重新配置lombok吗

【最新实用版】Python批量将pdf文本提取并存储到txt文件中_python批量读取文字并批量保存-程序员宅基地

文章浏览阅读1.2w次,点赞31次,收藏126次。#注意:笔者在2021/11/11当天调试过这个代码是可用的,由于pdfminer版本的更新,网络上大多数的语法没有更新,我也是找了好久的文章才修正了我的代码,仅供学习参考。1、把pdf文件移动到本代码文件的同一个目录下,笔者是在pycharm里面运行的项目,下图中的x1文件夹存储了我需要转换成文本文件的所有pdf文件。然后要在此目录下创建一个存放转换后的txt文件的文件夹,如图中的txt文件夹。2、编写代码 (1)导入所需库# coding:utf-8import ..._python批量读取文字并批量保存

随便推点

vite build-程序员宅基地

文章浏览阅读4.3k次。vite在开发阶段采用的是按需加载的方式,不会将所有文件打包。但是生产环境的部署是需要进行打包的,这里它使用的是rollup打包方式。对于代码切割的需求,使用原生动态导入,因此打包后支持新浏览器,对IE的兼容性不是很好,但是可以用对应的polyfill解决。使用esbuild来处理需要pre-undle的在cli.ts的build命令中引入build.ts调用doBuild方法,在这个方法中配置打包参数(input output plugin等)调用buildHtmlPlugin解析文件入口in_vite build

Scala:访问修饰符、运算符和循环_scala ===运算符-程序员宅基地

文章浏览阅读1.4k次。http://blog.csdn.net/pipisorry/article/details/52902234Scala 访问修饰符Scala 访问修饰符基本和Java的一样,分别有:private,protected,public。如果没有指定访问修饰符符,默认情况下,Scala对象的访问级别都是 public。Scala 中的 private 限定符,比 Java 更严格,在嵌套类情况下,外层_scala ===运算符

MySQL导出ER图为图片或PDF_数据库怎么导出er图-程序员宅基地

文章浏览阅读2.6k次,点赞7次,收藏19次。ER图导出为PDF或图片格式_数据库怎么导出er图

oracle触发器修改同一张表,oracle触发器中对同一张表进行更新再查询时,需加自制事务...-程序员宅基地

文章浏览阅读655次。CREATE OR REPLACE TRIGGER Trg_ReimFactBEFORE UPDATEON BP_OrderFOR EACH ROWDECLAREPRAGMA AUTONOMOUS_TRANSACTION;--自制事务fc varchar2(255);BEGINIF ( :NEW.orderstate = 2AND :NEW.TransState = 1 ) THENBEG..._oracle触发器更新同一张表

debounce与throttle区别及其应用场景_throttle和debounce应用在哪些场景-程序员宅基地

文章浏览阅读513次。目录概念debouncethrottle实现debouncethrottle应用场景debouncethrottle场景举例debouncethrottle概念debounce字面理解是“防抖”,何谓“防抖”,就是连续操作结束后再执行,以网页滚动为例,debounce要等到用户停止滚动后才执行,将连续多次执行合并为一次执行。throttle字面理解是“节流”,何谓“节流”,就是确保一段时..._throttle和debounce应用在哪些场景

java操作mongdb【超详细】_java 操作mongodb-程序员宅基地

文章浏览阅读526次。regex() $regex 正则表达式用于模式匹配,基本上是用于文档中的发现字符串 (下面有例子)注意:若未加 @Field("名称") ,则识别mongdb集合中的key名为实体类属性名。也可以对数组进行索引,如果被索引的列是数组时,MongoDB会索引这个数组中的每一个元素。也可以对整个Document进行索引,排序是预定义的按插入BSON数据的先后升序排列。save: 若新增数据的主键已经存在,则会对当前已经存在的数据进行修改操作。_java 操作mongodb