Raspberry Pi Pico

News

  • 7-14-2022: Added TFT GUI code examples which include wire frame OpenGL graphics which can be controlled with the touch screen and push button widgets. Also updated the Lib directory of functions for new OpenGL features (both OLED and TFT versions).

  • 6-07-2022: Added Veeprom (Virtual EEPROM) to library and terminal based tester project. This set of functions use flash memory to emulate a EEPROM for storing parameters that survive a power down. This is useful for saving calibration values or user settings.

  • 5-29-2022: Updated Tft schematic for touch screen interface to ADC inputs of Pico and updated TFT projects to include hardware_adc library since the TFT access functions now have code to read the touch screen with gfFetchTouch() function.

  • 5-27-2022: Added OpenGL support for 320x240 Elegoo 2.8 inch TFT display and included some projects to demo the features. Also, updated the OLED projects to remove hard coded display size and now make GLUT calls to figure out the window size to use.

Note: When downloading files, click the circled icon at the top of the new page to retrieve the file.

Basics

    • Where to buy ($4) and how to get set up with a free development environment:

raspberrypi.com/products/raspberry-pi-pico

Libraries

    • Lib.zip: C library files: (7-08-2022)

      • Veeprom: Implements a virtual EEPROM with 255 (32,24,16 or 8)-bit locations in flash using two sectors based on an application note from Microchip. The code allows the number of sectors and number of locations to be modified with compile time constants. Also, the word size can be 1,2,3 or 4 bytes.

      • OglTft: Same as OglOLED except for TFT display. A tiny implementation of OpenGL and GLUT for wireframe 3D graphics.

      • Tft320x240: Code to interface to Elegoo 2.8 inch TFT display in immediate mode

      • Tft320x240Fb: Code to interface to Elegoo 2.8 inch TFT display in frame buffer mode. Requires a call to UpdateDisplay to transfer internal frame buffer to the display (used with OglTft).

      • TFT320x240Wfb: Windowed enhancements to work with GUI code to run OpenGL in a window.

      • DispRnfWire: Simpler version of 3D model and animation player for use with models exported from Create3D for use with an OLED display.

      • OglOLED: Tiny implementation of OpenGL and GLUT for 128x64 OLED display for wireframe 3D graphics using the same code that runs on Windows.

      • OLED128x64: Code to interface to a 128x64 I2C OLED display.

      • Serial: Code to use the USB interface as a serial port with some bug work-arounds.

Projects

TFT GUI (Widgets and OpenGL in a window)

Pico Projects: also need Lib.zip

  • TftGuiSimple.zip (V1.0 6-18-2022) Simple GUI elements for first example

  • TftGui1.zip (V1.0 6-18-2022) Overly complex GUI elements which includes a dual 2D graphics display and free drawing screen.

  • TftGui3d1.zip (V1.0 6-24-2022) Wireframe OpenGL 3D graphics in a window with GUI elements.

  • TftGui3d2.zip (V1.0 7-04-2022) Wireframe OpenGL 3D graphics in multiple windows with GUI elements. Also using touch to allow the 3D views to be manipulated.

  • TftGuiRnf1.zip (V1.0 7-08-2022) Wireframe OpenGL 3D animations in a single window from Create3d editor. The colors can be modified and saved in VEEPROM so that they remain through a power cycle. The view can be manipulated using the touch screen.

  • TftGuiRnf2.zip (V1.0 7-08-2022) Wireframe OpenGL 3D animations in multiple windows from Create3d editor. The colors are taken from the 3D models made with Create3d. The view can be manipulated using the touch screen.

Tools:

  • CreateLcdGui: Visual GUI creation tool used generate gui.c and gui.h files from *.gui files in the above project.

    • LcdGuiPico.pdf: Overview of writing GUI code handlers describes TftGuiSimple and TftGui1 examples.

  • Create3D: 3D modeling and editor to create the RNF wireframe models.

Schematic: PicoTFT.pdf (V1.1 2-29-2022)

These projects demonstrate how to use the visual GUI creator tool to make basic (a few buttons) to complex projects (multi-window OpenGL animations). Check out the video above to get an idea of what is possible.

Note that for non-3D GUI code no extra definitions are required in the CMakeLists.txt file. For wireframe OpenGL GUI code the following is needed to set some #define values:

target_compile_definitions(${PROJECT_NAME} PRIVATE

VEE_PAYLOAD_SIZE=4 # Can be 4,3,2 or 1 byte per word or not included

VEE_VALID_BUFFER_MARKER=0x1861 # can be any 16 bit number or not included

TFT_OGL_WINDOWED=1 # required for 3D graphics in a window

PICO_MALLOC_PANIC=0 # Allow malloc to return NULL instead of killing program

)

The VEE_* lines are optional. By default, the virtual EEPROM code uses a payload size of 4 bytes but the calibration code works with a size of 1,2,3 or 4 bytes so this can be set to any size the is good for the application if it will store other values. If no other values will be saved, leave it at 4 as that is the most efficient size. The VEE_VALID_BUFFER_MARKER should be different for each application so that values from a previous project loaded into the Pico are not misinterpreted.

