Я пытаюсь записать простой блочный сигнал (10 мс при отключении 10 мс), исходящий от Arduino на канале B PicoScope серии 2000, на Python, однако я вообще не вижу сигнала. Я дважды проверил свои настройки, и все они кажутся правильными.
Мой код выглядит следующим образом:
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()
Вывод графика выглядит следующим образом:
Когда я просматриваю канал B в программном обеспечении Pico, я вижу волну нормально:
Что происходит не так? Я пробовал разные варианты, такие как переход в режим чтения блоков, более длительную запись и т. д. Документацию я получил отсюда: Документация
Я пытаюсь записать простой блочный сигнал (10 мс при отключении 10 мс), исходящий от Arduino на канале B PicoScope серии 2000, на Python, однако я вообще не вижу сигнала. Я дважды проверил свои настройки, и все они кажутся правильными. Мой код выглядит следующим образом: [code]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.")
# 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() [/code] Вывод графика выглядит следующим образом: [img]https://i.sstatic.net/O9srmep1.png[/img]
Когда я просматриваю канал B в программном обеспечении Pico, я вижу волну нормально: [img]https://i.sstatic.net/n3wOElPN.png[/img]
Что происходит не так? Я пробовал разные варианты, такие как переход в режим чтения блоков, более длительную запись и т. д. Документацию я получил отсюда: Документация