Go Down

Topic: Arduino Pong (Read 46978 times) previous topic - next topic

grandtippler

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

grandtippler

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.

Alastair.Parker

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

tvdbon

Quote
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.

tvdbon

Quote
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 ?

binarymillenium

#20
Aug 27, 2007, 05:49 pm Last Edit: Aug 27, 2007, 05:49 pm by binarymillenium Reason: 1
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:
http://vimeo.com/288344

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


grandtippler

Hi  tvdbon,
I'm using the 168.

tvdbon

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 .

John_Ryan

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  :)

CrashingDutchman

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.

Oliver Keller

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?

Oliver Keller

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. :-)


Code: [Select]
/*
  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) :)

norbiv8

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

Pictures about problem:
http://forsalestuff.fw.hu/

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

quackmaster7000

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

shenakan

Very great work !!

May be it is a stupid question, but it is difficult to do the same thing in color or this is not possible with the artuino ? What is missing to do it ??

Go Up