echo '' ;

ESP32 Lua-RTOS Module – PIO

The PIO (Programmable Input/Output) module in the ESP32 Lua-RTOS is a versatile feature that allows users to configure and control the GPIO pins of the ESP32 microcontroller dynamically. It provides an interface for performing various operations such as digital input, digital output, and pulse-width modulation (PWM) generation, among others.

Functionalities and Capabilities

  1. Digital Input/Output: The PIO module allows users to configure GPIO pins as digital inputs or outputs. Digital inputs can be used to read the state of external sensors or switches, while digital outputs can drive external devices such as LEDs, relays, or motors.
  2. Interrupt Handling: It supports interrupt handling on GPIO pins, allowing users to trigger actions based on changes in pin states. This feature is useful for implementing event-driven applications where real-time responses to external events are required.
  3. Pull-up/Pull-down Resistors: The PIO module enables users to enable or disable the internal pull-up or pull-down resistors on GPIO pins, ensuring stable and reliable signal readings.
  4. Pulse-Width Modulation (PWM): It provides support for generating PWM signals on GPIO pins, allowing users to control the intensity of analog devices such as LEDs, motors, or servos.
  5. Pin Configuration: Users can dynamically configure the functionality and characteristics of GPIO pins using the PIO module, including setting pin modes (input/output), configuring interrupt triggers, and adjusting PWM parameters.
  6. Low-Level Access: The PIO module offers low-level access to GPIO pins, allowing users to directly manipulate pin states and registers for advanced control and customization.
  7. Resource Management: It provides mechanisms for managing GPIO pin resources efficiently, preventing conflicts and ensuring proper allocation of resources across different tasks or modules.

Overall, the PIO module in the ESP32 Lua-RTOS enhances the flexibility and versatility of the ESP32 microcontroller, enabling users to implement a wide range of GPIO-based applications with ease and efficiency. Whether for simple digital I/O tasks or more complex PWM generation and interrupt handling, the PIO module offers powerful capabilities for interacting with external devices and sensors in Lua-RTOS projects.

LED

Set LED as OUPUT/ INPUT

led_pin_1 = pio.GPIO20
led_pin_2 = pio.GPIO21
pio.pin.setdir(pio.INPUT, led_pin_1)  --input
pio.pin.setdir(pio.OUTPUT, led_pin_2) --Output

LED On

led_pin = pio.GPIO4
pio.pin.setdir(pio.OUTPUT, led_pin)
pio.pin.sethigh(led_pin)

LED Blink using Delay in do while functioning with thread function

thread.start(function()
	pio.pin.setdir(pio.OUTPUT, pio.GPIO23)
	pio.pin.setpull(pio.NOPULL, pio.GPIO23)
	
	while true do
		pio.pin.setval(1, pio.GPIO23)
		tmr.delayms(1000)
		pio.pin.setval(0, pio.GPIO23)
		tmr.delayms(1000)
	end
end)

LED Blink using Delay in do while function

-- www.aruneworld.com/embedded/espressif/esp32/lua_rtos_esp32
pio.pin.setdir(pio.OUTPUT, pio.GPIO23)
pio.pin.setpull(pio.NOPULL, pio.GPIO23)

while true do
	pio.pin.setval(1, pio.GPIO23)
	tmr.delayms(1000)
	pio.pin.setval(0, pio.GPIO23)
	tmr.delayms(1000)
end

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from ArunEworld

Subscribe now to keep reading and get access to the full archive.

Continue reading