Digital inputs let you interface with the board. This example adds a button input to the Arduino RP2040 Connect. When you press the button, the onboard LED will turn on. Additionally, while the button is pressed, the variable n increases in value by 1. That value is printed to the REPL.


  • One side of the button to D4
  • The opposite side of the button to GND

You can access the code by downloading the Project Bundle. To do this, click on the Download Project Bundle button in the window below. It will download as a zipped folder.

# SPDX-FileCopyrightText: 2021 Liz Clark for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
from digitalio import DigitalInOut, Direction, Pull

#  LED setup for onboard LED
led = DigitalInOut(board.LED)
led.direction = Direction.OUTPUT

#  button setup
switch = DigitalInOut(board.D4)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

#  variable for number count
n = 0

while True:

	#  when switch is NOT pressed...
    if switch.value:
		#  LED is off
        led.value = False
	#  when switch is pressed...
		#  LED is on
        led.value = True
		#  value of n increases by 1
        n += 1
		#  n is printed to the REPL
        print("led ON %i" % n)
	#  delay

Upload the Code and Libraries to the Arduino Nano RP2040 Connect

After downloading the Project Bundle, plug your board into the computer USB port. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called CIRCUITPY. Unzip the folder and copy the file to the Arduino Nano RP2040 Connect's CIRCUITPY drive. Then, rename that file to No libraries are needed in the lib folder for this code since it only uses built-in CircuitPython libraries.

Your Arduino Nano RP2040 Connect CIRCUITPY drive should look like this after copying the file.

This guide was first published on Jun 04, 2021. It was last updated on 2021-06-04 14:46:06 -0400.

This page (Digital Input) was last updated on May 24, 2022.

Text editor powered by tinymce.