NESBot: Arduino Powered Robot beating Super Mario Bros for the NES

 by pjgat09
FeaturedContest Winner
DSCN0222.JPG
This guide will take you through the steps to build an NES playing robot. 


You will need:

An Arduino Duemilanove (other boards will probably work, but you will have to adjust the steps for your device)
Working NES Console
Super Mario Bros. (Note: this must be only the single game, not the two- or three-in-one cartridge)
A controller you can cut the cord from
Two LEDs (two different colors are recommended but not required)
2x ~390 ohm resistors
3x 1.6k ohm resistors
3x 3.3k ohm resistors
4021 (16 pin Shift Register. Note: the 74xx series will not work)
SD Card slot (more on this later)
A pushbutton (not required, but recommended)
A switch (not required, but recommended)
A soldering iron (you'll probably need one)
Multimeter
Hookup wire

Software needed:
Arduino Interface, available from http://arduino.cc/ 
Processing, available from http://processing.org/
FCEUX, available from http://fceux.com/ (you probably want the windows binary unless you know what you're doing)
 
Remove these adsRemove these ads by Signing Up

Step 1: Background information

This project is based off the efforts of the people at TASVideos . For a full description of what they do, take a look at their Welcome Page .

Every approved submission (called "movies", even though they contain no audio or video data) on their website is simply a series of recorded button presses that in theory can be played back on the actual console for which they are intended. In most cases however the emulator differs too greatly from the actual consoles to make this possible, but in the case of the NES the difference is significantly smaller.

The game choice also makes a big difference as to whether the button presses can be played back or not. If the game relies on any uninitialized memory for randomness, or if it is heavily based on console timing, it may not work. In the case of Super Mario Bros however, as long as the button presses start play back at the right time, the movie will play back correctly.

These button presses are based on frames on the console. Almost every time the console redraws the screen (~60 times a second), the controller is polled for input. However, there are times when the screen is redrawn, but the controller is not polled. These are called lag frames. Due to the difference in the way the emulator handles these lag frames, any movie must be modified to run correctly on the console. This is handled later on. 

To turn "in theory" into reality, we will start by modifying the controller. 
1-40 of 54Next »
Derpancakes says: Mar 27, 2013. 8:34 PM
Just got an NES today. Totally doing this!
space explorer says: Mar 9, 2013. 3:20 AM
almost absolutely impossible for human..awesome!
GenesisMaster says: Jan 2, 2013. 8:20 AM
I tried to create a NESBot shield on DipTrace. I got this (see the picture below).

 Is it all OK?
NESBot Shield.BMP
pjgat09 (author) in reply to GenesisMasterJan 2, 2013. 9:18 AM
Hard to say without checking out all those traces by hand. Cool to see it in shield form!

This instructable is kind of stale now. I really need to update it, but haven't had time. I have since removed the need for processing, and instead the movie files are loaded as files directly onto the SD card. I can try to find all the actual changes if needed, but I think this instructable might still work.

If you decide to get this printed, I'd love to see the result!
GenesisMaster says: Dec 4, 2012. 8:11 AM
I don't understand your schematic very well. What are all these "GND"? Are they somehow linked? And these tracks linked by green dots?
pjgat09 (author) in reply to GenesisMasterDec 4, 2012. 9:45 AM
GND stands for Ground. The arduino and the NES have seperate grounds. In my schematic on the right I link them together (ARD GND and NES GND) to make just GND (with the symbol). Then yes, all the GND symbols are tied together and would be plugged into the GND port on the arduino.

The green lines are connections. The green dots are just to clarify that when multiple wires meet they are connected. Otherwise they are not connected and are just crossed wires.
AldricLopezVergara says: Nov 11, 2012. 5:15 PM
Hi Im trying to do this same thing but without the arduino, I was thinking of using an EEPROM, some counters, and the shift register. But I dont understand whats in the txt file the lua creates. Is it the exact buttons frame by frame?
techboy411 says: Sep 6, 2012. 9:17 AM
why is the converter is solderder
GASSYPOOTS says: Dec 20, 2011. 5:40 PM
can you fix it to use the duckhunt/mario one? or possibly a DSI game
Kingpin3k says: Oct 27, 2011. 7:03 AM
Why does the 7421 not work and is it possible to drop the ShiftRegister if you are using the shiftout function of the arduino?
pjgat09 (author) in reply to Kingpin3kOct 27, 2011. 7:34 AM
The 7421 is a dual 4-input AND gate, so I'm not sure how that would be useful. The closest 7400 series chip I found was the 74165. I actually started by using that chip, but if I recall correctly the clock input is inverted compared to the 4021. I tried using a NOT gate to fix that, but it was too slow and I lost sync very easily.

I switched to using the 4021 after my order for them came in since it is the chip the controller actually uses. I don't think using the shiftout will work on the arduino due to the speed required. The latch pulse arrives every so often, slow enough for the arduino to handle, but after it arrives the 4021 is clocked 7-8 times extremely quickly, faster than the arduino can likely handle.
elijahlucian says: Feb 13, 2011. 9:37 AM
now try that without cheats.
skitchmusic in reply to elijahlucianFeb 20, 2011. 8:00 PM
There were no cheats used in this run. It's a Tool-Assisted Run, but there are no external cheats modifying the game's actual code to make it run this way.
vader406 in reply to skitchmusicApr 20, 2011. 12:16 AM
Well this whole thing is still an external cheat lol.
Flyinseamnky in reply to elijahlucianFeb 13, 2011. 2:01 PM
right!
Sgt. Cookie says: Mar 17, 2011. 6:34 AM
The world is going to hell in a handbasket and you created SkyNet. Thank you.



On a serious note:

Cool, all you need now is one that can play brawl and you will be champion of the world, at brawl.
ThisIsFake1 says: Feb 22, 2011. 2:38 AM
So you are still saying this is not fake? And that it's your code playing it? So in 4-2, your robot just happens to use a glitch? You just happen to be jumping in the exact interval to use a glitch??
kellykel in reply to ThisIsFake1Feb 28, 2011. 2:14 PM
It is just playing back button presses, no robot is figuring out what to do.
kellykel says: Feb 27, 2011. 10:59 AM
There are so many noobs here. This is real. Those are just glitches that are hard to do unless you are TASing. Talk about something you know about.
saintneko says: Feb 15, 2011. 1:10 AM
Sorry, this is faked.

At 4:50, notice how the Piranha Plant disappears when Mario jumps up onto the tube. It doesn't retract, it just disappears as he lands on it.
skitchmusic in reply to saintnekoFeb 20, 2011. 8:02 PM
No, it's not faked. Anything that appears to be an oddity are side effects of glitches within the game itself.
lioneyexp says: Feb 13, 2011. 3:58 PM
Next Instructible from him should be "How to heavily mod Super Mario Bros. so that you can phase through walls, disregard Piranha Plants, and ignore virtually any other threat in the game."
skitchmusic in reply to lioneyexpFeb 20, 2011. 8:01 PM
The game was not modded, and none of the techniques demonstrated involved modding the game.

These are all exploits that existed in the original game, but are generally difficult/impossible to generate under normal circumstances.
gossumx says: Feb 10, 2011. 2:54 PM
Why don't the Piranha flowers hurt him?
patrick p f in reply to gossumxFeb 10, 2011. 3:21 PM
its a cool skill to have in super mario. because of how mario jumps, if you time it right, you can just make it over a piranha. i can do it without even thinking
Flyinseamnky in reply to patrick p fFeb 13, 2011. 2:04 PM
no man he touched them. he did not make it over them.
skitchmusic in reply to FlyinseamnkyFeb 20, 2011. 7:59 PM
Yes, but the way collision detection works in Super Mario Bros, that specific type of collision does not result in death.

It's a known glitch in the game.
popscott3 says: Feb 19, 2011. 9:13 AM
WWWOOOOHHHH!!!!
lioneyexp says: Feb 13, 2011. 1:16 PM
Mario can wall jump?? 3:55

did you just jump off of lava? O_o 4:49
touched the flame rope? 5:11. 5:14
touched the squid? 5:12, 5:15
thealeks in reply to lioneyexpFeb 17, 2011. 2:30 PM
there was a platform in the lava.

the flame rope and squid, i have no explanations for.
Flyinseamnky in reply to lioneyexpFeb 13, 2011. 2:03 PM
Yeah I noticed that none of the plants hurt him, that he was running across gaps, and could run through walls that as far as I know of you could not do before. Like the first warp zone. Usually you have to use the moving platforms to get on top of the bricks and run across.
mdmetzger in reply to FlyinseamnkyFeb 14, 2011. 5:03 AM
For the jumping off lava, there's a platform down there that's difficult to see in the real game. Almost everyone spent way too long trying to figure that out unless you spot it early on.

As for apparent collisions with squid / ropes / piranha plants / etc, the collision detection algorithms aren't perfect in this game (remember, this was made in 1985...) so if you time it right you can seemingly pass by the edges of something.

Running across gaps works fine as long as there's only a single block gap on a panel (ie, several in world 8, etc.)

And you can definitely slide through bricks - the trick in 1-2 is actually a method to get to the so-called minus world (-1) that is a never ending water world.

It looks weird, and part of the oddity with this is the 'perfect" computer controlled player, but every one of these tricks can be done by a human with the right timing. I've done all of these at one time or another save for the jumping out of the large gap - now I'm really tempted to try it...
thealeks in reply to mdmetzgerFeb 17, 2011. 2:31 PM
i know the minus world trick, but how come it didnt send the computer there? this whole thing is fishy
mdmetzger in reply to thealeksFeb 17, 2011. 9:35 PM
Because if you go far enough to the right, it treats it as a normal warp zone rather than the minus world / level 5 warp zone.
anthnysantos says: Feb 15, 2011. 2:36 PM
Nice project, but the instructable needs some work. Mostly, you fail to list several components and never really mention them. For example, wouldn't I need an SD card? Also, you never list the part you used to connect the Micro SD adapter to the breadboard. Normally, this is not a huge deal, but is definitely aggravating to someone who has not used an Adruino controller before or has little experience in wiring SD cards. There definitely needs to be some clarity around the use of the SD card.

Other than those details, it seems to read pretty well for a novice audience.
AntzyP says: Feb 11, 2011. 3:22 AM
was pretty sure he'd be dead meat at 3:53...
fadeddeath in reply to AntzyPFeb 15, 2011. 10:01 AM
He would also have died in the under water scene at 5:05 5:10 5:11 5:12 5:14 and 5:16 but that's not the biggest tell that it is fake. Since when does an NES system start up that quickly. . .
PaulMakesThings in reply to fadeddeathFeb 15, 2011. 10:43 AM
Also Mario doesn't move forward, at least not nearly that far, while facing backwards.
AntzyP in reply to PaulMakesThingsFeb 15, 2011. 12:20 PM
nah, its not fake. Check out the site he mentions. It's really a sequence of key-presses created after using a very complex emulator which allows us to rewind time and remove our mistakes(kinda like braid, i guess)...
faxwork says: Feb 14, 2011. 12:18 AM
There are a lot of glitches and tricks you can do in SMB. This is real. It is apparent that the robot in this instructable is better at this game than we can possibly ever be, with such perfect timing and execution of said glitches.
1-40 of 54Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!