Você está na página 1de 13

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

tronixstuff
fun and learning with electronics

Tutorial: Video output from your Arduino


This is chapter thirty-five of a series originally titled Getting Started/Moving Forward with Arduino! (http://tronixstuff.wordpress.com/tutorials/) by John Boxall (http://tronixstuff.wordpress.com/about-2/) A seemingly endless series of tutorials about the Arduino (http://arduino.cc/) universe. The first chapter is here (http://tronixstuff.wordpress.com/2010/04/04/getting-started-with-arduino-chapterzero/), the complete series is detailed here (http://tronixstuff.wordpress.com/tutorials). Please note that the tutorials are not currently compatible with Arduino IDE v1.0. Please continue to use v22 or v23 (http://arduino.cc/en/Main/Software) until further notice. Welcome back fellow arduidans! 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 minumum hardware required and demonstrate basic functions to get started. To whet your appetite, here is a quick video demonstration of what is possible:

1 of 13

05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

. You cant 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 (or you could buy a kit (http://littlebirdelectronics.com/collections/nootropic-design) instead). 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 Arduno Uno/Duemilanove/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 D29. 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:

2 of 13

05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

(http://tronixstuff.files.wordpress.com/2011/05/basicschem.jpg) (tronixCAD v1.0) If youre not up for soldering into an RCA plug, a simple way is to chop up a standard video lead as such:

(http://tronixstuff.files.wordpress.com/2011/05/cablestripss.jpg) 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 (http://littlebirdelectronics.com/products/thumb-joystick) (as reviewed here (http://tronixstuff.wordpress.com/2010/05/21/part-review-sparkfunlbe-thumbjoystick/)).

3 of 13

05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

(http://tronixstuff.files.wordpress.com/2011/05/mshieldss.jpg) 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 (http://code.google.com/p/arduino-tvout/downloads/list). We will use the TVoutBeta1.zip version. Copy the downloaded folder into the ../arduino-002x/libraries folder and restart the Arduino IDE. Those of you who may have a nootropic design Hackvision (http://tronixstuff.wordpress.com/2011/05/14/kit-review-%E2%80%93-nootropic-designhackvision/) 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 lets go! For every project, place these two lines at the top of your sketch: #include <TVout.h> TVout TV; 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 (http://en.wikipedia.org/wiki/PAL) or NTSC (http://en.wikipedia.org /wiki/NTSC)). In void setup() use either TV.start_render(_NTSC) // for NTSC (or) TV.start_render(_PAL); // for PAL system Now for the main functions. The first one of interest will be:
4 of 13 05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

TV.clear_screen(); which clears the screen. Or if you would like to fill the screen with white, use TV.fill_screen(1); 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 wouldnt display for me. Working on it! To choose a font use: TV.select_font(font4x6); // using font4x6 Then to write the text, choose the screen location with: TV.set_cursor(x,y); then display the text with: TV.print("Hello, world..."); // etc You can also use TV.println(); to add a carriage return as expected. Display single characters with a position in the one function using: TV.print_char(x,y,c); // c is the character to display So lets have a look at the various fonts in action with the following sketch (download (https://sites.google.com/site/tronixstuff/home/arduino-tutorial-seriesfiles/example35p1.pde)): Example 35.1 /* Example 35.1 - arduino-tvout text demonstration http://tronixstuff.wordpress.com/tutorials > chapter 35 | CC by-sa-nc */ #include #include TVout TV; int d=10; // for delay purposes

5 of 13

05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

char c='X'; void setup() { TV.begin(_PAL); // for PAL system TV.clear_screen(); } void loop() { TV.select_font(font4x6); for (int a=0; a<6; a++) { for (int b=0; b<128; b++) { TV.print_char(b,a*6,c); delay(d); TV.clear_screen(); } } delay(1000); TV.clear_screen(); TV.select_font(font6x8); for (int a=0; a<6; a++) { for (int b=0; b<128; b++) { TV.print_char(b,a*8,c); delay(d); TV.clear_screen(); } } delay(1000); TV.clear_screen(); TV.select_font(font8x8); for (int a=0; a<6; a++) { for (int b=0; b<128; b++) { TV.print_char(b,a*8,c); delay(d); TV.clear_screen();
6 of 13 05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

} } delay(1000); TV.clear_screen(); }

. 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 lets start with basic pixels. To draw a pixel, use: TV.set_pixel(x,y,z); where x and y are the coordinates of the pixel, and z is the colour (1 = white, 0 = black, 2 = inverse of current pixels colour). You want more than a pixel? How about a line: TV.draw_line(x1,y1,x2,y2,colour); Draws a line from x1, y1 to x2, y2 of colour colour. (1 = white, 0 = black, 2 = inverse of current pixels colour). Rectangles? Easy:

7 of 13

05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

TV.draw_rectangle(x,y,w,h,colour,fill); 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: TV.draw_circle(x,y,r,colour,fill); 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 (download (https://sites.google.com/site/tronixstuff/home/arduino-tutorial-seriesfiles/example35p2.pde)): Example 35.2 /* Example 35.2 - arduino-tvout font demonstration II http://tronixstuff.wordpress.com/tutorials > chapter 35 | CC by-sa-nc */ #include TVout TV; int d=100; // for delay purposes int x1,x2,y1,y2,r=0; void setup() { TV.begin(_PAL); // for PAL system TV.clear_screen(); randomSeed(analogRead(0)); // seed the random number generator } void pixels() { TV.clear_screen(); for (int a=0; a<200; a++) { x1=random(128); y1=random(96); TV.set_pixel(x1,y1,2); delay(d); }
8 of 13 05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

delay(1000); TV.clear_screen(); } void lines() { TV.clear_screen(); for (int a=0; a<96; a++) { TV.draw_line(0,a,127,a,1); delay(d); } delay(500); for (int a=0; a<96; a++) { TV.draw_line(0,a,127,a,0); delay(d); } TV.clear_screen(); delay(500); } void circles() { TV.clear_screen(); for (int i=0; i<30; i++) { TV.draw_circle(64,48,i,1,0); delay(200); TV.draw_circle(64,48,i,1,1); delay(200); TV.draw_circle(64,48,i,0,0); delay(200); } delay(1000); TV.clear_screen(); } void loop() { pixels(); lines(); circles(); }
9 of 13 05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

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/ (http://code.google.com/u/mdmetzle/) for the arduino-tvout library.

(http://tronixstuff.files.wordpress.com/2010/10/ledborder.jpg) Have fun and keep checking into tronixstuff.com (http://tronixstuff.com/). Why not follow things on twitter (http://twitter.com/tronixstuff), Google+ (https://plus.google.com /114792914994310886893/posts), subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group (http://groups.google.com/group /tronixstuff) dedicated to the projects and related items on this website. Sign up (http://groups.google.com/group/tronixstuff) its free, helpful to each other and we can all learn something. May 30, 2011 - Posted by John Boxall | arduino, education, video | 128, 96, arduino, circle, composite, data, DIY, duemilanove, game, how, jack, learn, lesson, lessons, library, line, output, pinout, pixel, RCA, socket, to, tronixstuff, tutorial, tutorials, tv, TV-out, understand,

10 of 13

05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

uno, video

17 Comments
1. Hi John, Another great tutorial. I am just constantly amazed at what can be done with an arduino board. norman Comment by Norman Elliott | May 30, 2011 | Reply It never ends! Sorry it was a bit short, I ran out of time and wanted to get that article out before the end of the month. In a few weeks I will continue with another TV out article. cheers john Comment by John Boxall | May 31, 2011 | Reply 2. Hello John, and again thank you for an inspiring series! On a very non-Arduino-related question, what is the music in the top and bottom clips. Shazam cant match it, and I feel the urge to make an iTunes purchase! Comment by hlantz | May 31, 2011 | Reply Visit these links: http://www.youtube.com/watch?v=oJi5sfz0q0Q and http://www.youtube.com /watch?v=Tr1hTJxY5b4. Under the number of views counter there should be artist details and links to iTunes. have fun john Comment by John Boxall | May 31, 2011 | Reply 3. Very cool! I hadnt seen this library, and assumed that Id need the Nootropic board to play with this type of thing. Thanks for the info! Comment by Tim | June 1, 2011 | Reply No worries. That was my thought at first then after realising anyone could do it,

11 of 13

05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

here we are. Have fun john Comment by John Boxall | June 1, 2011 | Reply 4. Great tutorial as usual, John! Any ideas on the feasibility of color video with the Arduino? What would be the limiting factors? Its just amazing what you can do with an Arduino and some programming. Comment by Jeff Gilmour | June 1, 2011 | Reply Colour video? No, that requires too much hardware, memory space and CPU power. However I did find someone who has grey levels going, have a look at http://www.javiervalcarce.eu/wiki/TV_Video_Signal_Generator_with_Arduino. Comment by John Boxall | June 1, 2011 | Reply 5. very cool project using TV-out library..can u update this article with full schematic from the joystick? Comment by stpdxpdc | July 16, 2011 | Reply The joystick is very simple, it is just two resistors that you read with two analogue inputs and they are separate from the TV out circuitry. More on the joystick here: http://tronixstuff.wordpress.com/2010/05/21/part-review-sparkfunlbe-thumbjoystick/ cheers john Comment by John Boxall | July 16, 2011 | Reply 6. hi, is it possible to run this in parallel with a compiste video feed to create a Onboard Screen Display where in the black areas would display live video feed and displaying changing information add by the arduino? Comment by NateC | September 12, 2011 | Reply You would need to have a composite video mixer of some sort. Comment by John Boxall | September 12, 2011 | Reply 7. Hi John, excellent article! I was just wondering if it would be possible to isolate the arduino from the TV, maybe through an opto-isolator? Thanks. Comment by Mark | October 30, 2011 | Reply

12 of 13

05/23/2012 02:52 PM

Tutorial: Video output from your Arduino t r o n i ...

http://tronixstu.wordpress.com/2011/05/30/tutorial...

You would need to use an analogue isolation amplifier. This is outside the scope of my articles, however this may be a good start: http://www.analog.com/static /imported-files/tutorials/MT-071.pdf Comment by John Boxall | October 30, 2011 | Reply Hi John, thanks for your reply. It looks like those cost more than an arduino board, so maybe Ill just risk it. Thanks again really great set of articles here. Comment by Mark | October 30, 2011 8. Can I just say what a relief to discover someone that truly knows what theyre talking about over the internet. You certainly understand how to bring an issue to light and make it important. More and more people must read this and understand this side of your story. Its surprising you arent more popular because you certainly have the gift. Comment by Spammer | March 10, 2012 | Reply Thank you for your kind comments Mr Spammer. Comment by John Boxall | March 10, 2012 | Reply

Site info
tr o nixstuff Theme: Andreas04 by Andreas Viklund. Blog at WordPress.com.

Follow t r o n i x s t u f f
Powered by WordPress.com

13 of 13

05/23/2012 02:52 PM

Você também pode gostar