一、示波器软件(电脑端)
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)