Raspberry Pi Pico 2

The Raspberry Pi Pico 2 is Raspberry Pi's successor to the Raspberry Pi Pico board, based on their new RP2350 processor:

RaspberryPiPico2.jpg

The RP2350 has the following features:

  • Dual ARM Cortex-M33 or dual RISC-V Hazard3 processors @ 150MHz

  • 520 KB on-chip SRAM; 4 MB on-board QSPI flash

  • 26 multi-purpose GPIO pins, including 4 that can be used for ADC

  • 2 × UARTs, 2 × SPI controllers, and 2 × I2C controllers

  • 24 × PWM channels

  • 1 × USB 1.1 controller and PHY, with host and device support

  • 12 × PIO state machines

The Raspberry Pi Pico 2 provides over twice as much workspace as the RP2040-based Raspberry Pi Pico, and is significantly faster. The presence of both ARM and RISC-V cores is an interesting development, meaning it could be possible to run both ARM and RISC-V machine code. For more information see Raspberry Pi Pico 2.

The Raspberry Pi Pico 2 is available from several suppliers; for example, in the UK from The Pi Hut: Raspberry Pi Pico 2.

Introduction

Saving the workspace

The Raspberry Pi Pico 2 uses the LittleFS flash filesystem supported by the Raspberry Pi Pico/RP2040/2350 core to allow you to save the entire workspace using save-image.

ARM assembler

The ARM version of uLisp includes an ARM assembler that allows you to generate machine-code functions, integrated with Lisp, written in ARM thumb code. The assembler itself is written in Lisp to make it easy to extend it or add new instructions. For more information see ARM assembler overview.

Installing uLisp from the Arduino IDE

Install the Raspberry Pi RP2040/RP2350 core

  • Add the following URL to the Additional Boards Manager URLs list in the Arduino IDE Preferences dialog box:
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
  • In the Arduino IDE search for the Raspberry Pi Pico/RP2040/RP2350 core in Boards Manager and install it.
  • Select Raspberry Pi RP2040 from the Board menu, and Raspberry Pi Pico 2 from the submenu.
  • Set Flash Size to the option that gives FS: 1MB. On the Raspberry Pi Pico 2 this is 4MB (Sketch: 3MB, FS: 1MB).

This allocates enough space for use by LittleFS to save the entire workspace with save-image.

You can leave all the other options at their defaults.

Upload uLisp

  • Download the latest ARM version of uLisp from the Download uLisp page.
  • Select the board's USB port from the Port menu
  • Upload uLisp to the board.

Using uLisp

  • You may need to select the board's USB port from the Port menu again.
  • Select Serial Monitor from the Tools menu.
  • Enter Lisp commands.

Putting the board into upload mode

If the upload fails you may need to put the board into upload mode first.

  • Unplug the USB port.
  • Press and hold the BOOTSEL button.
  • Plug in the USB port.
  • Release the BOOTSEL button.

Error on save-image

If when you call save-image you get the error;

Error: 'save-image' problem saving to LittleFS

the most likely explanation is that you didn't set the Flash Size option to the appropriate value to reserve memory for LittleFS before uploading uLisp.

Pinout

The following diagram shows the pinout of the peripherals available from uLisp with the Raspberry Pi Pico 2:

Pico2Pinout.gif

LEDs

The Raspberry Pi Pico 2 has a green LED connected to the digital pin 25 which you can flash with the following program:

(defun blink (&optional x)
  (pinmode :led-builtin t)
  (digitalwrite :led-builtin x)
(delay 1000) (blink (not x)))

Run it by typing:

(blink)

All pins can also be used for analogue (PWM) output, so you can pulsate the LED slowly on and off with the program:

(defun pulse ()
  (let (down)
    (loop
     (dotimes (x 256) 
       (delay 5) 
       (analogwrite :led-builtin (if down (- 255 x) x)))
(setq down (not down)))))

Run it by typing:

(pulse)

Exit from either program by entering ~.

Analogue inputs

The Raspberry Pi Pico 2 has three analogue inputs which you can access on digital pins 26, 27, and 28. They have 12-bit precision.

Analogue outputs

You can generate an analogue output using PWM on any of the digital pins 0 to 28. By default the precision is 8 bits, but you can change it to a value from 4 to 16 bits by calling, for example:

(analogwriteresolution 16)

Playing notes

You can use the note function to play tunes on any pin. For example, the following function scale plays the scale of C on the specified pin:

(defun scale (pin) 
  (mapc 
   (lambda (n) (note pin n 4) (delay 500))
   '(0 2 4 5 7 9 11 12)) 
  (note))

For example, connect a piezo speaker between digital pin 10 and GND, and evaluate:

(scale 10)

Serial

The Raspberry Pi Pico 2 has two serial ports: Serial1 on pin numbers 0 (TX) and 1 (RX), and Serial2 on pin numbers 8 (TX) and 9 (RX).

SPI

The Raspberry Pi Pico 2 has two SPI ports: SPI0 on pin numbers 16 (MISO), 19 (MOSI), 18 (SCK) and 17 (SS), and SPI1 on pin numbers 12 (MISO), 15 (MOSI), 14 (SCK) and 13 (SS).

I2C

The Raspberry Pi Pico 2 has two I2C ports: Wire0 on pin numbers 4 (SDA) and 5 (SCL), and Wire1 on pin numbers 26 (SDA) and 27 (SCL).