Picoscope 2204A continuous waveform generator using python in Raspberry Pi 4

Post your Linux discussions here
Post Reply
amphebee90
Newbie
Posts: 0
Joined: Mon Jan 02, 2023 3:33 am

Picoscope 2204A continuous waveform generator using python in Raspberry Pi 4

Post by amphebee90 »

Hello,

I need to generate continuous (non-stop) waveform from Picoscope 2204a using python in Raspberry Pi 4.
So far, I managed to generate short-time waveform using the example with the built-in generator from https://www.picotech.com/picoapps/uploa ... als.md.pdf.

Here is my code

Code: Select all

from picosdk.ps2000 import ps2000
from picosdk.functions import assert_pico2000_ok, adc2mV
from picosdk.PicoDeviceEnums import picoEnum

with ps2000.open_unit() as device:
    print('Device info: {}'.format(device.info))

    res = ps2000.ps2000_set_sig_gen_built_in(
        device.handle,
        1000_000,     # offset voltage in uV
        2000_000,     # peak-to-peak voltage in uV
        0,           # type of waveform (0 = sine wave)
        20000.0,     # start frequency in Hz
        20000.0,     # stop frequency in Hz
        0.0,         # frequency change per interval in Hz
        0.1,         # interval of frequency change in seconds
        0,           # sweep direction (0 = up)
        1_000        # number of times to sweep
    )
    assert_pico2000_ok(res)
However, this code can only generates the waveform for roughly less than 100 ms. I tried to find another example using python to generate non-stop waveform using python but unfortunately I cannot find one. Any help will be appreciated.

Thanks!
Last edited by amphebee90 on Tue Jan 03, 2023 3:18 am, edited 1 time in total.

Martyn
Site Admin
Site Admin
Posts: 4277
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Picoscope 2204a continuous waveform generator using python in Raspberry Pi 4

Post by Martyn »

That is just a small section of your code, the key part will be the call to start the streaming

Code: Select all

ps2000.ps2000_run_streaming_ns
and ensuring that the streaming is not set to auto stop after a set number of samples.

You will find further examples on our GitHub pages

https://github.com/picotech/picosdk-pyt ... aming_mode
Martyn
Technical Support Manager

amphebee90
Newbie
Posts: 0
Joined: Mon Jan 02, 2023 3:33 am

Re: Picoscope 2204a continuous waveform generator using python in Raspberry Pi 4

Post by amphebee90 »

Thanks!

I tried to use the example from the streaming_mode.py and simplify it into the code below, and now I can generate the sine wave continuously non-stop.

Code: Select all

import matplotlib.pyplot as plt
import numpy as np

from picosdk.ps2000 import ps2000
from picosdk.functions import assert_pico2000_ok
from picosdk.PicoDeviceEnums import picoEnum

with ps2000.open_unit() as device:
    print('Device info: {}'.format(device.info))

    res = ps2000.ps2000_set_sig_gen_built_in(
        device.handle,
        1000_000,     # offset voltage in uV
        2000_000,     # peak-to-peak voltage in uV
        0,           # type of waveform (0 = sine wave)
        20000.0,     # start frequency in Hz
        20000.0,     # stop frequency in Hz
        0.0,         # frequency change per interval in Hz
        0.1,         # interval of frequency change in seconds
        0,           # sweep direction (0 = up)
        1_000        # number of times to sweep
    )
    assert_pico2000_ok(res)

    res = ps2000.ps2000_run_streaming_ns(
        device.handle,
        500,
        2,
        100_000,
        False,
        1,
        50_000
    )
    assert_pico2000_ok(res)

    fig, ax = plt.subplots()
    plt.show()
However, it is a bit strange that if I remove the last two lines for the plot (which is unnecessary and unrelated with the signal generator), the Picoscope will stop generating the sine wave in less than 1 second.

I wonder why?

Post Reply