Tutorial: Video output from your Arduino

Create video output from your Arduino in chapter 35 of tutorials about the Arduino universe. The first chapter is here, the complete series is detailed here.

[Updated 10/01/2013]

In this chapter we will examine something different – the ability of our Arduino and compatible boards to create composite video output. In other words, displaying stuff from the Arduino on a TV. A lot of people were unaware of the ability to do this, however the process is very simple and not difficult to implement from a hardware perspective. Within this chapter we will learn to construct the minimum hardware required and demonstrate basic functions to get started.

To whet your appetite, here is a quick video demonstration of what is possible:

You can’t expect too much from a 16 MHz microcontroller without a video card… but the price is right, and with some imagination and the right functions you can do quite well. To make this happen we need to knock out some hardware of our own. Connection is very easy. First we need to locate three pins on our Arduino board. They will be used to output Sync, Video and also GND. For those with Arduino Uno/Freetronics Eleven etc Sync is digital 9, video is digital 7 and GND is … GND. If you have a Mega/Mega2560 Sync is digital 11 and video is A7. There is also the ability to generate audio with the methods in this article, and if you want to do this the Uno (etc.) pin is digital 11 or 10 on the Mega.

The monitor or television used needs to have a composite video-in socket (jack). For those with older televisions that have a VCR connected, you could use the video-in socket on the VCR. The schematic for video out is very simple, you only need two normal 0.25W resistors and a video lead:

If you’re not up for soldering into an RCA plug, a simple way is to chop up a standard video lead as such:

Then just wire the termination of the two resistors to the centre core (“pin”) and GND to the shield. For the purpose of this article I have made a quick TV-out shield that also includes a thumb joystick (as reviewed here).

A real triumph of engineering… however it solves the problem. The vertical trimmer is connected to A0;  the horizontal to A1; the button to digital 8 via a 10k0 pull-up resistor. Next, you will need to download and install the arduino-tvout library. It can be found here. We will use the TVoutBeta1.zip version.  Those of you who may have a nootropic design Hackvision – please note your library is different.

Now to see how to integrate TV-out into our sketch. We will run through the basic functions which integrated with your imagination should see some interesting results…  So let’s go!

For every project, place these two lines at the top of your sketch:

The first brings in the library, and the second line creates an instance of TV to use with the library functions. Next, we need to activate TVout and select the appropriate broadcast standard (PAL or NTSC). In void setup() use either

Now for the main functions. The first one of interest will be:

which … clears the screen. Or if you would like to fill the screen with white, use

Moving on – to write some text. First we need to select a font. There are three basic fonts to choose from:

  • font4x6 (each character being 4 pixels by 6 pixels, etc.)
  • font6x8
  • font8x8

Well there is four, but it wouldn’t display for me. Working on it! To choose a font use:

Then to write the text, choose the screen location with:

then display the text with:

You can also use TV.println(); to add a carriage return as expected. Display single characters with a position in the one function using:

So let’s have a look at the various fonts in action with the following sketch:

 

Now to move into the 1970s with some basic graphical functions. We have a screen resolution of 128 by 96 pixels to work with. When planning your display, you need to ensure that the sketch never attempts to display a pixel outside of the 128 x 96 screen area. Doing so generally causes the Arduino to reboot.

First let’s start with basic pixels. To draw a pixel, use:

where x and y are the coordinates of the pixel, and z is the colour (1 = white, 0 = black, 2 = inverse of current pixel’s colour). You want more than a pixel? How about a line:

Draws a line from x1, y1 to x2, y2 of colour colour. (1 = white, 0 = black, 2 = inverse of current pixel’s colour).

Rectangles? Easy:

Draws a rectangle with the top-left corner at x,y; width w, height h, colour and optional fill colour. Circles are just as simple:

Draws a circle with centre at x,y; radius r pixels, edge colour, optional fill colour.

Now to see these functions in action with the following sketch:

And for the video demonstration:

So there you have it, a start with Arduino and TV-out. Furthermore, a big thanks to http://code.google.com/u/mdmetzle/ for the arduino-tvout library.

LEDborder

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

The following two tabs change content below.

John Boxall

Founder, owner and managing editor of tronixstuff.com.

