Table of Contents

lamaPLC: Raspberryes

The RP2040 is a small, specially engineered silicon chip developed by Raspberry Pi to serve as the central controller for electronic devices.

The Raspberry Pi Pico is a compact green circuit board centered on the RP2040 chip, featuring a USB port, storage memory, and pin connections. This design allows for easy connection to a computer, enabling programming to control electronics such as sensors, lights, and motors.

FeatureRP2040 (The Chip)Pi Pico (Standard)Pi Pico HPi Pico WPi Pico WHRP2040-ZeroRP2040-ETH
ManufacturerRaspberry PiRaspberry PiRaspberry PiRaspberry PiRaspberry PiWaveshareWaveshare
Dimensions7 × 7 mm51 × 21 mm51 × 21 mm51 × 21 mm51 × 21 mm23.5 × 18 mm51 × 21 mm
Flash Storage0 MB2 MB2 MB2 MB2 MB2 MB4 MB
USB ConnectorNoneMicro-USBMicro-USBMicro-USBMicro-USBUSB Type-CUSB Type-C
Wireless (Wi-Fi/BT)NoneNoneNone2.4GHz Wi-Fi & BT 5.22.4GHz Wi-Fi & BT 5.2NoneNone
Wired NetworkNoneNoneNoneNoneNoneNoneRJ45 Ethernet Port
Header PinsNoneUnsoldered (Bare pads)Pre-solderedUnsoldered (Bare pads)Pre-solderedUnsoldered (Castellated)Unsoldered
Debug ConnectorNoneNone3-pin JST-SHNone3-pin JST-SHNoneNone
Onboard LightNoneGreen LEDGreen LEDGreen LEDGreen LEDRGB NeoPixelNone
Usable GPIO Pins30262626262914
Logic Voltage (GPIO)3.3V3.3V3.3V3.3V3.3V3.3V3.3V
Input Voltage (VBUS/VIN)N/A (Requires exact 1.1V & 3.3V)1.8V to 5.5V1.8V to 5.5V1.8V to 5.5V1.8V to 5.5V5.0V (via USB-C or 5V pin)5.0V (via USB-C or 5V pin)
Software SupportC/C++, MicroPython, CircuitPythonC/C++, MicroPython, CircuitPythonC/C++, MicroPython, CircuitPythonC/C++, MicroPython, CircuitPythonC/C++, MicroPython, CircuitPythonC/C++, MicroPython, CircuitPythonC/C++, MicroPython (with special build)
Network LibrariesNoneNoneNonenetwork (Wi-Fi), bluetoothnetwork (Wi-Fi), bluetoothNonewiznet / custom CH9120 drivers
Primary UsageCustom circuit design & commercial productsLearning code, DIY hobbies, basic automationPrototyping without a soldering ironSmart home, wireless IoT, web serversWireless IoT without a soldering ironTiny gadgets, wearable tech, macro padsHardwired network devices, industrial IoT

Raspberry Pi Pico

The Raspberry Pi Pico is a compact, quick, and budget-friendly microcontroller board built for managing physical hardware and electronics. Unlike a complete computer, it doesn't operate on an OS such as Windows or Linux. Instead, it executes a single program that you create on your computer and upload to the board using USB.

Key Characteristics

The Raspberry Pi Pico 2 is a major performance upgrade over the original Pico 1, delivering faster speeds, double the memory, and a completely new processor architecture while maintaining physical drop-in compatibility.

The primary difference lies in the microprocessing chip: the original Pico utilizes the RP2040 chip, whereas the Pico 2 is built on the upgraded RP2350 platform.

The physical form factor, micro-USB port, and standard 26-pin layout remain unchanged, allowing you to reuse existing breadboards and add-on gear. However, the internal specifications are heavily upgraded:

