I am using MCP3008 with Raspberrypi Model B. MCP3008 is sampling the analog signal. But is there any way through which I can verify if it is correct or not. For example, I need a sampling rate of 1.5 kHz, so I read the sample every 666 us. But then I am not sure how to verify the number of samples it has acquired in one second.

  • If you take a sample at a rate of 1.5 kHz, why do you need to verify how many you get in 1 second? Commented Sep 25, 2018 at 13:06

2 Answers 2


By current sampling rate I assume you mean the number of samples taken in the last second.

Take a time-stamp as you take a sample and increment a sample count. If the number of seconds in the time stamp is different from the previous number of seconds then display and then zero the sample count.

An example follows.

#!/usr/bin/env python

import time

second = int(time.time())
sample = 0

def bump_sample():
   global second, sample
   now = int(time.time())
   sample += 1
   if now != second:
      print("{} samples/second".format(sample))
      sample = 0
      second = now

while True:

A good approach would be to ditch the delay functions inside Python (probably that's what's you on), inside Linux (means that you just hope for the operating system to be time-accurate, and it never is critically accurate). Exploit hardware interrupts which are super-well defined if used correctly. You will set an interrupt to occur and trigger your sampling period; take an idea from here:


keep in mind the conversion time that any ADC needs to deliver a sample and the maximum sampling rate which you can have based on your Vcc on the ADC pin (https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf).

Not the answer you're looking for? Browse other questions tagged or ask your own question.