VEEPROM (Virtual EEPROM)

Pico Projects: Veeprom.zip (V1.0 6-07-2022) also need Lib.zip

Schematic: Just software

This project uses the library files Veeprom.c and Veeprom.h to exercise a virtual EEPROM implemented in flash memory. The algorithm used is based a Microchip application note AN1095. The goal is to increase the endurance over that of flash memory and to use much less flash memory than one sector per word to be stored. The project includes a terminal based interface to test the code by writing random data to random addresses and then reading it back to check the results. I've had no problems writing 100,000 32-bit values to multiple Picos and using just two sectors of flash.

Compile time constants that can be changed are listed below. If these values are not overridden in the CMakelist.txt (target_compile_definitions [see the CMakelist.txt of the project for an example]), default values are defined in the library file Veeprom.c.

VEE_PAYLOAD_SIZE:

Size in bytes of the word to be stored. Must be 1 to 4

VEE_VALID_BUFFER_MARKER:

Random 1 to 4 byte value (set by VEE_VALID_BUFFER_MARKER_SIZE) to mark a valid buffer. This value should be different for different applications so that stale data from an old app loaded into a Pico is not used in a new one.

VEE_ERASED_BUFFER_MARKER:

0xff, 0xffff, 0xffffff or 0xffffffff depending on VEE_VALID_BUFFER_MARKER_SIZE

VEE_VALID_BUFFER_MARKER_SIZE:

Size in bytes of VEE_VALID_BUFFER_MARKER

VEE_NUM_SECTORS_PER_BUFFER:

Number of sectors to use per buffer (which there are two) to store the data. The default size is 1. This should only need to increase if planning on doing millions of writes or hacking the code to create a payload size way greater than 4.

TFT Display Fun

Pico Projects: also need Lib.zip

  • TftRandom.zip (V1.2 5-29-2022 to 6-17-2022) Random 2D graphics in immediate mode

  • Tft3d1.zip (V1.2 5-29-2022 to 6-17-2022) Wireframe 3D graphics using OpenGL

  • Tftrnf2.zip (V1.2 5-29-2022 to 7-08-2022) Wireframe 3D animations using RNF/OpenGL from Create3D

Schematic: PicoTFT.pdf (V1.1 2-29-2022)

These projects are similar to the OLED projects except using a larger color display. The display is a 320x240 Elegoo 2.8 inch TFT display. Tft3d1 is the same as OLED3d2 except more points on the ring. Tftrnf2 is identical to OLEDrnf2 except it uses the OglTft instead of OglOLED library of functions. The animations and models in Tftrnf2 are the same files as OLEDrnf2 which were produced with Create3D.

Currently, only using one core of the Pico since there is not enough RAM to implement double buffering. The performance is similar to the OLED code.

3D Graphics from Create3D using OpenGL on OLED Display

Pico Project: OLEDrnf2.zip (V1.1 5-17-2022 to 7-08-2022) also need Lib.zip

Schematic: PicoOLED.pdf (V1.0 2-21-2022)

This project builds on top of the OpenGL on OLED Display code to play animations of models produced by Create3D. This is a free tool I wrote using HP UNIX graphics workstations [HP-UX] back in the early 1990s. I ported it to Windows in the late 1990s and add a few features here and there. Years ago I was a 3D graphics hardware designer at HP and liked to make demos to show off our hardware.

3D Graphics using OpenGL on OLED Display

Pico Project: OLED3d2.zip (V1.1 4-24-2022 to 5-26-2022) also need Lib.zip

Schematic: PicoOLED.pdf (V1.0 2-21-2022)

This project implements a subset of OpenGL and GLUT to drive a tiny 128x64 pixel I2C Organic Light Emitting Diode display. The main core handles the application, 3D transforms, 3D clipping, perspective divide and line drawing while the 2nd core handles updating the display and clearing the frame buffer for the next image.

The same application code that is running on the Pico compiles and runs the same on Windows (using Visual Studio 2022 and freeglut from sourceforge.net).

OLED Display

Pico Project: OLEDDisplay.zip (V1.1 1-21-2022 to 3-28-2022) also need Lib.zip

Schematic: PicoOLED.pdf (V1.0 2-21-2022)

This project displays animated text and graphics on the display. This uses the OLED128x64 file in the library Lib.zip which can be found above.

Servo Control

Animation/Control Editor

Pico Project: Servo2.zip (V1.0 1-21-2022) also need Lib.zip

Schematic: PicoServoController.pdf (V1.0 2-22-2022)

Windows Code: ServoCnt.zip

This project controls up to 16 servos with spline curve control to allow smooth transitions between key positions. This code is used with Windows based software to control a robot arm like 3D graphics animation using key frames. This uses the Serial file in the library Lib.zip which can be found above.

The video above was done using the PIC18F1330 version (see the PIC page) of the servo controller but the PICO version behaves the same. I just have not made a new video.