(Python + micro python)树莓派pico示波器

一、示波器软件(电脑端)

from serial import *
import matplotlib.pyplot as plt
import time

#########   端口设置   ###########
PORT = "COM7"
##################################
print("Loading...")
x_points = ["0"]
y_points = ["0"]
t_0 = time.time()   #新建时间戳

plt.plot(x_points,y_points)

ser = Serial(PORT,9600)     #波特率默认9600
while True:
    line = ser.readline().decode('utf-8').rstrip()      #获取串口信息
    t_1 = time.time()
    x_points.append(round(t_1 - t_0,2))
    y_points.append(line)
    print(line)
    nac = round(t_1 - t_0,2)         #时间差
    plt.clf()
    plt.plot(x_points,y_points)
    plt.xlim(nac - 3*len(x_points),nac + 3*len(x_points))   #波形图x轴取值
    plt.pause(0.01)

ser.close()
plt.show()

二、main.py(树莓派pico端)

from machine import *
from utime import *

ADC_0 = ADC(26)
#ADC_1 = ADC(27)
#ADC_2 = ADC(28)
logicIO = Pin(16,Pin.IN,Pin.PULL_DOWN)
ExitPin = Pin(15,Pin.IN,Pin.PULL_DOWN)
led = Pin(25,Pin.OUT)

led.value(1)
def ShowWave():
    while True:
        res_u16 = ADC_0.read_u16()
        res = res_u16 * 3.3 / 65535
        print(res)
        sleep_ms(200)
        if ExitPin.value() == 1:
            break

        
def ShowLogic():
    while True:
        print(logicIO.value())

#######################################
ShowWave()          #示波器
#ShowLogic()        #逻辑分析仪
#######################################

led.value(0)

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值