Arduino Pong

Thanks for the comments, especially Benoit, as I based this on your code!

For a bit of a write up on the process, have a look at

Enjoy playing pong!

Alastair

WOAh !!! Awsome job !! I ve built it too based on your source, and will post some pics later today possibly, but I m having some sync issues, how should I edit it in order to make it work on NTSC ?

Thanks for sharing and good job ! ;D

Heres some info that I forgot about, which is important if you guys are actually going to run pong!

In order to get the timings exact, you will need to disable the timer interrupt on the atmega168

Edit the file lib/targets/arduino/wiring.c
and block comment out the following

// enable timer 0 overflow interrupt
#if defined(AVR_ATmega168)
sbi(TIMSK0, TOIE0);
#else
sbi(TIMSK, TOIE0);
#endif

ie:

make it look like this

/*
// enable timer 0 overflow interrupt
#if defined(AVR_ATmega168)
sbi(TIMSK0, TOIE0);
#else
sbi(TIMSK, TOIE0);
#endif
*/

Getting nstc to work.

According to www.amazon.com/Black-Video-Game-Console-Design/dp/0672328208
pal has 625 total lines (about 575 visible) and ntsc has 525(about 480 visible), because arduino pong ignores interlacing, the effective number of lines is cut in half.
If someone were to try to get it to work on ntsc, I would start by decreasing the number of displayed lines, which will probably mess up the timing, so some experimentation would be needed with the remainder of the delays after vsync.

Perhaps someone with an ntsc tv can have a go at hacking the code and then sharing the results so other ntsc hackers can enjoy pong aswell.

Sorry I can't be more help right now, I will try to look into it, but without an ntsc tv, testing is hard :slight_smile:

Alastair

thanks alistair. I m gonna dedicate tonight 's .. night. at it. Will try to post my results !

::slight_smile:

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.