您好!欢迎来到一线生活-深圳论坛
关注我们
扫码关注官方微信
手机版
手机扫描直接访问

Arduino 实例(二十九)使用python pyserial模块实现示波器功能

2023-2-19 23:00| 发布者: arrarpetahack| 查看: 459| 评论: 0

摘要: 1 电路连接示意图2 实物连接照片3 Python 程序import timeimport matplotlib.pyplot as pltfrom drawnow import *import serialval = cnt = 0port = serial.Serial('COM3', 115200, timeout=0.5)plt.ion()#c ...

1 电路连接示意图


Arduino 实例(二十九)使用python pyserial模块实现示波器功能

2 实物连接照片


Arduino 实例(二十九)使用python pyserial模块实现示波器功能

3 Python 程序

import timeimport matplotlib.pyplot as pltfrom drawnow import *import serialval = [ ]cnt = 0port = serial.Serial('COM3', 115200, timeout=0.5)plt.ion()#create the figure functiondef makeFig():    plt.ylim(-1023,1023)    plt.title('Osciloscope')    plt.grid(True)    plt.ylabel('ADC outputs')    plt.plot(val, 'ro-', label='Channel 0')    plt.legend(loc='lower right')while (True):    port.write(b's') #handshake with Arduino    if (port.inWaiting()):# if the arduino replies        value = port.readline()# read the reply        print(value)#print so we can monitor it        number = float(value) #convert received data to integer        print('Channel 0: {0}'.format(number))        # Sleep for half a second.        time.sleep(0.01)        val.append(int(number))        drawnow(makeFig)#update plot to reflect new data input        plt.pause(.000001)        cnt = cnt+1    if(cnt>50):        val.pop(0)#keep the plot fresh by deleting the data at position 0

4 Arduino程序

int sensorpin = A0;void setup() {  // initialize serial communication at 115200 bits per second to match that of the python script:  Serial.begin(115200);}void loop() {  // read the input on analog pin 0  float sensorValue = analogRead(sensorpin);  byte data = Serial.read();  if (data == 's')  {    Serial.println(sensorValue);    delay(10);        // delay in between reads for stability  }}

5 效果


Arduino 实例(二十九)使用python pyserial模块实现示波器功能

6 视频效果

Ardrino借助Python做一个示波器 - 西瓜视频 (ixigua.com)


鲜花

握手

雷人

路过

鸡蛋
推荐阅读
华钠新材董事长蔡伟华:储能的未来藏于固态
在距离比亚迪总部3公里之外的马峦创谷科技企业孵化器园区内深圳华钠新材有限责任公司
我的深圳故事|英国数学教师的“深圳课堂”
她不远万里从英国来到深圳教书在这座朝气蓬勃充满无限可能的城市实现了自己的梦想记者
华为Pura先锋盛典及鸿蒙智行新品发布会
华为Pura先锋盛典及鸿蒙智行新品发布会
深圳五大科创平台开放共享
3月18日,深圳市国资委举办“国企民企同频共振 智汇科技共赢未来”科技创新对接会,现
英国老人从英国来深教书,“这座城市朝气蓬
年过七旬的老外不远万里从英国来到深圳教书,在这座朝气蓬勃、充满无限可能的城市实现
“上午发论文,下午就有投资人找上门”
3月18日,南方财经全媒体刊发文章《穿透巴斯德象限:“四链”融合与深圳的“创新溢价

相关分类

热点帖子
久坐久站易生痔疮,试试这几个方法告别烦恼
bigsilverrabbit久坐久站易生痔疮,试试这几个方法告别烦恼
在这个快节奏的时代,无论是办公室白领还是生产线工人,或者是开网约车的司机等,久坐
得了痔疮怎么办有凸起的小肉球
bigsilverrabbit得了痔疮怎么办有凸起的小肉球
在这个快节奏的时代,久坐不动、饮食不规律等生活习很容易引起健康问题,其中,痔疮成
痔疮是什么样子的有什么症状表现
bigsilverrabbit痔疮是什么样子的有什么症状表现
痔疮,作为普外科常见的良性疾病,其发病率相当高,尤其在年轻人中更为普遍。俗话说“
肛门口有个肉球突出是怎么回事?可能是这几个原因
bigsilverrabbit肛门口有个肉球突出是怎么回事?可能是这几
在日常生活中,不少人可能会遇到这样的尴尬情况:肛门口突然出现一个肉球,不仅影响日
外痔疮肉球怎么消除最快方法
bigsilverrabbit外痔疮肉球怎么消除最快方法
外痔疮肉球,是痔疮的一种表现形式,主要表现为肛门边缘的静脉丛扩张或血栓形成,形成
联系我们

免费联系电话

400-8855-271

客服QQ:2524604571

服务时间:周一到周日8:00-23:30

关注我们
  • 关注官方微信

  • 手机APP