Categories
python

heartpy

heartpy python 心电数据通用库

ecg python 处理 心跳信号 python心电图

https://blog.51cto.com/u_12195/6852475

Categories
python

树莓派 香橙派 PWM问题

查看GPIO引脚

gpio readall

用python调用PWM有两种方法

1.RPi.GPIO

import RPi.GPIO  as GPIO


GPIO.setmode(GPIO.BCM)

GPIO.setup(18,GPIO.OUT) #设置引脚为输出
pwm = GPIO.PWM(18,100) #只有12脚 和 18脚 支持硬件PWM   100为100hz
pwm.start(50) #占空比为50并输出

pwm.changeDutyCycle(20) #改变占空比
pwm.stop() #停止PWM波形输出

2OPI.GPIO

PWM is created in the form of an object.

1. First set up OPi.GPIO and create the object

    .. code:: python

       import OPi.GPIO as GPIO
       PWM_Class = GPIO.PWM(PWM_chip, PWM_pin, frequency_Hz, Duty_Cycle_Percent)


一般PWM_chip 为0 第一块 可以通过
 ls -l /sys/class/pwm/ 查看 一般返回 pwmchip0

PWM_pin 就是引脚了 


    Note currently you do not need to specify setmode before creating the class as for a GPIO
    only the PWM_chip number and the PWM_pin.
    The reson for this and how to find what they are is explained in the sysfs PWM section.

2. Begin the PWM cycle

    .. code:: python

        PWM_Class.start_pwm()

3. Change PWM duty Cycle

    .. code:: python
        PWM_Class.duty_cycle(50)

    Note this changes the Duty cycle to 50%

4. Change the frequency

    .. code:: python
        PWM_Class.change_frequency(500)

    Note this changes the Frequency to 500Hz

5. Stop the PWM device

    .. code:: python
        PWM_Class.stop_pwm()

    Note this stops the signal by setting the duty cycle to 0%

6. Change the Polarity of the signal

    .. code:: python
        PWM_Class.pwm_polarity()

    Note this changes swaps the on-off times. For example a duty cycle set to 75% before
    this will result in the signal being on 75% and off 25% of the time. After this is
    called it would be on 25% and off 75%.

7. Remove PWM Object

    .. code:: python
        PWM_Class.pwm_close()

3.wiringpi

import wiringpi

pwm0 =  wiringpi.GPIO(0)        
pwm0.pinMode(1,pwm0.PWM_OUTPUT)
pwm0.pwmSetMode(pwm0.PWM_MODE_MS)
pwm0.pwmSetClock(25)
pwm0.pwmWrite(1,self.brightness)




import wiringpi

PWM_OUTPUT  = 2
PWM_PIN = 1  #指定第二个PWM接口

# 初始化
wiringpi.wiringPiSetup()
wiringpi.pinMode(PWM_PIN, PWM_OUTPUT)  #初始化第二个PWM接口 18  

wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)  
#设置PWM工作模式 有两个值PWM_MODE_MS PWM_MODE_BAL
#一般选第一个  PWM_MODE_BAL or PWM_MODE_MS(平衡模式/占空比模式)

wiringpi.pwmSetRange(1024)  


#设置总周期默认1024 所以一个周期是 600khz/1024 约等于600hz

wiringpi.pwmSetClock(32)  
#设置分频 默认32 即600khz 总时钟频率是19.2Mhz 

wiringpi.pwmWrite(PWM_PIN,0) #设置占空比 0~1024  512 为一半  
#0的话相当于写入全部低电平 没有波形输出

while 1:
    for bright in range(0, 1000):
        wiringpi.pwmWrite(PWM_PIN, bright)
        wiringpi.delay(1)
    for bright in range(1000, 0, -1):
        wiringpi.pwmWrite(PWM_PIN, bright)
        wiringpi.delay(1)
Categories
python

pyqt5 pyside6 切换

pyside6 导入文件

from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *

pyqt5 导入文件

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

切记pyqt5 与 pyside6 不能混用

Categories
python

PyQt5 QStackedWidget 使用方法

initialize sub component

self.Stack = QStackedWidget (self)
self.Stack.addWidget (self.stack1)
self.Stack.addWidget (self.stack2)
self.Stack.addWidget (self.stack3)

事件触发关联

self.leftlist.currentRowChanged.connect(self.display)

切换页面

def display(self,i):
    self.Stack.setCurrentIndex(i)
Categories
python

QT 使用图片作为背景

convertToQtFormat = QtGui.QImage(rgbImage.data, rgbImage.shape[1], rgbImage.shape[0], QImage.Format_RGB888)
									#在这里可以对每帧图像进行处理,
									image = convertToQtFormat.scaled(440, 330, Qt.KeepAspectRatio)
									self.video.setPixmap(QPixmap.fromImage(image))

rgbImage.data 是 python图片数组数据

所有组件都可以通过 setPixmap(QPixmap.fromImage(image)) 设置背景图像

import sysfrom PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow

class Ui_MainWindow(object):

def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(270, 180, 241, 101))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap(":/img/logo.png"))
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))

if __name__ == '__main__':import resource  
# 导入添加的资源(根据实际情况填写文件名)
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

设置icon

        self.pushButton_9.setIcon(QtGui.QIcon(QtGui.QPixmap("./resources/setting.png")))
self.pushButton_9.setIconSize(QtCore.QSize(30,30))
Categories
python

QT designer 使用

使用QT designer会生成一系列ui后缀文件

通过pyuic可以将ui文件转化为py文件

python -m PyQt5.uic.pyuic 1.ui -o 1.py
pyuic5 1.ui -o 1.py
pyside6-uic form.ui -o ui_form.py

把1.ui 转换为 1.py

class MainForm(QtWidgets.QMainWindow):
	def __init__(self,parent=None):
		super(MainForm,self).__init__(parent)
		__content = Ui_MainWindow.Ui_MainWindow()
		__content.setupUi(self)
		
	

if  __name__ == "__main__" :
	try: 
		print('start')
		__app = QtWidgets.QApplication(sys.argv) 
		__win = MainForm()
		__win .show()
		sys.exit(__app.exec_())
	except KeyboardInterrupt :
		print('destroy')

__content = Ui_MainWindow.Ui_MainWindow()

这段代码可以换成不同的UI generate的代码 就可以 切换ui文件 看效果

Categories
python

Pyqt 组件说明

Categories
python

python 简介

    Python是一种跨平台的计算机程序设计语言。 是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言。最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越多被用于独立的、大型项目的开发。

    python语言上分为python2,python3。当初因为语法方案问题,遂对该编程语言进行了分支。两种语言上语法略有差别,譬如python2支持函数执行可不带括号等。然而随着时代发展python2已经逐渐退出历史舞台,最新版的操作系统默认支持的就是python3。我们一般说的python指的就是python3了

    python执行需要python运行时环境。https://www.python.org/官网地址下载。因为python运行时环境需要按照自己的操作系统下载对应的安装包,换句话说通过python运行时环境去兼容不同的操作系统的资源接口,对上层语言级别的调用提供一致的屏蔽操作系统差异的函数与库。所以python能做到跨平台。

    python作为脚本语言(其实是编译、运行一体化),调试方便。而且和调用c的库相当方便,被调用也只需开一个进程执行python命令,所以亦被称为胶水语言(基本逻辑用python写,核心算法等用c的库)。