Developing a handheld console with Arduino

IMG_3163Since my first exposure to computers and video games, I have wanted to design and build my own. Lacking, however, the resources and knowledge, I thought it would just be a pipedream. Well, fortunately for me, that is not the case.  The technology is to the point where just about anyone can do so and for just a little money and the internet.

Microcontrollers are the key and companies like SparkFun and AdaFruit can supply the bits. If you are really tight on funds or just cheap (like me) you can save a bit by shopping eBay. 

So, what can these microcontrollers do for you? Well, anything you want. And, yes, they can play games.

My original plan was to use something like AdaFruit’s Trinket for the brains and the Nokia 5110 LCD for the screen. Well, the Trinket is just too limited (and, frankly, difficult to program.)  During a lengthy eBay search, I found a bunch of Arduino UNO clones that fit in about the same space as the Trinket, only with more I/O and more memory. I ordered a few of them and then waited almost a month to get them. In the mean time, I used my UNO to start writing code.

IMG_3182Along the way, I discovered the Arduino’s were capable of video, so I spent a few weeks playing with that and have built a game console that I will revisit once my plate is clear. Adafruit and other vendors sell interfaces for the Wii Classic Controller and the Nunchuk…both of which are very easy to code.

Back to the handheld. The Trinket filled in, physically, for my board layout. When the Mini Pro finally arrived, I socketed it and began to wire it up. A strip for the 5110, connector for the speaker and daughter board for the audio amplifier. I wrote up a short demo that married the audio to the graphics library and produced a static Mario splash screen and beginning of the game.  It plays the Super Mario Brothers 2 theme upon startup.1398742_562906223779137_852686949_o

My next tasks include a controller (a matrix of four buttons: Left, Right, Shoot, Start/Stop) and a case. The actual game code will be last. I want the hardware nailed down before I do all of the code.

The system will run off of three 1.5 volt AA batteries. I wanted to use a rechargeable battery, but the added complexity is more than I want to deal with for now.

1425448_569760583093701_1031881671_oThe case is my biggest headache. I was going to use Lego’s, but the cost is more than I want to pay. I have an old Mattel JuiceBox that I will attempt to use. It looks big enough and already contains a battery compartment, holes for the controls and a speaker bay. It’s just really ugly.

I am also building version two of the handheld concurrently. This one will be for myself (the other is for my step son) so it doesn’t need to be as friendly and compact.  At some future point, I may take lessons learned from both and make a third version.  My version will also output video and has a PS/2 keyboard connector.  I have a version of Tiny Basic that will work with this hardware and this will be my portable computer and game console.1267690_572617716141321_1112089022_o

I have, so far, been pretty successful with my creations, even though I have a very rudimentary knowledge of electronics. I know what resistors and capacitors do and an understanding of transistors. More importantly, however, I can read a schematic and everything I’ve done has come from schematics found on the internet. In some cases, I’ve only borrowed parts of the schematic, in other cases, I used a basic schematic from a datasheet (talk about boring) and have put this stuff together on my own.  AdaFruit and SparkFun have terrific user forums and they have been a big help as well.  But, there is one site in particular: Arduino-Info. This site has code, schematics and really easy to understand explanation about each project. It covers basic things like LCD’s, keypad’s, servo motors and basic Arduino. It explains many electronics concepts and has lots of examples. It has been invaluable.

The Nokia 5110 LCD is a low cost and easy to code panel. It is low res, 84 pixels wide by 48 down. It is challenging (I have an even better appreciation for developers in the ‘70s and early ‘80s) to come up with graphics that look good in such low res. My Mario character looks more like Mega Man. It is a great choice, however, because it has a low memory footprint: 504 bytes for the frame buffer. This still gives about 1.4K to work with, a gold mine.  You can get them from AdaFruit or Sparkfun for under ten dollars or on eBay from $1.88 to about $3.00.

That brings me to parts buying. If you buy them on eBay, it will likely be from an overseas vendor.  I ordered parts from several Chinese vendors and, in all but one case, I got the items within two weeks and free shipping. I would highly recommend getting them from North American vendors. If you look, you can get pricing that is close to the Chinese vendors and still get free shipping. I got my Mega and one of my UNO’s from vendors located in North America. I had those items in just a few days, so it was worth the extra dollar or two.  I also buy from AdaFruit, SparkFun and Jameco. Some things, like the UNO and Mega, cost two to three times the eBay price. I paid ten bucks for the UNO clone and AdaFruit wants $23 and JameCo had one for nearly fifty. Radio Shack sells the UNO for $34.00. As for the Chinese vendors, I bought a bunch of small parts: joysticks, Mini Pro’s, keypads, LCD panels, sensors, etc.  The smallest order was $1.88 and the biggest was $16.  In all but one case, I got the parts in about two weeks, one took a month and one never arrived, but they did issue a rebate and an apology. I would buy from them again, That was the $1.88 order.

I will post more about my project at a later date

Follow Half-Byte on Facebook for more frequent updates on my projects and other tech news.

