Python中PicoScope 2000系列示波器无法捕获Arduino输出方波信号问题排查
Python中PicoScope 2000系列示波器无法捕获Arduino输出方波信号问题排查
我正尝试用Python捕获Arduino输出的简单方波信号(10ms高电平、10ms低电平),信号接在PicoScope 2000系列的B通道,但完全看不到信号。我已经反复检查了设置,看起来都没问题。
我的代码如下:
from ctypes import CFUNCTYPE, POINTER, c_int16, c_uint32, c_byte import matplotlib.pyplot as plt import numpy as np from picosdk.ps2000 import ps2000 from picosdk.functions import assert_pico2000_ok from picosdk.functions import adc2mV from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY import time from picosdk.PicoDeviceEnums import picoEnum import serial # Set up callback for streaming mode CALLBACK = C_CALLBACK_FUNCTION_FACTORY( None, POINTER(POINTER(c_int16)), c_int16, c_uint32, c_int16, c_int16, c_uint32 ) # List to hold ADC values adc_values = [] # Callback function to handle data def get_overview_buffers(buffers, _overflow, _triggered_at, _triggered, _auto_stop, n_values): adc_values.extend(buffers[0][0:n_values]) callback = CALLBACK(get_overview_buffers) # Open a PicoScope 2000 Series device and start data collection with ps2000.open_unit() as device: print('Device Info: {}'.format(device.info)) # Set up channel A res = ps2000.ps2000_set_channel( device.handle, picoEnum.PICO_CHANNEL['PICO_CHANNEL_B'], True, picoEnum.PICO_COUPLING['PICO_DC'], ps2000.PS2000_VOLTAGE_RANGE['PS2000_10V'], ) assert_pico2000_ok(res) print("Channel A set up successfully.") # Initialize fast streaming mode res = ps2000.ps2000_run_streaming_ns( device.handle, 500, # Sampling interval in nanoseconds 2, # Sampling time unit (2 = nanoseconds) 500_000, # Maximum samples to collect False, # Do not stop automatically when maximum samples are reached 1, # Number of samples to aggregate together 500_000 # Maximum samples to store before overwriting ) assert_pico2000_ok(res) print("Streaming mode initialized.") # Start data collection in streaming mode print("Starting data collection...") start_time = time.time() while time.time() - start_time < 1.0: # Collect for 1 seconds ps2000.ps2000_get_streaming_last_values(device.handle, callback) # Stop the PicoScope ps2000.ps2000_stop(device.handle) print("PicoScope stopped successfully.") mv_values_B = adc2mV(adc_values, ps2000.PS2000_VOLTAGE_RANGE['PS2000_10V'],c_int16(32767)) # Generate time axis sampling_interval = 500e-9 # Sampling interval in seconds (500 ns) time_axis = np.arange(len(mv_values_B)) * sampling_interval * 1e3 # Convert to milliseconds # Plot the data fig, ax = plt.subplots() ax.set_xlabel("Time (ms)") ax.set_ylabel("Voltage (mV)") ax.plot(time_axis, mv_values_B, label="Channel B Voltage") ax.grid(True) ax.legend() plt.title("Channel B Data Over Time") plt.show()
代码运行后生成的图如下:
但我用Pico官方软件查看B通道时,能正常看到波形:
到底哪里出问题了?我已经尝试过不同的选项,比如切换到块读取模式、延长录制时间等。我是参考Pico的官方文档来写的代码。
备注:内容来源于stack exchange,提问作者gjossep
相关产品推荐
相关产品推荐

