Simple VGA driver using Pico and micropython

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Hugh-maingauche
Posts: 15
Joined: Sun Aug 15, 2021 9:34 pm

Simple VGA driver using Pico and micropython

Post by Hugh-maingauche » Sun Mar 06, 2022 5:34 pm

Hello All,

I came out with this simple driver, writen entirely in micropython, (v1.18 pico firmware), allowing to use a VGA screen with a 640x480 resolution and 3 bits per pixel (8 colors).
My purpose was just to learn how to use PIO programming and synchronization with DMA, but I might as well share the result of this with the community.

Since the pico does not have a tremendous amount of memory for this kind of usage, I saved space by using 32 bits words (and only using 30 bits out of them).

In the end the buffer for the whole frame takes 120k of RAM, wich leaves the PICO with approx 50k to do some stuff with micropython

Synchronization between PIO and DMA is achived using PIO Irqs.

I got inspiration from :
- This project (for the pico, written in c) very well documented by V. Hunter Adams (vha3@cornell.edu) https://vanhunteradams.com/Pico/VGA/VGA ... ganization
- The explanations provided on this forum by Roberthh and the tools he posted on github https://github.com/robert-hh/RP2040-Exa ... r/rp2_util

I added the possibility to overclock the pico to 250MHz, but in the end it does not really impact the picture quality. I coded a few routines to draw rectangles/lines/circle, for testing purpose.

I tried to document the code as much as I could. Since I am still a beginner, I have no doubt that this can be optimized quite a lot.
If any of you is interested in using or improving it, i'll be happy to provide further explanations.

Code is here : https://github.com/HughMaingauche/PICO-VGA-Micropython

Image
Attachments
20220306_174803.jpg
20220306_174803.jpg (157.03 KiB) Viewed 3864 times

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Simple VGA driver using Pico and micropython

Post by pythoncoder » Tue Mar 08, 2022 9:50 am

If you're a beginner that's extremely impressive! :D
Peter Hinch
Index to my micropython libraries.

Hugh-maingauche
Posts: 15
Joined: Sun Aug 15, 2021 9:34 pm

Re: Simple VGA driver using Pico and micropython

Post by Hugh-maingauche » Wed Mar 09, 2022 10:32 pm

Hello pythoncoder,

well when i see you guys on this forum i really feel like i am a beginner. This thing took me 2 weeks and a lot of thinking (and also a scope). I turned 50 recently and I am totally amazed by the capabilities of such a small device.

I think this pico can do more than the CPC 464 i've had on my 14th birthday. To make sure of this I implemented a simple font and draw some nice plots !!! (see below)
2022-03-09 232855.jpg
2022-03-09 232855.jpg (159.24 KiB) Viewed 3734 times

User avatar
andypiper
Posts: 25
Joined: Wed Feb 02, 2022 12:17 pm
Location: Kingston upon Thames, UK
Contact:

Re: Simple VGA driver using Pico and micropython

Post by andypiper » Sun Mar 20, 2022 7:01 pm

This looks really neat. Out of interest, what VGA board / adapter are you using to connect to the Pico? It looks like something separate, rather than something like the Pimoroni base with VGA. #curious

Hugh-maingauche
Posts: 15
Joined: Sun Aug 15, 2021 9:34 pm

Re: Simple VGA driver using Pico and micropython

Post by Hugh-maingauche » Mon Mar 28, 2022 8:52 pm

Hello andypiper,

there is no VGA board, the pico GPIO pins are connected directly to the VGA cable via 300ohms resistors to drop the 3.3V to 0.7V on the red/blue/green inputs, and 47ohms resistors for impedance adjustment on the Hsync/Vsync inputs.

It is connected to the VGA cable via a simple header (see here) and that is maybe what you think is a separate board.

There is nothing more on the picture. The black square-shaped thing you see on my breadboard is a 3.3v lithium battery which is not related and not wired to anything.

Post Reply