Advertisements

Real do it yourself computer using Arduino or…how to make your own game console

IMG_3043Ever since I was a kid, there were two things I’ve always wanted to build: a computer and my own video game ‘console.’ Now, I grew up in the seventies and eighties, so both of these things were pretty crude, some even crude when they were new (RCA Cosmac, I’m looking at you!) While in the intervening years, I did ‘build’ both, I cheated in doing so. With the computer, ‘building’ one was simply buying premade cards and a motherboard and installing them, hardly building one. With the video game ‘console’, I assembled a ‘pong’ style game from a kit (which I wrote about here.)

Now that I have discovered the wonderful world of microcontrollers, I can, finally, actually build both of them.mk121pal

Today’s microcontrollers are as powerful, if not more so, than yesterday’s microcomputers. For instance, the ATMega 328 is every bit as capable as the 8080, one of the mainstays in the 1970’s. Because of this, you can build real computers that are very small and require little power. They also require substantially fewer parts to work and be useful.

While I am no electronics engineer, these chips are simple enough for even someone like myself to design and build a working computer that can, subsequently, become a game console.  Companies like Adafruit, iConstrux, Spark Fun, Arduino and others all have components that are geared toward these nifty little devices. Adafruit, for example, sells the Nunchucky, which is a tiny little board that allows you to easily interface a Nintendo Wii Nunchuck controller. These controllers are, themselves, very cool and underrated. They feature accelerometers, a joystick and two buttons and are easily read by these little processors. And, with the Nunchucky, you do not need to cut its cable.

IMG_3070While it is old news, it is new news to me…the Arduino’s are capable of limited video generation and, hence, limited graphics. Now, while the graphics ability will never threaten nVIdia or AMD, they will give the aforementioned RCA Cosmac a run for its money. 

Armed with this knowledge, the Nunchuck/Nunchucky, some basic soldering skill and enough knowledge of electronics to be somewhat dangerous, I have set out to build that computer/game console.

I am actually doing two consoles: a handheld for my stepson and a somewhat more capable one as my exercise in designing and constructing said system. The handheld will utilize a small joystick, a Nokia 5110 LCD and a speaker in addition to the Mega328 Mini Pro.

Unfortunately, I ordered a great deal of my parts from eBay and just about all are shipping from China, apparently by foot as they have not all arrived.

IMG_3041However, since my Uno did arrive, I’ve been able to design and build the Half Byte game shield and start working on a prototype game, based on the Super Mario games. No, the game will not be made public, but, perhaps, a modified version with different characters may be. I do not have license to distribute any copyrighted material from Nintendo.

The game shield currently features the audio and video out connectors, the 1kohm and 470ohm resistors that allow the video to work (along with a library for the Arduino), the Nunchucky board, Arduino I/O pins and the header for the Parallax Serial LCD (which uses digital pin 2.) I may add digitized sound output as well and, perhaps, blinky LED’s and support for my custom three button controller.

arduinovideoThe tricky thing with the video is that it is all handled by the processor. The resistors ‘fool’ most televisions into ‘thinking’ there is a legit video signal. The 1k resistor handles the sync while the other handles the video itself. It was very easy to do and only involved the sacrifice of one video cable (and, since then, I acquired actual connectors so I can use better cables.)  Because the processor does all of the work, and has a very limited memory space (2k of ram, tops) the resolution is a paltry 120×96, though I had to back it down a bit to about 100×96, I needed a bit more ram. There is a common library, called TVOUT, available that most people use, though a few have written their own. The common library provides for three different fonts, lines, circles, inverse video and other niceties. It also can display bitmaps, though they MUST be correctly formatted and converting a bitmap for use is a bit of a pain. You must first resize the bitmap to fit the tiny screen, then you have to save it as a monochrome bitmap, process that file through another program that creates the hex codes that go into an array in the Arduino PROGRAM memory (NOT RAM, but the Flash memory that stores your code.) I’ll post more instructions in a later post.

proto Mario 1So, once I got the video and audio up and working, I played around with some code. First, the TVOUT demo then my own code. The TVOUT demo is pretty cool with a nice rotation sequence. It also displays the bitmap for the schematic to generate the video, an interesting inclusion.

My ‘mario’ game began as a demo. I wanted to move an image around, controlled by the Nunchuck. I wanted to use Spongebob, but I could never get him to look right in such low resolution. Now, how damned hard is it to represent a SPONGE? UGH.  Mario looked much more recognizable and that’s what I went with. Once I had my bitmaps done, moving them around was easy.  I now have Mario, a Koopa Troopa and a Warp Pipe in my level.  I am using another game called Poofy for some direction. Poofy is a side scroller for Arduino that uses some interesting methods and code that are in the public domain (and developed by the people who brought us Hackvision, an Arduino based console similar to what I am doing.)

My next step with the game is a scrolling world, Mario’s ‘weapon’ and a story.

I will be documenting the process, so stay tuned!

For quicker updates, follow Half-Byte on Facebook.

Links: