General Purpose Input/Output (GPIO) RP2040 & ESP32

General Purpose Input/Output (GPIO) RP2040 & ESP32#

The General Purpose Input/Output (GPIO) pins on microcontrollers like the RP2040 and ESP32 are versatile pins that can be configured as either input or output pins. They can be used to read digital signals from sensors, control LEDs, drive motors, and interface with other digital devices.

_images/IMG_3134.jpg

Fig. 27 DualMCU ONE board#

The DualMCU ONE development board is equipped with 22 GPIO pins, 4 of which can be used as analog inputs. The ESP32 microcontroller also has a large number of GPIO pins but these pins require a expansion board to be used.

Let’s start with a simple example: blinking an LED. This example will demonstrate how to control GPIO pins on the DualMCU ONE board using both MicroPython.

LEDs ESP32 & RP2040#

In this section, we will learn how to work an RGB LED using a microcontroller. We will learn how to use the LED to different GPIO pins and control its on and off states with a simple program.

Hardware Description#

An RGB LED has three LEDs in one: red, green, and blue. You can control the color of the LED by varying the intensity of each of the LEDs. Here is an image of the RGB LED:

rgb led

Fig. 28 RGB LED#

Pin Connections#

Table 4 RGB LED Connections#

PIN

GPIO ESP32

GPIO RP2040

BLUE

27

RED

25

25

GREEN

26

RGB LED Code ESP32#

Tip

This code block is designed to work exclusively with the RGB LED on the DualMCU development board when using the ESP32 microcontroller.

import machine
import time

led_pin = machine.Pin(27, machine.Pin.OUT)
led_pin2 = machine.Pin(26, machine.Pin.OUT)
led_pin3 = machine.Pin(25, machine.Pin.OUT)

def loop():
    while True:
        led_pin.on()
        led_pin2.on()
        led_pin3.on()
        time.sleep(1)
        led_pin.off()
        led_pin2.off()
        led_pin3.off()
        time.sleep(1)

loop()