FrequencyIn – Read a frequency signal

FrequencyIn is used to measure the frequency, in hertz, of a digital signal on an incoming pin. Accuracy has shown to be within 10%, if not better. It is recommended to utilize an average of multiple samples to smooth out readings.

Frequencies below 1KHz are not currently detectable.

FrequencyIn will not determine pulse width (use PulseIn).

class frequencyio.FrequencyIn(pin, capture_period=10)

Create a FrequencyIn object associated with the given pin.

Parameters:
  • pin (Pin) – Pin to read frequency from.
  • capture_period (int) – Keyword argument to set the measurement period, in milliseconds. Default is 10ms; range is 1ms - 500ms.

Read the incoming frequency from a pin:

import frequencyio
import board

frequency = frequencyio.FrequencyIn(board.D11)

# Loop while printing the detected frequency
while True:
    print(frequency.value)

    # Optional clear() will reset the value
    # to zero. Without this, if the incoming
    # signal stops, the last reading will remain
    # as the value.
    frequency.clear()
deinit()

Deinitialises the FrequencyIn and releases any hardware resources for reuse.

__enter__()

No-op used by Context Managers.

__exit__()

Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.

pause()

Pause frequency capture.

resume()

Resumes frequency capture.

clear()

Clears the last detected frequency capture value.

capture_period

The capture measurement period. Lower incoming frequencies will be measured more accurately with longer capture periods. Higher frequencies are more accurate with shorter capture periods.

Note

When setting a new capture_period, all previous capture information is cleared with a call to clear().

__get__(index)

Returns the value of the last frequency captured.