Raspberry Pi Pico (Pico 1)Raspberry Pi Pico 2
FeatureRaspberry Pi Pico (Pico 1)Raspberry Pi Pico 2
Processor ChipRP2040RP2350
CPU ArchitectureDual Arm Cortex-M0+Dual Arm Cortex-M33 OR Dual RISC-V Hazard3 (selectable)
Clock Speed133 MHz150 MHz
SRAM (RAM)264 KB520 KB
On-board Flash2 MB4 MB
Floating Point UnitSoftware-only (slower math)Hardware FPU (on Arm cores)
PWM Channels16 channels24 channels
PIO State Machines812 (via a 3rd PIO block)

Software Compatibility

Both boards are configured and programmed with MicroPython, CircuitPython, or C/C++. They are highly source-compatible, so your code can be transferred easily. However, due to different internal memory layouts, they are not binary-compatible, requiring you to download or compile the appropriate variant file for either the RP2040 or RP2350 platform.

RP2040-Zero

RP2040-Zero The RP2040-Zero is an ultra-compact, low-cost microcontroller development board designed by Waveshare. It is built around the Raspberry Pi RP2040 silicon chip, squeezing the processing power of a standard Raspberry Pi Pico into a tiny form factor roughly the size of a postage stamp.

More information from the board: https://www.waveshare.com/wiki/RP2040-Zero

RP2040-Zero Core Hardware Specifications

RP2040-Zero Pinout

RP2040-Zero Pinout

RP2040-Zero/Eth I²C communication

Primary Hardware I²C Pin Pairs on RP2040-Zero

The main pins for hardware I²C on the Waveshare RP2040-Zero are GP0 (SDA) / GP1 (SCL) or GP4 (SDA) / GP5 (SCL):

i2c = machine.I2C(0, scl=machine.Pin(1), sda=machine.Pin(0))

Since the RP2040 chip has a versatile digital network matrix (pin multiplexing), nearly any GPIO pin can be configured for I²C. Nevertheless, the typical hardware blocks (I²C_0 and I²C_1) are most straightforwardly accessed with the configurations below.

Hardware BlockSDA (Data)SCL (Clock)Location on RP2040-Zero
I²C_0 (Standard)GP0GP1Top-left edge pins.
I²C_1GP4GP5Left edge, mid-bottom pins.
I²C_1 (Alternative)GP26GP27Bottom edge pins (Shared with ADC0/ADC1).

Key Electrical Requirements

RP2040-Zero/Eth UART communication

To enable UART (serial communication) on the Waveshare RP2040-Zero/Eth, you can use its two dedicated hardware UARTs: UART0 and UART1. The RP2040's flexible pin multiplexing allows these UART peripherals to be assigned to various GPIO pins on your board.

Default Hardware UART Pin Mapping

While you can map UART to multiple pins, the standard layout for the RP2040-Zero relies on these primary pins:

PeripheralTX PinRX Pin
UART0GP0GP1
UART1GP4GP5

Here is how to initialize and use UART0 at a standard baud rate of 9600 to send and receive data:

import machine
import utime
 
# Initialize UART0 on GP0 (TX) and GP1 (RX)
# Common baud rates: 9600, 115200
uart = machine.UART(0, baudrate=9600, tx=machine.Pin(0), rx=machine.Pin(1))
 
print("UART0 Initialized. Waiting for data...")
 
while True:
    # 1. Sending Data
    uart.write("Hello from RP2040-Zero!\n")
 
    # 2. Receiving Data (Check if any bytes are waiting in the buffer)
    if uart.any():
        # Read the incoming data bytes
        incoming_bytes = uart.read()
 
        # Convert bytes to a readable string
        incoming_text = incoming_bytes.decode('utf-8', errors='ignore')
 
        print(f"Received: {incoming_text.strip()}")
 
    utime.sleep(1)

Note: The RP2040 works only with 3.3V logic. When connecting it to a 5V device, such as an older Arduino Uno, always use a logic level shifter to protect the RP2040 pins.

RP2040-Zero/Eth Built-in temperature sensor

