loading

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!

<p>Hello </p><p>We have uploaded the code to the Arduino board but the monitor is showing no signal</p>
<p>Dear Pruthvi_96, which Arduino IDE do you have? it seems that the VGAx library is fully compatible with IDE 1.6.4</p>
<p>Hello!</p><p>Nice projects, thank you!</p><p>Is it possible to put 4 your games in one sketch? It would be great!!!</p>
<p>Thank you for the compliment! <br>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. <br>But it would be possible to built a single &quot;consolle&quot; 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. </p>
<p>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.</p><p>About &quot;consolle&quot;: I think, it needs one universal connector for 2 types of the manipulators - pot-s or buttons.</p>
<p>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. </p><p>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. </p><p>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. </p>
<p>I tryed to upload the same code on an Arduino NANO ATmega328 and it works as well! </p>
<p>So, are the resistors required or not? or, would it work without resistors?</p>
<p>yes, the resistors are required as well. </p>
<p>Ok thanks</p>
<p>Hello!</p><p>I love Pong and decided to build this as my first Arduino project.</p><p>I want to make a table with a screen in so to players can sit on each side and play.</p><p>I have got it working but I want to changes, maby someone can help me?</p><p>1: I want the green bar to go the oposite way when i turn the knob/potentiometer. Where do I change the code?</p><p>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?</p>
<p>Dear Pladask, for question 1: the easiest way should be to change in </p><p><em>void processInputs() {<br> buttonOneStatus = digitalRead(BUTTON_ONE_PIN); <br> buttonTwoStatus = digitalRead(BUTTON_TWO_PIN);<br> wheelOnePosition = analogRead(WHEEL_ONE_PIN);<br> wheelTwoPosition = analogRead(WHEEL_TWO_PIN);<br> buttonStatus = buttonOneStatus || buttonTwoStatus; <br>}</em></p><p>to </p><p><em>void processInputs() {<br> buttonOneStatus = digitalRead(BUTTON_ONE_PIN); <br> buttonTwoStatus = digitalRead(BUTTON_TWO_PIN);<br></em> <em><strong>wheelOnePosition = 1023 - analogRead(WHEEL_ONE_PIN);</strong><br> wheelTwoPosition = analogRead(WHEEL_TWO_PIN);<br> buttonStatus = buttonOneStatus || buttonTwoStatus; <br>}</em></p><p>I cannot test it at the moment, let me know if it works. </p><p>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. </p><p>When you finish your project I would really appreciate if you can publish here a picture! </p>
<p>Hello Rob Cai !</p><p>I have finally tested your code and it works perfect! Thank you!</p><p>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 ;-)</p>
<p>hello i'm from india and in my country the supply voltage is 230v,50Hz so is there any effect due to this?because right now i got output on Monitor but the word and image display in screen is not proper , the output is like we stretch the all screen. and if this problem is due to supply voltage than please help me where i have to make the change. </p><p>Thank You. </p>
<p>Dear tejanihiren1991, I am from Italy and we have the same supply voltage, thus I do not think the problem you have is due to that. </p><p>I had a similar behaviour while using the VGAX libraries, and at the end it was related to the Arduino software version (IDE), as shown in this video:</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/1gNkWwYC3mY" width="500"></iframe></p><p>I am using now IDE 1.6.4 and I had glitches with IDE 1.0.5 (I haven't tried the latest one). </p><p>You should also take care of the groundings, if one is missing you may have unpredictable behaviours. And finally, try with a different monitor. I hope one of these suggestions work for you!</p>
<p>i want to display small size font on screen, so is there any tool or method that help me.Thank you</p>
<p>Well, in principle you can create your own fonts, but on the other hand the actual font resolution is already quite low (vertical x horizontal = 5 x 4 pixels), thus if you shrink it even more I doubt you can obtain something that can be read. </p><p>By the way, to create your fonts you have to modify the &quot;glyph&quot; part, such as the lines: </p><p>{ 5, 128, 64, 32, 16, 8, 0, }, //glyph '\' code=59</p><p>In this example, &quot;5&quot; means that you have a font done by 5 columns (most are only 4), thus here it is 5 raw x 5 columns. </p><p>Now every number (from 128 to 8) generate a row (from top to bottom)</p><p>128 = <strong>1 0 0 0 0</strong></p><p>64 = <strong>0 1 0 0 0</strong></p><p>32 = <strong>0 0 1 0 0</strong></p><p>16 = <strong>0 0 0 1 0</strong></p><p>8 = <strong>0 0 0 0 1</strong></p><p>Can you see the glyph &quot;\&quot;? another example</p><p>{ 5, 136, 168, 168, 168, 80, 0, }, //glyph 'W' code=54</p><p>136 = <strong>1 0 0 0 1</strong> = 128 + 8</p><p>168 = <strong>1 0 1 0 1</strong> = 128 + 32 + 8</p><p>168 = <strong>1 0 1 0 1</strong></p><p>168 = <strong>1 0 1 0 1</strong></p><p>80 = <strong>0 1 0 1 0</strong> = 64 + 16</p><p>Can you see the glyph &quot;W&quot;? </p><p>I hope with these examples you can see the principle. </p>
<p>Again Thank you so much, i follow your steps and work good,and now i try to make font more bigger than your font, and than i realize that it print only 8 Dot of Horizontal line, Why that happen? If i want to print all word than what i have to do? And is ant Method to decrease pixel size, like normal small font display in Monitor.Sorry for my poor English.</p>
<p>Dear tejanihiren1991, I believe there is no simple way to reduce the pixel size! In my understanding the actual resolution (120 x 60 pixels) is already obtained pushing the limit of the Arduino performance. An higher definition means more instructions per unit time! I am not expert since I have not written these libraries, I am just an user. If you read some of the description provided by <strong>Smaffer</strong> on <strong>github</strong> (the link is above in the instructables) you may get more information about the working principle and its limits. <strong><br></strong></p>
<p>Thank you so much Rob Cai, i update Arduino IDE and now it work Fine.Again Thanks For Help.<a href="https://www.instructables.com/member/Rob%20Cai" rel="nofollow"><br></a></p>
<p>My code compiles and uploads, but my monitor still says no signal. What could be wrong?</p>
<p>Nevermind, I made a simple wiring mistake. It works great! Thanks for this tutorial!</p>
<p>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<br><br>#define MAX_Y_VELOCITY 0.1<br><br>right?</p><p>Thank you so much, tonight I and my friends felt like a 70's friends group *__*</p>
<p>Hi NicolaC22</p><p>I am glad to know you have fun with it!</p><p>No, to increase the speed you have to modify the line</p><p>ballVx = random(50., 80.)/500. + (scoreL + scoreR)/35; </p><p>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...</p><p><strong>...WRONG! I am realizing right now that this formula is wrong! scoreL and scoreR are integers (and &lt; 7) then the second term is always zero!!! </strong></p><p>It should be modified like (if I am right):</p>ballVx = random(50., 80. + 5.*((float) scoreL + (float) scoreR))/500.; <p>Now, ballVx should go from { 0.1 to 0.16 (score 0 vs 0) } to { 0.1 to 0.3 (score 7 vs 7) }</p><p>I cannot test it at the moment, I will come back to this soon... </p>
<p>nice, thank you!! will try it asap :) otherwise I'll have a &quot;talk&quot; with the formula xD</p>
<p>why isnt the code working for me??? halp</p>
<p>hi <strong>Samo 2121</strong>, honestly I think the description you gave of the problem is a bit insufficient...</p>
<p>oh yea well nvm now its fixed...</p>
<p>hello rob. i made all of it, codes compiled with no errors but my monitor says no signal?</p>
<p>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 ;)</p>
but i used same scheme with different example and i got signal
<p>Dear <strong>MichalJ3</strong>, thanks for the suggestion given to <strong>MehmetO2</strong>. A further hint: the VGA plug pins have always a little numeration (from 1 to 15). You may need a magnifying lens to see them (or a very good view!). In case of doubt, you can follow the - hardly visible - numeration written on the DSUB 15 connector in the schematics above, thus, for instance, RED is on PIN 1, green is 2, etc...</p>
<p>Hey Rob! I need help! I'm getting an error when compiling the code:</p><p>pong_VGAx_v1.3.cpp.o: In function `drawMenu()':</p><p>/Applications/pong_VGAx_v1.3.ino:237: undefined reference to `VGAX::printPROGMEM(unsigned char*, unsigned char, unsigned char, unsigned char, unsigned char, char const*, char, char, unsigned char)'</p><p>/Applications/pong_VGAx_v1.3.ino:238: undefined reference to `VGAX::printPROGMEM(unsigned char*, unsigned char, unsigned char, unsigned char, unsigned char, char const*, char, char, unsigned char)'</p><p>pong_VGAx_v1.3.cpp.o: In function `drawStartScreen()':</p><p>/Applications/pong_VGAx_v1.3.ino:303: undefined reference to `VGAX::printPROGMEM(unsigned char*, unsigned char, unsigned char, unsigned char, unsigned char, char const*, char, char, unsigned char)'</p><p>/Applications/pong_VGAx_v1.3.ino:304: undefined reference to `VGAX::printPROGMEM(unsigned char*, unsigned char, unsigned char, unsigned char, unsigned char, char const*, char, char, unsigned char)'</p><p>/Applications/pong_VGAx_v1.3.ino:305: undefined reference to `VGAX::printPROGMEM(unsigned char*, unsigned char, unsigned char, unsigned char, unsigned char, char const*, char, char, unsigned char)'</p><p>pong_VGAx_v1.3.cpp.o:/Applications/pong_VGAx_v1.3.ino:306: more undefined references to `VGAX::printPROGMEM(unsigned char*, unsigned char, unsigned char, unsigned char, unsigned char, char const*, char, char, unsigned char)' follow</p><p>collect2: error: ld returned 1 exit status</p><p>Error compiling.</p>
<p>Hi <strong>damianlee84</strong>, it looks like a library problem. Do you have the latest version? </p><p>At some point the &quot;old&quot; command vga.print had to be changed in vga.printPROGMEM</p><p>see this <a href="https://github.com/smaffer/vgax/commit/a2a6df12ed129e8c1da7082c545e1fae68e55988" rel="nofollow">link </a></p><p>Furthermore I have Arduino IDE 1.6.4</p><p>Which version are you using? </p><p><br></p>
<p>Rob! It finally works! Thanks for your help. It was the VGA cable that was very old. I replaced it and it works. But I have another problem now. I started building the circuit and when I added the first potentiometer, it moves both players. I thought it was because I was missing the other potentiometer. I added the second one and now it starts glitching.</p>
<p>Hi <strong>Damianlee84</strong>. When only one potentiometer is connected (on A1) and the other pins are disconnected (A2, A3 and so on) it is normal to have some floating voltage on them that gives unwanted behaviour (such as the second paddle moves following the first one). If you want to temporary test the circuit before it is finished, you should at least ground the unconnected analog pins. </p><p>If this does not solve the glitch issue, please try v.1.2. The version 1.3 has just a faster &quot;<em>analogRead()</em>&quot; function, but it is not really needed and I did not tested too much this version. </p>
<p>Hi Rob, i fixed the library issue. Now, it compiles and uploads the code just fine (although sometimes it gives me a warning: &quot;Low memory available, stability problems may occur&quot;). But it doesn't show me anything on the screen. I haven't set up the buttons and the potentiometers, yet, because I wanted to make sure that it works for me. My IDE is 1.6. and I'm using the latest code (v.1.3). Thanks a lot for your help!</p>
<p>Hey Rob</p><p>Mate its working a treat now ..Thank you so much for your time :)</p><p>I made a copy of the original Pong Cab to put it in ...</p><p>Will look at how to get sound now ..Really enjoying this one ;)</p><p>If you have time in the future iwould like to add sound i will have a play </p>
<p>Hi Sunr4, this is really AWESOME! You make me proud of having done this project!</p><p>The sound is already implemented in the game code, you just need to connect a speaker to Pin A0 (and to ground of course). Let me know if it does not work! </p>
<p>Cheers ! :) ... I will work on the sound during the week me and my son have been having little tournaments on it ..Simple game but i think we are having more fun with this than the playstation at the moment :) </p>
<p>Hi Sunr4, you can connect a further button on digital pin 2 (D2), same way as for the other buttons, then you should modify the sketch as follows (the differences are in Bold) : </p><p>1) add the last line </p><p>#define WHEEL_ONE_PIN 3 //analog<br>#define WHEEL_TWO_PIN 1 //analog<br>#define BUTTON_ONE_PIN A4 //digital <br>#define BUTTON_TWO_PIN A2 //digital <br><strong>#define BUTTON_ZERO_PIN D2 //digital </strong></p><p>2) modify this part as follows</p><p>void processInputs() {<br> buttonOneStatus = digitalRead(BUTTON_ONE_PIN); <br> buttonTwoStatus = digitalRead(BUTTON_TWO_PIN);<br> <strong>buttonStatus = digitalRead(BUTTON_ZERO_PIN); // this is the START button</strong><br> wheelOnePosition = analogRead(WHEEL_ONE_PIN);<br> wheelTwoPosition = analogRead(WHEEL_TWO_PIN);<br> <strong>//buttonStatus = buttonOneStatus || buttonTwoStatus; </strong><br>}</p><p>I think it should work, but I cannot test it at the moment. Let me know...</p>
<p>Changed the new button to A5 seems to work but was wondering if it can start on that button and auto serve for each player until the end of the game ..Like the arcade version ?</p><p>Any way only if you have the time :)</p>
<p>Hi Sunr4, </p><p>sorry for the late reply. What you ask needs a simple modification of the sketch: At the end you have two almost identical parts, a bit after the comments </p><p><strong>// ball out from left ----------</strong></p><p>and </p><p><strong>// ball out from right ----------</strong></p><p>i.e.</p><p><strong>while(buttonOneStatus == 0){<br> processInputs(); <br> ballY = ((wheelOnePosition / 8) * (VGAX_HEIGHT-PADDLE_HEIGHT-1))/ 128 + 4;<br> drawGameScreen(); <br> PaddleHit = 0; <br> }</strong></p><p>you need for both to comment the &quot;while&quot; instruction, and eventually to add a little delay, i.e. </p><p><strong>//while(buttonTwoStatus == 0){<br> processInputs(); <br> ballY = ((wheelTwoPosition / 8) * (VGAX_HEIGHT-PADDLE_HEIGHT-1))/ 128 + 4;<br> drawGameScreen(); <br> PaddleHit = 0; <br> vga.delay(300);<br> //}</strong></p><p><br></p>
<p>Hey thanks :) Sorry this is my first ever Arduino project so i have lots to learn :)</p><p>I have edited what you said and see what you are doing but i am getting an error</p><p>D2 was not declared in this scope ?</p><p>Cheers</p>
<p>Hi Sunr4, yes, you are right!</p><p>1) Modify the first correction of before like this (i.e. &quot;2&quot; instead of &quot;D2&quot;)</p><p><strong>#define BUTTON_ZERO_PIN 2 //digital <br></strong></p><p>2) now this pin (digital 2) must be decleared as an input in void setup, i.e.: </p><p>void setup() {<br> //Serial.begin(9600); <br> vga.begin();<br> randomSeed(1); <br> <strong>pinMode(BUTTON_ZERO_PIN, INPUT);</strong><br>}</p><p>At least now I can compile without errors, even if I cannot test it yet! </p><p>I am happy you have choosen this project as your first ever with Arduino. I hope it works now.</p>
<p>Hi Rob</p><p>Sorry finally got back to this .. I did what you said and the game just jumps straight into the game and severs automatically .. No start screen and the game just keeps looping hehehe :) Getting closer </p><p>Really keen to get this finished and show you the final build :)</p>
<p>no schematic :-(</p>
<p>Hi Marc. Yes, there is a schematic! Just click the small left picture below the main one on the top! </p><p>The two buttons are used to start the game. The ball is assigned to the player that lost the last point, thus he can choose when to throw it. </p>
<p>Hi. nice instructable :-)</p><p>Why are the two button are for?</p><p>thank you.</p><p>Marc.</p>
<p>Is it possible to have a one button start (insert coin) like if it were in a arcade ?</p>

About This Instructable

15,717views

101favorites

License:

More by Rob Cai:Simple Grafting Without Special Tools Arduino VGA Game Console Arduino VGA Games 4-in-1 
Add instructable to: