Setting ADC sampling frequency doesn't work


I need to set my sampling frequency of the ADC in Particle Photon and I have written the following code:
import streams
import adc
import timers

sampling_freq = 48000
sampling_time = 0.05 # [s] sampling time
inputAnalog = A0 # define the analog pin for reading the value
samples_len = int(sampling_freq*sampling_time)

# reload the driver with a custom sampling frequency
adc.init(ADC0, samples_per_second=sampling_freq)




for i in range(2):
sleep(1000) # wait for a second
digitalWrite(LED0, HIGH) # turn the LED ON by setting the voltage HIGH
sleep(1000) # wait for a second
digitalWrite(LED0, LOW) # turn the LED OFF by setting the voltage LOW

print("\rEntering loop")
timer = timers.timer()

while True:

samples =, samples_len) # get Raw values (0-4095)
t1 = timer.get()
samples = None
print("\r\tAcquired samples! t=",t1,"ms\r\t")
but the printed value of t1 is 2 ms, instead of the expected 50 ms, so it seems like the sampling frequency is around 1.2 MHz, which is nowhere near what I need.. As far as I can see I've done everything according to the docs. Am I missing something or is there some trick to this?
Thanks in advance for the help.


  • edited July 2017
    Hi findal,

    Thanks for reporting this issue; we succeed to replicate the problem and we are investigating and working to fix it.

    Stay tuned for updates :)
    Matteo Cipriani
    Zerynth Support Team
  • Hi findal,

    Zerynth r2.0.9 is out.
    Now ADC sampling frequency can be properly set.
    We tested your script in our Particle Photon and all works fine.

    Matteo Cipriani
    Zerynth Support Team
  • findalfindal Member

    Frequency setting works for me as well! Thanks for the assistance.

Sign In or Register to comment.

ZERYNTH Community

@ 2016, all rights reserved.