The Waveshare RP2040 features a built-in temperature sensor integrated directly inside the RP2040 microcontroller. It works by measuring the internal temperature of the silicon chip rather than the ambient room temperature.

Sensor Characteristics

MicroPython Code Example

import machine
import utime
 
# Configure ADC channel 4 for the internal sensor
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)
 
while True:
    # Read the raw 16-bit ADC value
    reading = sensor_temp.read_u16() * conversion_factor
 
    # Calculate temperature in Celsius based on the RP2040 datasheet
    temperature = 27 - (reading - 0.706) / 0.001721
 
    print(f"Chip Temperature: {temperature:.2f} °C")
    utime.sleep(2)

RP2040-Zero/Eth WS2812 RGB LED

The WS2812 RGB LED is operated through a single data line connected to pin GP16, enabling programming of unique colors and blinking effects.

To control the onboard WS2812 RGB LED on the RP2040-Zero, use the neopixel library and connect it to GP16, which is the correct pin for this board:

import machine
import neopixel
import time
 
# The RP2040-Zero onboard RGB LED is connected to GP16
RGB_PIN = 16
NUM_PIXELS = 1
 
# Initialize the NeoPixel object
pixels = neopixel.NeoPixel(machine.Pin(RGB_PIN), NUM_PIXELS)
 
def set_color(r, g, b):
    """Sets the RGB LED color (values from 0 to 255)"""
    pixels[0] = (r, g, b)
    pixels.write()
 
# Cycle through Red, Green, Blue, and White
while True:
    set_color(255, 0, 0)    # Red
    time.sleep(1)
 
    set_color(0, 255, 0)    # Green
    time.sleep(1)
 
    set_color(0, 0, 255)    # Blue
    time.sleep(1)
 
    set_color(50, 50, 50)   # Dim White
    time.sleep(1)

RP2040-Eth

RP2040-eth The RP2040-eth is an ultra-compact, low-cost microcontroller development board designed by Waveshare. It is built around the Raspberry Pi RP2040 silicon chip, squeezing the processing power of a standard Raspberry Pi Pico into a tiny form factor roughly the size of a postage stamp.

More information from the board: https://www.waveshare.com/rp2040-eth.htm

RP2040-Eth Core Hardware Specifications

RP2040-Eth Features

RP2040-eth Pinout

RP2040-eth Pinout

RP2040-Eth I²C communication

See: RP2040-Zero/Eth I²C communication

RP2040-Eth UART communication

See: RP2040-Zero/Eth UART communication

RP2040-Eth Ethernet communication

The RP2040 communicates internally with the CH9120 Ethernet chip using a dedicated UART serial interface and control pins:

CH9120 PinRP2040 PinFunction
RXDGP21Serial Data Input
TXDGP20Serial Data Output
TCPCSGP17TCP Client Connection Status
CFG0GP18Serial Debug / Configuration Enable
RSTIGP19Hardware Reset (Active Low)

The integrated CH9120 chip supports four selectable communication protocols:

Network Configuration

The code for configuring the operating mode, IP, gateway, subnet mask, port number, and serial port baud rate is located in the Python/RP2040-ETH-Demo/RP2040-ETH-Demo.py file. You can modify it according to your specific requirements.

MODE = 1  #0:TCP Server 1:TCP Client 2:UDP Server 3:UDP Client
GATEWAY = (192, 168, 1, 1)    # GATEWAY
TARGET_IP = (192, 168, 1, 10) # TARGET_IP
LOCAL_IP = (192, 168, 1, 200) # LOCAL_IP
SUBNET_MASK = (255,255,255,0) # SUBNET_MASK
LOCAL_PORT1 = 1000            # LOCAL_PORT1
TARGET_PORT = 2000            # TARGET_PORT
BAUD_RATE = 115200            # BAUD_RATE

Raspberry topics on lamaPLC

This page has been accessed for: Today: 6, Until now: 58