frequencyio
– Support for frequency based protocols
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 Camera
- Adafruit EdgeBadge
- Adafruit Feather ESP32 V2
- Adafruit Feather ESP32-C6 4MB Flash No PSRAM
- Adafruit Feather ESP32-S2 Reverse TFT
- Adafruit Feather ESP32-S2 TFT
- Adafruit Feather ESP32-S3 Reverse TFT
- Adafruit Feather ESP32-S3 TFT
- Adafruit Feather ESP32S2
- Adafruit Feather ESP32S3 4MB Flash 2MB PSRAM
- Adafruit Feather ESP32S3 No PSRAM
- Adafruit Feather HUZZAH32
- Adafruit Feather M4 CAN
- Adafruit Feather M4 Express
- Adafruit FunHouse
- Adafruit Grand Central M4 Express
- Adafruit HUZZAH32 Breakout
- Adafruit Hallowing M4 Express
- Adafruit ItsyBitsy ESP32
- Adafruit ItsyBitsy M4 Express
- Adafruit MagTag
- Adafruit Matrix Portal M4
- Adafruit MatrixPortal S3
- Adafruit Metro ESP32S2
- Adafruit Metro ESP32S3
- 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 ESP32 PICO
- Adafruit QT Py ESP32-S3 4MB Flash 2MB PSRAM
- Adafruit QT Py ESP32-S3 no psram
- Adafruit QT Py ESP32S2
- Adafruit Trellis M4 Express
- Adafruit Vindie S2
- Adafruit-Qualia-S3-RGB666
- Ai Thinker ESP32-CAM
- AloriumTech Evo M51
- Arduino Nano ESP32
- Artisense Reference Design RD00
- AutosportLabs-ESP32-CAN-X2
- BARDUINO 4.0.2
- BDMICRO VINA-D51
- BLING!
- BPI-Bit-S2
- BPI-Leaf-S3
- BPI-PicoW-S3
- BastWiFi
- Bee-Data-Logger
- Bee-Motion-S3
- Bee-S3
- BlizzardS3
- CP32-M4
- CRCibernetica IdeaBoard
- CircuitART Zero S3
- CircuitBrains Deluxe
- ColumbiaDSL-Sensor-Board-V1
- CrumpS2
- Cytron Maker Feather AIoT S3
- DFRobot FireBeetle 2 ESP32-S3
- Deneyap Kart
- Deneyap Kart 1A
- Deneyap Kart 1A v2
- Deneyap Mini
- Deneyap Mini v2
- DynOSSAT-EDU-OBC
- ES3ink
- ESP 12k NodeMCU
- ESP32 Devkit V1
- ESP32-C6-DevKitC-1-N8
- ESP32-C6-DevKitM-1
- ESP32-H2-DevKitM-1
- ESP32-P4-Function-EV
- ESP32-S2-DevKitC-1-N4
- ESP32-S2-DevKitC-1-N4R2
- ESP32-S2-DevKitC-1-N8R2
- ESP32-S3-Box-2.5
- ESP32-S3-Box-Lite
- ESP32-S3-DevKitC-1-N16
- ESP32-S3-DevKitC-1-N32R8
- ESP32-S3-DevKitC-1-N8
- ESP32-S3-DevKitC-1-N8R2
- ESP32-S3-DevKitC-1-N8R8
- ESP32-S3-DevKitC-1-N8R8-with-HACKTABLET
- ESP32-S3-DevKitM-1-N8
- ESP32-S3-EYE
- ESP32-S3-USB-OTG-N8
- Espressif ESP32 DevKitc V4 WROOM-32E
- Espressif ESP32 DevKitc V4 WROVER
- Espressif ESP32 TTGO T8 v1.7
- Espressif ESP32-EYE
- Espressif ESP32-LyraT
- Espressif-ESP32-S3-LCD-EV-Board
- Espressif-ESP32-S3-LCD-EV-Board_v1.5
- FeatherS2
- FeatherS2 Neo
- FeatherS2 PreRelease
- FeatherS3
- FeatherS3 Neo
- Flipper Zero Wi-Fi Dev
- Franzininho WIFI w/Wroom
- Franzininho WIFI w/Wrover
- Freenove ESP32-WROVER-DEV-CAM
- Gravitech Cucumber M
- Gravitech Cucumber MS
- Gravitech Cucumber R
- Gravitech Cucumber RS
- HMI-DevKit-1.1
- Hardkernel Odroid Go
- Heltec ESP32-S3-WIFI-LoRa-V3
- HexKyS2
- IoTs2
- Kaluga 1
- LILYGO T-DECK
- LILYGO T-DISPLAY S3 v1.2
- LILYGO T-Display S3 Pro
- LILYGO T-Watch-S3
- LILYGO TEMBED ESP32S3
- LILYGO TTGO T-DISPLAY v1.1
- LILYGO TTGO T-DISPLAY v1.1 4M
- LILYGO TTGO T8 ESP32-S2
- LILYGO TTGO T8 ESP32-S2 w/Display
- LOLIN S3 16MB Flash 8MB PSRAM
- LOLIN S3 MINI 4MB Flash 2MB PSRAM
- LOLIN S3 PRO 16MB Flash 8MB PSRAM
- Lilygo T-watch 2020 V3
- M5Stack Atom Echo
- M5Stack Atom Lite
- M5Stack Atom Matrix
- M5Stack Atom U
- M5Stack AtomS3
- M5Stack AtomS3 Lite
- M5Stack AtomS3U
- M5Stack Cardputer
- M5Stack Core Basic
- M5Stack Core Fire
- M5Stack Core2
- M5Stack CoreS3
- M5Stack Dial
- M5Stack M5Paper
- M5Stack Stick C
- M5Stack Stick C Plus
- M5Stack Timer Camera X
- MORPHEANS MorphESP-240
- MagiClick S3 N4R2
- Maker Go ESP32C6 Supermini
- Maker badge by Czech maker
- MakerFabs-ESP32-S3-Parallel-TFT-With-Touch-7inch
- MicroDev microS2
- Mini SAM M4
- MixGo CE
- NanoS3
- Neuron
- OMGS3
- Oak Dev Tech PixelWing ESP32S2
- Oxocard Artwork
- Oxocard Connect
- Oxocard Galaxy
- Oxocard Science
- P1AM-200
- ProS3
- PyCubedv04
- PyCubedv04-MRAM
- PyCubedv05
- PyCubedv05-MRAM
- RGBTouch Mini
- S2Mini
- S2Pico
- SAM E54 Xplained Pro
- SAM32v26
- SQFMI Watchy
- Saola 1 w/Wroom
- Saola 1 w/Wrover
- Seeed Xiao ESP32-C6 4MB Flash 512KB SRAM
- Seeed Xiao ESP32-S3 Sense
- Seeeduino Wio Terminal
- Silicognition LLC M4-Shim
- SparkFun MicroMod SAMD51 Processor
- SparkFun Thing Plus - SAMD51
- Sprite_v2b
- Sunton-ESP32-8048S050
- Sunton-ESP32-8048S070
- TG-Boards' Datalore IP M4
- TTGO T8 ESP32-S2-WROOM
- Targett Module Clip w/Wroom
- Targett Module Clip w/Wrover
- The Open Book Feather
- ThingPulse Pendrive S3
- TinyC6
- TinyPICO
- TinyPICO Nano
- TinyS2
- TinyS3
- TinyWATCH S3
- UARTLogger II
- VCC-GND YD-ESP32-S3 (N16R8)
- VCC-GND YD-ESP32-S3 (N8R8)
- VIDI X V1.1
- Waveshare ESP32-S2-Pico
- Waveshare ESP32-S2-Pico-LCD
- Waveshare ESP32-S3-GEEK
- Waveshare ESP32-S3-Pico
- Waveshare ESP32-S3-Tiny
- Waveshare ESP32-S3-Zero
- Waveshare ESP32S3 LCD 1.28
- WeAct ESP32-C6 (4MB)
- WeAct ESP32-C6 (8MB)
- WeMos LOLIN32 Lite
- Winterbloom Sol
- nanoESP32-S2 w/Wrover
- nanoESP32-S2 w/Wroom
- senseBox MCU-S2 ESP32S2
- sunton_esp32_2432S028
- sunton_esp32_2432S032C
-
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.
- 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() → 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.
-
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()
.
-
__get__(index: int) → int
Returns the value of the last frequency captured.