Page 1 of 1

Simple VGA driver using Pico and micropython

Posted: Sun Mar 06, 2022 5:34 pm
by Hugh-maingauche
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

Re: Simple VGA driver using Pico and micropython

Posted: Tue Mar 08, 2022 9:50 am
by pythoncoder
If you're a beginner that's extremely impressive! :D

Re: Simple VGA driver using Pico and micropython

Posted: Wed Mar 09, 2022 10:32 pm
by Hugh-maingauche
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 4144 times

Re: Simple VGA driver using Pico and micropython

Posted: Sun Mar 20, 2022 7:01 pm
by andypiper
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

Re: Simple VGA driver using Pico and micropython

Posted: Mon Mar 28, 2022 8:52 pm
by Hugh-maingauche
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.