VGA library for Arduino UNO and ATMega328


Hello everyone, i've created a VGA library for Arduino UNO. Here you can download it. The library implement a 120x60px framebuffer where each pixel is stored as 2 bits (4 colors). The framebuffer is stored inside SRAM. The 4 colors generated from the library are not predefined. You can connect two of the VGA connector pins in different ways, selecting the color combination that you prefer. To use this library you need only 4 resistors and one DSUB15 connector.


Based on the VGA color video generation by Nick Gammon. Inspired from the game Toorums Quest by Peten Paja. AVR interrupt dejitter from Charles CNLOHR.

Happy Hacking!!

Excellent !! I also tried colour but I had a tiny jitter problem which I couldnt find a way to solve

One of the 8 colour drivers I did was for the ATTiny13A (amongst others) Forum Post youTube Video you can see the jitter problem near the end of the video

Cheers :)

Hi Mcnobby, your ATTINY project is great!

I've seen the video and your sourcecode. The problem can be a little jitter in the execution of your interrupt function (1clock or more of delay that depends on the instruction that is in execution when the interrupt happens) . I have got a similar problem but in my case the signal was more disaligned (1pixel or more). I've saw this video by Charles CNLOHR before i realized the problem.

Otherwise can be a clock problem.. Have you looked the signal with an oscilloscope? It's ok?

Thanks very much, I just like trying to squeeze every ounce out of little chips !!

It is a timer interrupt clock cycle issue, one day I will fix it and hopefully keep it under 1k !!

Do you have any videos/youTube smaffer ?

Here are some of my videos:

Here is my twitter account:

Very good smaffer !! :)

I dont have twitter, but I subscribed to your youTube :)

Dear Smaffer,

I want to thank you again in this post for your VGA library.
I have created a new post for the Arduino color game I have done using it, here it is the link.

You can find the code as well.

Thank you Rob Cai! Good work!

I had a close look at your code today, just trying to see the difference between VGA and composite (PAL)

I believe the VGA line is 32us, whereas the composite line is 64us, so basically it is much harder to squeeze pixels into a VGA signal !

I have just written a new PAL driver for ATMega1284, its 352*280px, it reads BMPs off an SDcard and displays on the TV… I still havent implemented that jitter fixer… I havent got my head round it yet !!

I am using timer1 running flat out at 24MHz, I really wanted 32MHz but the '1284 couldnt handle it !! ha ha

Be really good to get the screen flicker free

ANYWAY… your project looks awesome, I must try it when I get a chance !!

Hello Smaffer, if you are using a CLS() in your library then perhaps consider THIS post.. I was asking for a way to clear a large array really fast, this was the video array in TVout

Some of the answers are quite interesting, in the end I decided to treat chunks of the array as uint64_t's and clearing them with one line

Also I considered writing an ASM routine that sits in the interrupt somewhere that will clear the display between writing frames to remove any flicker

I am now writing a simplified version of your code for an ATMega8


mcnobby: you can see the jitter problem near the end of the video

Cheers :)

I haven't looked at your code but I found jitter unless I put the processor to sleep (idle mode). It wakes up instantly and always on the same clock cycle so-to-speak.

Here, in particular:

  while(1) { // this is the main loop
    if (timer == 2) {
      // timed code here....

You are waiting for the ISR to fire anyway, and when it does you will have a few clocks before you notice if timer == 2. So add a sleep:

  while(1) { // this is the main loop
    sleep_mode ();   // wake in a predictable way
    if (timer == 2) {
      // timed code here....

In initialization, make sure sleep mode is idle:

  set_sleep_mode (SLEEP_MODE_IDLE);

Hi guys, i have created a small game for Arduino UNO, using my VGAX library. The game is called BIT NINJA and is a classic retro platform game like super mario bros. All the graphics and sounds are on flash (around 16k, for now). The gameplay is done using around 40 bytes of SRAM.

YouTube video: LINK

Some of the code is taken from my program "maffiodo1" of the 23rd International Obfuscated C Code Contest (2014) (program screenshot1 screenshot2)

When the game will be finished i will publish the sourcecode online.

Happy hacking!

Has anybody tried using the VGAx Library on an Arduino Mega? what whould i consider? i tried using the same pins but couldnt make it work.


I have the color bar sketch working from Nick Gammon's tutorial at

I notice smaffer's schematic dropped the blue connection (pin 3 on the vga connector) and it's associated 470 ohm resistor. Was that on purpose? and why?

It is explained in the first post, but not in depth. This offers 2 bits, so 4 colours (or states as you wish). You have to decide what colours you choose, you could as well drop red or green to get an other set of colours. One of these states is 00, no colour, so black. You could also choose to have blue HIGH all the time, to get another extra palette. 00 would be blue. 01 would be purple. 10 would be cyan. And 11 would be white.

The reason is storage; to get a reasonable resolution, just drop a third of the memory needed. I can imagine it also saves some timing trouble, and it would help against the reported misalignment (chance of that would grow larger each added bit per pixel).

I am in the same situation as adgm1988, I attempted to run this on a Mega2650 using the same pins as the UNO and it didnt work. (tested with an uno, works ok so its not my dsub/resistor arrangement)

Are there any obvious reasons why it shouldnt work ? might it be something timer related ? I'd like to run it on a 2560 ideally so I can use Rugged Circuits QuadRam 512kb SRAM expansion, I thought it might be quite promising.

update - I managed to get Nick Gammon's VGA demo to work on the Mega2560, I'm not sure what might be different in VGAx any help would be appreciated.

Did someone try to use I2C with this library? Or will communicating via i2c break the VGA output?

The interrupt-handling required by I2C might throw out the VGA timings.

Off the back of Smaffers VGAX, I wrote a nice bit of code that drives a VGA monitor in 17bit colour Works on a Nano (and UNO) and seems quite smooth

Here it is in one project decoding 250kbps data streams presenting as a bar graph

Next UNO/VGA projects will involve a 16 input analogue voltage visualiser, colour spectrum analyser using FFT, and to finish the above youTube project with all its diagnostic DMX features

I absolutely LOVE driving video/TV/VGA from these little jiggers, for me it all started with the TVout library, then all Nicks investigations, AtomicZombie, and finally Smaffers code

I hope one day to post some really awesome projects, and show how sections of line handling can be driven using a really simple indexed array of vectors, which runs really fast (of which time is an absolute premium on VGA !)