VGA Pong With Arduino Uno

21,734

105

37

Published

Introduction: VGA Pong With Arduino Uno

I have repruduced a color version of the classic Pong running for a VGA monitor, using a bare Arduino Uno.

It is for two players and it has sound too. It has four colors and a resolution of 120 x 60 pixels.

My goal was to avoid any special shield or support IC!

I just used few resistors, a DSUB15 connector, a pair of potenziometers and buttons. The Arduino board and the others components are placed in two wood boxes. The second player paddle is connected to the main block by means of a recycled USB cable. Pictures of the whole "console" and a simple schematic are shown at the beginning of this video:

In the past I have reproduced the B&W version for TV, using the TVout libraries...

...but now, insted of the TVout library, the color Pong is done using the VGAx library recently written by Smaffer.

You can read further the details in this Arduino forum

Instructions to built your own Color Pong with Arduino

In brief, here you can download the latest code version, then you need the VGAx libraries from Smaffer on github published here.

NB it seems that the VGAx library is fully compatible only with Arduino IDE 1.6.4. Older or newer versions may not work properly or work at all.

Once you have the code uploaded an an Arduino Uno (I have Rev. 3) without errors, you can start to build your own console.

You need:

  1. an Arduino Uno Rev. 3
  2. DSUB15 Connector, i.e. a VGA female connector or a VGA cable to be cut.
  3. four resistors: 2 x 68 Ohm and 2 x 470 Ohm
  4. two 10 kOhm potentiometers
  5. two buttons
  6. other two resistors (from 1 to 2 kOhm are fine)
  7. some piece of cable
  8. facoltative: an USB female plug and an USB cable for the second player, or any other connector/cable with four wires

The schematic is reported at the beginning of this Instructable, together with an overview of the finished consolle and how the game looks on my TV.

I placed the Arduino board with the VGA connector in a wood box, which holds also the first player potentiometer and button. I used a second smaller wood box for the second player and I decided to connect it to the main one by means of an USB female plug and an USB cable. You can use any other connector/cable wich contains at least four separated wires.

Enjoy!

6 People Made This Project!

Recommendations

  • Clocks Contest

    Clocks Contest
  • Water Contest

    Water Contest
  • Oil Contest

    Oil Contest

37 Discussions

Hi. Nice Project :)

Can I use this game for my design project ? thanks.

Hello

We have uploaded the code to the Arduino board but the monitor is showing no signal

1 reply

Dear Pruthvi_96, which Arduino IDE do you have? it seems that the VGAx library is fully compatible with IDE 1.6.4

0
user
abomin

1 year ago

Hello!

Nice projects, thank you!

Is it possible to put 4 your games in one sketch? It would be great!!!

3 replies

Thank you for the compliment!
I think it is not possible, almost each game uses all the available memory for the variables and simply putting two or more games together would overtake the 100% of it.
But it would be possible to built a single "consolle" with four buttons and two wheels compatible with all the games, one has just to re-map buttons an potenziometers in the code. I plan to do that as soon as I have time, may be during the Christmas holidays. You just need then to upload the code in the same device.

It`s true, but if we choose ONE game in start menu (when it powered up or by pressing a reset) - we don`t need a room for variables of ANOTHER games.

About "consolle": I think, it needs one universal connector for 2 types of the manipulators - pot-s or buttons.

well, it is not so simple. If you join two games in the same sketch (each one with its own variables), the Arduino memory is occupied from the whole variables as soon as they are defined, even if you do not really use the ones for the first game when you play to game two.

The good news is that many variables can be used for one game or the other, you just need to assign theme one value or another, and this save space.

I have a working sketch now where one can choose between pong or breakout, and I plan to add more, but it will take time.

Hello!

I love Pong and decided to build this as my first Arduino project.

I want to make a table with a screen in so to players can sit on each side and play.

I have got it working but I want to changes, maby someone can help me?

1: I want the green bar to go the oposite way when i turn the knob/potentiometer. Where do I change the code?

2: I have a 4:3 LCD. Is there a way to change screen resolution? Or even better, expand the borders of this pong code?

2 replies

Dear Pladask, for question 1: the easiest way should be to change in

void processInputs() {
buttonOneStatus = digitalRead(BUTTON_ONE_PIN);
buttonTwoStatus = digitalRead(BUTTON_TWO_PIN);
wheelOnePosition = analogRead(WHEEL_ONE_PIN);
wheelTwoPosition = analogRead(WHEEL_TWO_PIN);
buttonStatus = buttonOneStatus || buttonTwoStatus;
}

to

void processInputs() {
buttonOneStatus = digitalRead(BUTTON_ONE_PIN);
buttonTwoStatus = digitalRead(BUTTON_TWO_PIN);
wheelOnePosition = 1023 - analogRead(WHEEL_ONE_PIN);
wheelTwoPosition = analogRead(WHEEL_TWO_PIN);
buttonStatus = buttonOneStatus || buttonTwoStatus;
}

I cannot test it at the moment, let me know if it works.

For question 2 I have no answer. One of the main issues with the VGAx libraries is to center the picture, the best way is to use the center feature of the monitor, when available. The resolution (120 x 60 pixels) is more or less the maximum for the Arduino Uno capabilities, and it is not possible to use all the monitor surface. The yellow borders are the maximum extension available.

When you finish your project I would really appreciate if you can publish here a picture!

Hello Rob Cai !

I have finally tested your code and it works perfect! Thank you!

I have so many projects (non-arduino related) going on at the moment and I'm not great with wood, but i hope I can start with the box to put it in soon. I will post a picture when it's ready ;-)

My code compiles and uploads, but my monitor still says no signal. What could be wrong?

1 reply

Nevermind, I made a simple wiring mistake. It works great! Thanks for this tutorial!

Worked perfectly! Thank you so much dude! Just one question: in order to increase the speed of the game, do I just need to edit this lane

#define MAX_Y_VELOCITY 0.1

right?

Thank you so much, tonight I and my friends felt like a 70's friends group *__*

2 replies

Hi NicolaC22

I am glad to know you have fun with it!

No, to increase the speed you have to modify the line

ballVx = random(50., 80.)/500. + (scoreL + scoreR)/35;

the first part is a random number between 0.1 and 0.16 and the second part is an increment related to the total score (left player + right player) i.e. when the score is 2 vs 5 the ballVx is a random number between 0.3 and 0.36...

...WRONG! I am realizing right now that this formula is wrong! scoreL and scoreR are integers (and < 7) then the second term is always zero!!!

It should be modified like (if I am right):

ballVx = random(50., 80. + 5.*((float) scoreL + (float) scoreR))/500.;

Now, ballVx should go from { 0.1 to 0.16 (score 0 vs 0) } to { 0.1 to 0.3 (score 7 vs 7) }

I cannot test it at the moment, I will come back to this soon...

nice, thank you!! will try it asap :) otherwise I'll have a "talk" with the formula xD

hi Samo 2121, honestly I think the description you gave of the problem is a bit insufficient...

oh yea well nvm now its fixed...

hello rob. i made all of it, codes compiled with no errors but my monitor says no signal?

1 reply

I think, like was my Problem - you looks on bad side of vga connector. In Scheme is it from rear side, not from front...try it ;)