42 Responses to “Tutorial: Video output from your Arduino”

  1. Norman Elliott says:

    H John,

    Another great tutoral. I am just constantly amazed at what can be done wth an arduno board.

    norman

    • John Boxall says:

      It never ends! Sorry t was a bt short, I ran out of tme and wanted to get that artcle out before the end of the month. In a few weeks I wll contnue wth another TV out artcle.
      cheers
      john

  2. hlantz says:

    Hello John, and agan thank you for an nsprng seres! On a very non-Arduno-related queston, what s the musc n the top and bottom clps. Shazam can’t match t, and I feel the urge to make an Tunes purchase!

  3. Tim says:

    Very cool! I hadn’t seen ths lbrary, and assumed that I’d need the Nootropc board to play wth ths type of thng. Thanks for the nfo!

  4. Jeff Gilmour says:

    Great tutoral as usual, John! Any deas on the feasblty of color vdeo wth the Arduno? What would be the lmtng factors? It’s just amazng what you can do wth an Arduno and some programmng.

  5. stpdxpdc says:

    very cool project usng TV-out lbrary..can u update ths artcle wth full schematc from the joystck?

  6. NateC says:

    h, s t possble to run ths n parallel wth a compste vdeo feed to create a Onboard Screen Dsplay where n the black areas would dsplay lve vdeo feed and dsplayng changng nformaton add by the arduno?

  7. Mark says:

    H John, excellent artcle! I was just wonderng f t would be possble to solate the arduno from the TV, maybe through an opto-solator? Thanks.

  8. Spammer says:

    Can I just say what a relef to dscover someone that truly knows what they’re talkng about over the nternet. You certanly understand how to brng an ssue to lght and make t mportant. More and more people must read ths and understand ths sde of your story. It’s surprsng you aren’t more popular because you certanly have the gft.

  9. SHOBHA says:

    h just wanted to know whether tv out supports any tmer ? when use my arduno wth vdeo expermenter sheld for dsplay text on tv , the text wll be dsplayed all the tme… want to dsplay the text for certan tme t self , lke around 10mnutes….does tv out lbrary supports ths knd of applcaton?

  10. Jason Adams says:

    H John. cool artcle. do you know f tv lbrary s compatble wth 1.0 IDE?

    Regards
    Jason

  11. Kana says:

    Hello,
    I was wonderng about the cable you are usng, RCA Composte Vdeo. I have a cord smlar to t but when I cut open the nsde, the core/pn s not sold but nstead made up of many tny copper wres. I tred usng ths anyway but my mages dsplay very shaky and not completely clear. Do you thnk t has to do wth my cable or s t more lkely to be an error wth my crcutry? I have also seen that my Sync pn doesn’t affect the mage whatsoever. Perhaps t s shaky because of ths?
    Thank you.

    • John Boxall says:

      Yes, t does sound flaky. Double-check your crcut and wrng, and f possble try a dfferent coax lead. Sometmes you can get a lead from a cheap $2 store – then cut the plug from one end and use that.
      cheers

      • kanaabe says:

        Thank you very much. I thnk the cable I have s not COAX. It s the yellow component of the Audo/Vdeo cable. I wll try to get a COAX cable and an RCA converter. Does that sound rght? Also my TV s very old from the 90’s. Sorry I am new to ths, ths s my frst Arduno project wth Vdeo! I found your tutoral very helpful though and t s my prmary resource at ths pont!

      • John Boxall says:

        No, the yellow one s fne.

  12. Tim C says:

    Great Job John. Queston – Is t possble to use the cable/antenna coax nput nstead of Vdeo n (whch I don’t have). Thanks

  13. Steve Black says:

    H, ths s not “TV.draw_rectangle” s “TV.draw_rect” :)

  14. Steve Black says:

    Good tutoral ! Dd you do a tutoral on the TV audo output? because I’ve created a lttle game and I would lke to have sound !

  15. Heldur says:

    H!

    Nce gong :)
    Ths soluton s exactly what I need to smulate black-screen :) Thank you for that!
    One queston:
    s t ok to “multply” output for let’s say for 12 nputs wth just usng hex-buffers behnd ouputs 7 and 9. Buffer nputs group together and connected to pn 7, another group to pn 9, and all “new” outputs n seres wth resstors lke pns were at frst? Or wll there be some problems wth ths plan?
    Thank you!

    Heldur

  16. Steve Black says:

    Hello ! I found a lbrary for dsplayng color on a screen wth VGA output (https://code.google.com/p/arduno-vgaout/) but I can not fnd tutorals and that s why I ask you f you could make one? Thank you n advance! :)

  17. Jonius says:

    hello Jhon

    do you have a tutoral about accelerometer mma7361+arduno?

  18. Rodrigo says:

    Hello John!

    I wonder f t would be possble to supermpose characters n a vdeo sgnal captured by a camera? Hug.

Trackbacks/Pingbacks


Leave a Reply

Subscribe via email

Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: