Table of Contents

Intro to RP2040

Microcontroller

Microcontrollers are tiny integrated circuits (ICs) that you can program to perform various tasks. They have a processor, memory, and input/output pins (GPIO) to interact with the external world. From toys to cars, microcontrollers are everywhere in electronics.

The RP2040 is a powerful and versatile microcontroller built by the Raspberry Pi Foundation. This chip, based on the ARM architecture, is the heart of development boards like the popular Raspberry Pi Pico. We also utilize the RP2040 in Marble Pico board.

Raspberry Pi Pico board Marble Pico board

To unleash the potential of the RP2040, the Raspberry Pi Foundation created the Pico-SDK. This free and open-source software development kit (SDK) equips you with the tools and libraries needed to program the RP2040 in C and C++.

RP2040

This chip name was provided by the Raspberry Pi foundation and is explained in the datasheet:

RP2040 pinout

RP2040 has a dual M0+ processor cores, DMA, internal memory and peripheral blocks connected via AHB/APB bus fabric. It offers a variety of features for flexible development:

RP2040 system overview

In short, the RP2040 packs powerful processing, flexible memory options, diverse communication options, and built-in peripherals, making it suitable for various development projects.

Environment interaction

General-purpose input/output pins let you connect external components like LEDs, sensors, or buttons to your RP2040. You can configure them to be inputs (reading data) or outputs (sending data). The RP2040 provides 30 multi-function GPIOs controllable via software (C/C++ or MicroPython) for diverse functionalities beyond basic input/output.

In order to interface with the external environment, various electronic components are used, serving either as actuators (modifying the state of the external environment) or as transducers/sensors (influenced by the external environment and providing information to the microcontroller about various parameters).

Examples of actuators:

Examples of sensors:

LED-s

LEDs - Light Emitting Diode - also called electroluminescent diodes - emit light when they are directly polarized. Not to be confused with light bulbs as they have radically different methods of operation.

LEDs can be used as indicator lights (often used in various appliances to signal that the appliance is on and doing something), or for illumination, in which case power LEDs are used. In the lab, LEDs are used to indicate the status of a pin.

Calculation of current limiting resistor To use an LED for the purpose of indicating the status of a pin (rather said to indicate the presence of voltage), the current through the LED must be limited. This can be done most simply by stringing a resistor with the LED.

An LED is designed to operate at a nominal current (ex: 10mA). The voltage drop at this current across low power indicator LEDs is given by the chemistry of the LED (this also gives the color of the LED). In the lab, since we are using such a low current LED, we can power it directly from the logic pins of the MCU.

 Schema de lucru și calculul rezistenței de limitare a curentului prin LED

If the MCU has a pin voltage of 3.3V, also noted as 3V3, to light up an LED with a nominal current of 10mA and a voltage drop of 2V we need a resistance of 130 Ω.

We can use a resistor with a higher resistance value. The nominal current will light up the LED at it's maximum brightness. For status LEDs we can pick a resistance even 10 times bigger and the LED will light up slightly.

If there is no resistor in the circuit, the resistance will be almost 0 Ω, the current will tend to ∞, meaning a short circuit. This will absolutely burn the LED and make it unusable, but it can also burn the MCU. Most MCUs have short circuit protection, but is safer to not rely on that.

Buttons

The simplest way for the user to interact with a MCU is through the use of buttons.

There are various ways to connect a button to the MCU, but these are the most used versions:

 Conectarea unui push-button: a) incorect, cu intrare flotantă, b) corect, cu rezistență de pull-up

Conectarea unui push-button: a) incorect, cu intrare flotantă, b) corect, cu rezistență de pull-up

To save external space, in most MCUs these resistors have been included inside the integrated circuit. Initially they are disabled and their activation can be done through software.

Breadboard and jumper wires

A breadboard is a rectangular board with a grid of holes that allows you to create temporary electronic circuits without soldering. The board typically has metal strips underneath the surface, connecting the holes in certain patterns. These patterns follow a standard layout, facilitating circuit building. Breadboards are reusable and provide a convenient way to prototype circuits quickly and make changes easily by rearranging components.

 breadboard  breadboard connections

a) Breadboard for Electronics Prototyping, b) Internal Wiring of a Breadboard

Jumper wires are flexible wires with connectors at each end, typically male connectors (pins) or female connectors (sockets). They are used to create electrical connections on a breadboard by plugging one end into a hole on the breadboard and the other end into another hole, forming a connection between the two points.

 jumper wires

Datasheets

The RP2040, like most electronic components, has a datasheet (sometimes called a data sheet or spec sheet). This document is like an instruction manual for the chip, explaining its features and how to use it in your projects.

What's in an RP2040 Datasheet?

Keep in mind:

GPIO configuration

GPIO pins can be used as outputs (LEDs, motors, buzzers) or as inputs (buttons, sensors).

The R02040 has three peripherals that control the GPIO pins:

  1. Pads - control the actual physical pin or pad that the processor has outside. This control the electrical parameters, like maximum current or pull up and pull down resistors
  2. IO Bank0 - connects and multiplexes the peripheral's pins to the output pads. Several peripherals use the same output pad to communicate with the exterior. For example, in the image below, GPIO0 can be used either for:
    • SIO - the GPIO function
    • SPI_RX - the receive pin for the SPI peripheral
    • I2C0_SDA - the data pin for the I2C0 peripheral
    • UART0_TX - the transmit pin for the UART0 (serial port 0) peripheral
  3. SIO - that controls the interior MCU's pins. This is the peripheral that developers use to read and write the value of the pins.

Marble Pico board Marble Pico pinout

Wowki simulator

Wokwi is a web-based platform that allows you to simulate and prototype electronic circuits with microcontrollers. It provides a visual interface where you can drag and drop components, connect them with virtual wires, and write code to control their behavior. Wokwi currently supports popular microcontroller boards like:

Exercises

  1. Create a program in Wowki to blink an LED connected to a Raspberry Pi Pico (RP2040) microcontroller.
  2. Design and implement a program for a Raspberry Pi Pico (RP2040) microcontroller that increments a counter from 0 to 9 and displays the current count on an 7-segment display. The program should also include a reset button that, when pressed, resets the counter back to 0.

References