frequencyio – Support for frequency based protocols

Avertissement

This module is not available in SAMD21 builds. See the Module Support Matrix - Which Modules Are Available on Which Boards 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 call deinit() or use a context manager. See Lifetime and ContextManagers for more info.

For example:

import time
import frequencyio
import board

frequency = frequencyio.FrequencyIn(board.D11)
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 with statement to do it yourself.

Available on these boards
  • ATMegaZero ESP32-S2
  • Adafruit EdgeBadge
  • Adafruit Feather ESP32-S2 TFT
  • Adafruit Feather ESP32S2
  • Adafruit Feather M4 CAN
  • Adafruit Feather M4 Express
  • Adafruit FunHouse
  • Adafruit Grand Central M4 Express
  • Adafruit Hallowing M4 Express
  • Adafruit ItsyBitsy M4 Express
  • Adafruit MagTag
  • Adafruit Matrix Portal M4
  • Adafruit Metro ESP32S2
  • Adafruit Metro M4 Airlift Lite
  • Adafruit Metro M4 Express
  • Adafruit Monster M4SK
  • Adafruit PyGamer
  • Adafruit PyPortal
  • Adafruit PyPortal Pynt
  • Adafruit PyPortal Titano
  • Adafruit Pybadge
  • Adafruit QT Py ESP32S2
  • Adafruit Trellis M4 Express
  • AloriumTech Evo M51
  • Artisense Reference Design RD00
  • BDMICRO VINA-D51
  • BastWiFi
  • CP32-M4
  • Capable Robot Programmable USB Hub
  • CircuitBrains Deluxe
  • CrumpS2
  • DynOSSAT-EDU-OBC
  • ESP 12k NodeMCU
  • Feather ESP32S2 without PSRAM
  • FeatherS2
  • FeatherS2 Neo
  • FeatherS2 PreRelease
  • Franzininho WIFI w/Wroom
  • Franzininho WIFI w/Wrover
  • Gravitech Cucumber M
  • Gravitech Cucumber MS
  • Gravitech Cucumber R
  • Gravitech Cucumber RS
  • HMI-DevKit-1.1
  • Kaluga 1
  • LILYGO TTGO T8 ESP32-S2 w/Display
  • MORPHEANS MorphESP-240
  • MicroDev microS2
  • Mini SAM M4
  • Oak Dev Tech PixelWing ESP32S2
  • PyCubedv04
  • PyCubedv04-MRAM
  • PyCubedv05
  • PyCubedv05-MRAM
  • S2Mini
  • S2Pico
  • SAM E54 Xplained Pro
  • SAM32v26
  • Saola 1 w/Wroom
  • Saola 1 w/Wrover
  • Seeeduino Wio Terminal
  • Silicognition LLC M4-Shim
  • SparkFun MicroMod SAMD51 Processor
  • SparkFun Thing Plus - SAMD51
  • Sprite_v2b
  • TG-Boards' Datalore IP M4
  • Targett Module Clip w/Wroom
  • Targett Module Clip w/Wrover
  • The Open Book Feather
  • Thingz - Galaxia
  • TinyS2
  • UARTLogger II
  • Winterbloom Sol
  • nanoESP32-S2 w/Wrover
  • nanoESP32-S2 w/Wroom

class frequencyio.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 PulseIn).

Create a FrequencyIn object associated with the given pin.

Paramètres:
  • 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()
capture_period :int

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().

deinit() None

Deinitialises the FrequencyIn and releases any hardware resources for reuse.

__enter__() FrequencyIn

No-op used by Context Managers.

__exit__() None

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

pause() None

Pause frequency capture.

resume() None

Resumes frequency capture.

clear() None

Clears the last detected frequency capture value.

__get__(index: int) int

Returns the value of the last frequency captured.