This post shows how to connect VGA monitor with Arduino UNO board in order to draw shapes (lines, circles …) and print texts with resolution of 160×64 pixel.
VGA: Video Graphics Array
Hardware required:
- Arduino UNO board
- VGA monitor
- 2 x 68 ohm resistor
- 220 ohm resistor
- VGA connector
- Breadboard
- Jumper wires
Interfacing Arduino with VGA monitor circuit:
Example circuit diagram is shown below.
HSYNC (horizontal synchronization) pin of the VGA connector (pin #13) is connected to Arduino digital pin 3 through 68 ohm resistor.
VSYNC (vertical synchronization) pin of the VGA connector (#14) is connected to Arduino digital pin 10 through 68 ohm resistor.
Color pins (R: red, G: green, B: blue) of the VGA connector (respectively #1, #2 and #3) are connected together in order to get white and black colors, they are connected to Arduino digital pin 7.
Interfacing Arduino with VGA monitor code:
The following Arduino code requires two libraries:
The first library is a simple and small library for generating the required signals (VSYNC, HSYNC and video).
The VSYNC (vertical synchronization) signal is generated on pin 10.
The HSYNC (horizontal synchronization) signal is generated on pin 3.
The video signal is generated on pin 7.
Timer2 Module is configured to generate a compare match interrupt every 32 microseconds (31.25 kHz), the horizontal synchronous pulse is generated as a PWM signal with frequency of 31.25 kHz. Within this interrupt the Arduino outputs vertical synchronization pulse and video signal.
This library disables Timer0 interrupt which means the following functions will not work anymore:
unsigned millis();
unsigned long micros();
void delay(ms);
void delayMicroseconds(us);
Instead of delay(ms) function the VGA library has an other one with the same name.
Arduino VGA library can be downloaded from the following link:
Arduino VGA library
After the download of the library, put its files (VGA.h and VGA.ccp) in Arduino sketch folder.
The VGA library works with Adafruit graphics library which can be downloaded from the following link:
Adafruit graphics library —-> direct link
Full Arduino code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | /************************************************************************* * * VGA output with Arduino (white and black colors). * This is a free software with NO WARRANTY. * http://simple-circuit.com/ * ************************************************************************/ #include <Adafruit_GFX.h> // include Adafruit graphics library #include "VGA.h" // include VGA library // initialize the VGA library VGA display = VGA(); void setup(void) { // initialize the VGA display display.begin(); display.delay(5000); // wait 5 seconds display.clearDisplay(); // clear the screen buffer display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 0); display.println("Hello, world!"); display.setTextColor(BLACK, WHITE); display.println(3.141592); display.setTextSize(2); display.setTextColor(WHITE); display.print("0x"); display.println(0xDEADBEEF, HEX); display.setCursor(0, 40); display.setTextSize(1); display.print("Arduino VGA Example"); } void loop() { ; } // end of code. |
The image below shows my hardware circuit result:
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.
leonardo????? help
The library works but the text vibrates.
I’m facing an error:
class “VGA” had no member “setTextSize”
class “VGA” had no member “setTextColor”
C:\Program Files (x86)\Arduino\libraries\Adafruit-GFX-Library-master\Adafruit_GrayOLED.cpp:250:10: error: ‘spi_dev’ was not declared in this scope
if (!spi_dev || !spi_dev->begin()) {
^~~~~~~
can someone help me
I get the same error as Mike & Jacob. I don’t see an answer to their question. Also, why does it call in OLED & I2C routines?
Great! It works smoothly!
Arduino: 1.8.18 (Windows 8.1), Board: “Arduino/Genuino Uno”
In file included from C:\Program Files (x86)\Arduino\libraries\Adafruit-GFX-Library-master\Adafruit_GrayOLED.cpp:20:0:
C:\Program Files (x86)\Arduino\libraries\Adafruit-GFX-Library-master\Adafruit_GrayOLED.h:30:10: fatal error: Adafruit_I2CDevice.h: No such file or directory
#include
^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
I get the same Error – can anyone help?
My screen gets black, nothing appears.
My Arduino Uno give me error, when I upload it. Have you an tipp?
how can i change the background and the font colours ?
give me error when i upload it.. the libraries haven´t done for arduino mega..
download this library for include
https://github.com/adafruit/Adafruit_BusIO
how to use it ?
how can i do it with a mega ? is possible?
yes it is the same