Arduino Pong

DAMMNNNN I don t have any more 75() and 900() !!!!! :cry:

The 75ohm is required, but the 450 and 900 arent so critical, more common values like 430 and 1k could probably be used instead, just remember to check the volatges before you plug anthing into the tv !

have a read of http://www.rickard.gunee.com/projects/video/pic/howto.php, he explains the overall process quite well, including voltage info

Very nice! I tried it tonight but with not much luck. BUT I don't have a 75 Ohm resistor so I tried a 68 and 85 resistor. I can see that the program is running, but it's jumpy and not very much in sync. Is it possible that this happens because I don't have 75 ohm resistor ? Also, you mentioned something about disabling the timer interrupt? Is this only for the atmega168 ? I'm running it on an atmega8.

We have PAL tv's here in South Africa so thats not the problem. Any information would be greatly appreciated. Once I get your example going I would like to try and get something like tetris or even snake going :slight_smile:

Try putting cli(); in the setup routine. That should disable the interrupts.

disabling the timer is quite important, each scan line in the signal must take 63( +/- 0.5)us, if the interrupt fires during the line generation, it will blow out the timing significantly, I will try to take a picture of what I get when the timer is NOT disabled, then you can compare what you're getting.

I'm not too sure how to disable it on the amtega8, but try using agent_orange's solution of 'cli();' somewhere in the setup() routine.

with regards to the 75ohm resistor, I can't be sure how critical it is, the most important thing is that you can generate 4 distinct voltages wrt the tv signal pin.

the voltages that you are aiming for are close to:
sync = 0.0v
black = 0.33v
gray = 0.66
white 1v

I was able to generate approx:
sync = 0v
black= 0.30
gray = 0.64
white = 0.95

Check your results with a multimeter first, to see what you get.

Good luck!

Oh, on a side note, I can't verify how correct the PAL signal is, (I don't have an oscilloscope) so I only know that this works on the 2 tvs that I have (which are both pal, but quite new).
If anyone has actually got this working, maybe they could post back with their resistor values and geographical location.

Al

Heres what I get (on the 168) when I don't disable the interrupt

And this is what I get when i put 'cli();' as the first line in setup()

So it seems that cli(); works just as well as changing wiring.c, and it's easier!
Thanks agent_orange.

If your getting something similar to the first img, try the cli(); method.

Al

I'm getting the same blurred screen.
No change when I put the cli(); code in the first line of setup. Is there something else I need to do other then enter cli(); into the first line of set-up, recompile then upload to the micro?
If I comment out the interupt code in wired.c the title screen has no blurring but the screen goes blank and the micro locks up after that.

oh I've got a Pal tv(australia) and all resistor values are very close.

Is there something I'm missing?

Oh and fantastic project Alastair.

Cheers,
Brian

Ok ignore what I just said in the post above. cli(); in set-up works just fine.
I was running software version 0007, I just downloaded 0009 and it all works fine now.

I can play pong now, my life is complete!!!

Thanks for sharing a great project.

Thanks grandtippler, good to know someone else actually got it working, and that has been able to get some enjoyment out of it (hopefully some learning too!)

Al

Heres what I get (on the 168) when I don't disable the interrupt

...

If your getting something similar to the first img, try the cli(); method.

Al

Your photo pretty much shows the same problem that I'm having. I'll try it again tonight on the atmega8 with the cli() method.

Ok ignore what I just said in the post above. cli(); in set-up works just fine.
I was running software version 0007, I just downloaded 0009 and it all works fine now.

I can play pong now, my life is complete!!!

Thanks for sharing a great project.

Are you using arduino with an atmega168 or atmega8 ?

I haven't implemented pong, but I've got video output working for NTSC. What I've done so far is easier than pong because there are none of the branches in code that have to all meet timing, but I'll play with that later.

Code:
http://binarymillenium.googlecode.com/svn/trunk/arduino/videontsc/video5from3.pde

Video, with incorrect timing demonstrated:

Writeup:
http://code.google.com/p/binarymillenium/wiki/ArduinoVideo

Hi tvdbon,
I'm using the 168.

has anybody got this to work on the atmega8 ? I tried the cli method and the pong intro screen shows fine now, but when the game starts it gets out of sync again .

Question

Can video output from Arduino, be mixed with a web cam or other live video camera source?

I know there's video mixers that can do it, but they cost lots.

If anyone's experimenting in this field, please let me know :slight_smile:

Have a look at the lm1881 (National semiconductor if I am correct).

I think I have seen it mentioned a couple of times here too. It can be mixed with a normal video source, not sure about webcam.

I tried it with an atmega8 and atmega168 (arduinoBT) on my trusty self made beamer (slide-projector with pocket TV screen). While arduino pong seems to be just the perfect new companion for this beamer (which is not really usable for anything fine grained like a movie...) I see a second ghost picture. Also none picture has the right height. Is it maybe the cable lenght? I have roughly 1,5 meter.
I see many settings in the header, but when I change e.g. WIDTH, HEIGHT or DISPLAY_LINES it only gets worse, showing out-of sync artefacts...
Any hints?
I haven't looked to close at the code, but I assume that touching e.g. DISPLAY_LINES must mess up the timing, right?

regarding the resistors: I simply use three 1K potentiometers for all values and I see most changes when truning the 75 ohm one. But it looks not that picky... 100 ohm could also work I guess.
Hmmm, maybe I have some naughty analog filter effect due to the pots (acting as inductors) which causes ghost images?

I looked around for a TV test-pattern an found this very simple and clean one:
http://hklab.net/wiki/TV_Video_Signal_Generator_with_Arduino

