Raspberry Pi Pico
News
6-05-2024: Added the 3D GPU project which uses a Lattice FPGA driven by a Pico.
5-29-2024: Updated Lib.zip to include code interface Pico to Lattice FPGA GPU connected to a TFT display to perform 3D solid model graphics with lighting using OpenGL calls.
7-20-2023: Updated WebServer class to handle WiFi connection loss and reconnect without user intervention. Also, made first connect retry forever unless new optional 3rd parameter to Init is set to INIT_SINGLE_TIMEOUT.
7-13-2023: Added documentation to the WebServer class and examples.
7-05-2023: Added Pico W on-the-fly web creation examples and web server class in C++. Also, update Lib.zip to include WebServer, HtmlHelper and JavaScript C++ classes to aid in the creation of on-the-fly web pages which are able to use AJAX to display real-time data.
Contact:
Send email to ted_rossin at yahoo
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:
Libraries
Lib.zip: C library files: (5-29-2024)
DispRnfSolid.c: 3D model and animation player for use with models exported from Create3D for use with Lattice FPGA GPU controlled TFT display.
OglSolid.c: Implementation of OpenGL and GLUT for 3D graphics (lights and solid models) for use with Lattic FPGA GPU controlled TFT display.
Tft320x240Gpu.c: Code to interface to Elegoo 2.8 inch TFT display via Lattice FPGA based GPU.
GpuWr.pio: PIO program to drive 16 bit FPGA interface
WebServer: C++ class on top of LwIP to create a much easier to use web server interface.
HtmlHelper: C++ class to ease some of the chores of web page creation as well as parsing requests from buttons and image requests.
JavaScript: C++ class to make it easier to create JAVA script and Canvas webpages as well as some helper functions to handle AJAX requests and to move data around.
SDFileIO: Implements standard C file I/O (fopen, fclose, fread, fwrite, fputs, fgets, fseek, ftell, and fprintf.
SDFs: Implements a unix like file system using an SD card connected to an SPI port.
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
Solid 3D graphics using Lattice FPGA based GPU to a TFT display
Pico Projects: TftSolid3d.zip (V1.0 5-29-2024 to 5-29-2024) also need Lib.zip
FPGA Source: See the Lattice Page
Schematic: None. Have to read the code to get the ugly wiring.
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 solid models.
This is a collection of example OpenGL projects that demonstrate how to draw solid model 3D graphics using the Raspberry Pi Pico connected to an Alchitry Cu FPGA programmed up with GPU code and connected to a 320x240 TFT display with 4 RAM chips. The RAMs implement a frame and depth buffer. The PIO is used to interface to the FPGA to get reliable speed (damn that tiny 2 way set associative cache!).
The FPGA controls the LCD display and RAM to form a Z-buffered 3D system which can draw 3D depth tested triangles to form solid objects on the screen. The LCD controller in the FPGA is able to draw 2D vectors, rectangles as well as copy the frame buffer into the LCD display. The controller also clears the buffers for the next frame to be drawn. The Raspberry Pi Pico implements the OpenGL pipeline up to rasterizing triangles which is done by the FPGA. The Pico converts OpenGL function calls into triangles and applies 3D transforms, lighting calculations as well clipping before sending the triangle vertex and color data to the FPGA to be drawn.
Triangle and span rendering uses fixed point math and the machine snaps the starting points by interpolating the pixel values based on words/equations from p. 20 of "Advance Animation and Rendering Techniques". This is what prevents flashing at triangle seams in animations.
Web Server (on-the-fly) in C++ using Pico W
Pico W Projects: WebDemos.zip (V1.0 7-01-2023 to 7-03-2023) also need Lib.zip
Documentation: PicoWebserver.pdf (V1.1 7-20-2023)
Schematic: None. Works with bare board.
This is a collection of six example projects that go from simple (boring text[WebSimple]) to more complex (real-time graphs of the processor temperature [WebAjax2]) that serve up web pages using the Pico W. The projects are in C++ and use a WebServer class that is found in the Lib.zip package. The WebServer class uses LwIP to move data between the client (web browser) and the server (Pico W) in a way that allows web pages to be created on the fly using real-time data.
Seeed Studio OpenGL on OLED display
Pico Project: OLEDrnf2.zip (V1.2 5-17-2022 to 8-23-2022) also need Lib.zip
Schematic: PicoSeeedOLED.pdf (V1.0 9-03-2022).
This is the same code as OLEDrnf2 except it and the I2C library have been modified to work with the tiny Seeed Studio board. Makefile.txt has a line that needs to be uncommented that has SEEED_PICO=1 in it at the end of the file.
SD Card File System
Pico Project: SdFileSystem.zip (V1.0 8-17-2022) also need Lib.zip .
Schematic: PicoTFTwithSD.pdf (V1.0 8-09-2022)
This project demonstrates a file system by implementing a tiny UNIX like shell using a serial port and SD card plugged into a TFT display socket. Commands implemented are:
ls, cd, pwd, cat, new, cp, rm, mkdir, date, setdate, df, unmount, mount
TFT Digital Picture Frame
Pico Project: TftPicFrame.zip (V1.0 8-11-2022) also need Lib.zip
Tools:
ImgCrop: Tool to convert JPEG images to the format needed by the TFT display.
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.
Schematic: PicoTFTwithSD.pdf (V1.0 8-09-2022)
This project implements a small digital picture frame using a TFT display. Note that the pictures above are from the finished product made with a PIC processor but the the Pico project behaves the same.
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 added 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
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.