Support for frequency based protocols
This module is not available in SAMD21 builds. See the Support Matrix for more info.
All classes change hardware state and should be deinitialized when they
are no longer needed if the program continues after use. To do so, either
deinit() or use a context manager. See
Lifetime and ContextManagers for more info.
import frequencyio import time from board import * frequency = frequencyio.FrequencyIn(D13) frequency.capture_period = 15 time.sleep(0.1)
This example will initialize the the device, set
capture_period, and then sleep 0.1 seconds.
CircuitPython will automatically turn off FrequencyIn capture when it resets all
hardware after program completion. Use
deinit() or a
to do it yourself.
FrequencyIn(pin: microcontroller.Pin, capture_period: int = 10)¶
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
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.
When setting a new
capture_period, all previous capture information is cleared with a call to
Deinitialises the FrequencyIn and releases any hardware resources for reuse.
No-op used by Context Managers.
Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.
Pause frequency capture.
Resumes frequency capture.
Clears the last detected frequency capture value.
__get__(self, index: int)¶
Returns the value of the last frequency captured.