is it possible to do something else during adc reading ?

Dear all,

i try to sample an analog signal at 40khz with adc but i dont success to do it in real time in this code :

import time, pyb
from pyb import ADC

adc = pyb.ADC(pyb.Pin("P6"))        # create an ADC on pin P5
tim = pyb.Timer(6, freq=40000)         # create a timer running at 10Hz
buf = bytearray(5)                # creat a buffer to store the samples

    # The ADC has 12-bits of resolution for 4096 values.
    adc.read_timed(buf, tim)            # sample here
    for val in buf:                     # loop over all values
        print(i, val)                      # print the value out

because i cant do anything else when adc.read_timed(buf, tim) is working.
Do you have another way to do this ?


That’s not how this function works, it reads n samples and then returns. If you want to do something else while sampling the closest you can get is sampling in a timer callback.