Its done on an ardunio board, but supprisingly not compiled within the IDE, so I changed the code
to run in Arduino 0009. I also changed it to support the same circuit and pins that Al uses in arduino pong.
So video out is still generated on digital pin 8+9.

Now, I can see 3 nice vertical bars, which tells me that the ghost pictures I get from the arduino
pong code is probably not a hardware issue of my circuit or beamer...
Although the ghost pictures I see in pong are all exactly vertically shifted... maybe I just don't see them in
the 3 vertical bars pattern?

Anyways, I think this code is a good test! And maybe an even better starting point for proper
video generation. It also looks like the _delay_us() function is more accurate than delayMicroseconds...
When I've time and muse to pull that clunky scope from my shelf, I'll compare the signal patterns of this 3 bar test and arduino pong. :slight_smile:

/* 
   Vertical Bars Pattern PAL TV Signal Generator with Arduino 
   Use this code as you want
   2007 Javier Valcarce Garcia, <javier.valcarce@gmail.com>
   
   
   ---
   
   copied from http://hklab.net/wiki/TV_Video_Signal_Generator_with_Arduino
   This pattern should work on PAL and NTSC TV sets, as mentioned on the webpage.
   
   It's slightly changed to compile inside the standard Arduino IDE (Version 0009)
   Note that the left and right bar are usually not exact the same size, as 
   there are slight offsets in most TVs. 
   See reference: http://www.retroleum.co.uk/PALTVtimingandvoltages.html
   
     2007.09.11 Oliver Keller <oli.keller@gmail.com>
   
*/
 
// yes, ther is an avrlibc inside arduino...
#include <util/delay.h>
 
/////////////////////////////////////////////////////////////////////////////////////////////////
// Pins where the 2-bit DAC is connected, this is the composite video-out ;)
// PINB0 is DigitalPin 8, PINB1 is DigitalPin 9 
#define PINB0 0 // LSB, 1 kOhm resistor 
#define PINB1 1 // MSB, 330 Ohm resistor
 
// PINB1 PINB0 OUTPUT 
// 0     0     0.0V   - Sync level
// 0     1     0.3V   - Black level
// 1     0     0.6V   - Gray level
// 1     1     1.0V   - White level
 
#define LEVEL_SYNC   PORTB &= ~(1 << PINB1); PORTB &= ~(1 << PINB0);
#define LEVEL_BLACK  PORTB &= ~(1 << PINB1); PORTB |=   1 << PINB0; 
#define LEVEL_GRAY   PORTB |=   1 << PINB1;  PORTB &= ~(1 << PINB0);
#define LEVEL_WHITE  PORTB |=   1 << PINB1;  PORTB |=   1 << PINB0;
/////////////////////////////////////////////////////////////////////////////////////////////////
 
 
/////////////////////////////////////////////////////////////////////////////////////////////////
inline void vsync_pulse()
{
      LEVEL_SYNC; 
      _delay_us(30); 
      LEVEL_BLACK; 
      _delay_us(2); 
}
 
/////////////////////////////////////////////////////////////////////////////////////////////////
inline void equal_pulse()
{
      LEVEL_SYNC; 
      _delay_us(2); 
      LEVEL_BLACK; 
      _delay_us(30);
}
/////////////////////////////////////////////////////////////////////////////////////////////////
inline void hsync_pulse()
{
      LEVEL_SYNC; 
      _delay_us(5); //4.7us
      LEVEL_BLACK; 
      _delay_us(7); //7.3us
}
 
       unsigned int line = 0;
 
/////////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{

 
      /* NOTE THAT THE SIGNAL GENERATED BY THIS PROGRAM HAS A NOT VERY ACCURATE TIMING SO 
       IT IS POSSIBLE THAT THE IMAGE BLINKS ON YOUR TV SCREEN OR DOESN'T SHOW AT ALL, 
       THIS PROGRAM WRITTEN IN C (INSTEAD OF ASSEMBLER) IS ONLY A PROOF OF CONCEPT */
 

      DDRB = 0xFF; // PORTB, all pins are outputs
      cli();
}

void loop()
{
          if (line == 626) 
          {
              line = 1;
          }
          else
          {
              line++;
          }
 
 
          switch(line)
          {
          case 1:
          case 2:
          case 314:
          case 315:
              vsync_pulse();
              vsync_pulse();
              break;
 
          case 3:
              vsync_pulse();
              equal_pulse();
              break;
 
          case 4:
          case 5:
          case 311:
          case 312:
          case 316:
          case 317:
          case 623:
          case 624:
          case 625:  
              equal_pulse();
              equal_pulse();
              break;
 
          case 313:
              equal_pulse();
              vsync_pulse();
              break;
          default:
              // Image scanline (not a sync line)
 
              hsync_pulse(); // Horizontal Sync, lenght = 12us                 
 
              LEVEL_GRAY;   
              _delay_us(8);
              LEVEL_BLACK;
              _delay_us(14);
              LEVEL_WHITE;
              _delay_us(8);
              LEVEL_BLACK;
              _delay_us(14);
              LEVEL_GRAY;
              _delay_us(8);
              //52us in total
          }
}

Note the code works on ATmega168 as well as on ATmega8 arduino boards. Its even smaller than the arduino bootloader (1k) :slight_smile:

I have problem with arduino pong :frowning:
I use atmega8 and arduino009.

Pictures about problem:

Please help me some idea what is the problem with my arduino pong.

Wow. That's extremely impressive!!! :o
GREAT Work!