I have a Raspberry Pi 2 Model B and want sample the GPIO 27 with 14400 samples per second. GPIO 27 is a pin with no Uart and no other before implemented funktions, i need the samples as single line.

The Problem is that linux gives my application ever few miliseconds time slice(e.g. every 15 ms or 20ms (i didn´t know it exactly)) but my application should sample the GPIO 27 ever 70µs. The Problem is now that while Linux do something other i miss 285 samples. Know someone a driver oder some other solution witch can help me to rise up the time slice for my application?

With frindly wishes sniffi

  • Related: raspberrypi.stackexchange.com/questions/9646/…
    – Ghanima
    Commented May 19, 2016 at 9:11
  • As usual the devil is in the details, do you want to sample exactly 14400 times a second, i.e. precisely every 69.4 µs, or do you want to sample at least that fast?
    – joan
    Commented May 19, 2016 at 10:16
  • I want semple exactly 14400 times a second or 19200 times a second.
    – sniffi
    Commented May 19, 2016 at 10:29
  • If you are sampling output from an audio DAC you use i2s
    – PaulF8080
    Commented May 19, 2016 at 14:51

1 Answer 1


Actually thinking about this it is potentially fairly trivial.

With pigpio you could just set up a callback on GPIO 27 (C, Python).

That will give you a stream of time-stamped level changes. You can just interpolate between the level changes to work out the intermediate sample values.

E.g. if the last level change was at time 1678000 microseconds and the level becomes 1 at time 16788543 then you know that any samples due between 1678000 and 16788542 were at level 0.

This is pretty much the same technique used by pigpio to bit bang incoming serial data on arbitrary GPIO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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