Rss

  • twitter
  • youtube

Multi-Tasking Arduino Pinball Audio

 

Well, another project has already consumed some of my time. I have decided to do a large project that will take up alot of time and would be a great learning experience. I have decided to make a pinball machine! And what a great theme, NBA Hangtime! I use to play this game growing up and still do, I even have a MAME machine sitting inside a Hangtime Cabinet. What makes the game excellent are many things, like the dunks, the minimal rules, 2 on 2, and who can forget the audio??? “Ooohhhhhhhhhh… BOOM Shaka Laka!”. Well I thought that the audio board would be the first thing to do, since it would make or break this machine. I am very pleased with the outcome!

Parts I used:

3 – Arduino WaveShields

3 – ATMega328 with Arduino Bootloader

3 – SD Cards

  1. Misc parts for the ATMegas (Read this for standalone ATMegas)

  2. Arduino Mega 2560 (Any will work, it sends the commands)

I recommend reading up on the I2C protocol if you do not understand it, it is VERY useful! (HERE)

So, one of the main problems people have with ATMegas are the fact you can not do multiprocessing, so in this example, if your playing a sound, you can not play another suond till that first sound is over. This is pretty much unacceptable for pinball machines. You have background music, and other effects happening all at once. So this is where the amazing I2C protocol comes in to help. It allows you to hook up many ATMegas taht can talk to each other. This allows you to have a Master sending commands to other arduinos so that they do the processing while the master goes onto other things… Soo.. Multiprocessing! (some micro-controllers can do this themselves, like the Parallax Propeller, it has 8 cogs, which are separate processors, but I wanted to do everything with Megas, since I understand the code, and its a challenge!)

In this last picture you can see the horrible ammount of wiring I had to do to get it all to work. But what i want you to look at is those Blue and Green wires coming from that molex connector. These are the I2C lines. They are just daisy chained from one mega to the other. If you look at my code, i send them commands based on what is happening. Each Mega has a separate address, in this case, they are 1, 2 and 3. So I send this command from the master…

sendcom(11, 27);

void sendcom (byte x, byte y) {

    Wire.beginTransmission(2); // transmit to device #2

  Wire.send(1);        //sends a command to tell it is “On”

  Wire.send(x);        // sends directory number

  Wire.send(y);       //sends file number, or “random number”

  Wire.endTransmission();    // stop transmitting

}

Then the slave arduino #2 gets 3 bytes. It recieves..

(1, 11, 27)

So it takes those and plays a file off the card (check the waveshield website for more info on that)

1 means its on, then it looks at the 11 (which on the SD card is the files in the 1100s, like 1101, 1125, 1131) and then it sees the 27 which is file 27…. in the 1100s…. so file “1127.wav”. The reason for this is I have some math that allows me to do random plays. It is constantly adding the int “randomnumber” by 1 till it hits 51, then tells it to go back to 0. That way when I use “randomnumber” like…

sendcom(11, randomnumber);

 

it will tell the slave to play a random file in the 1100s. This works great when playing pinball to keep things fresh. There is ALOT of possible combinations with this!

 

Getting all of the audio was very very time consuming. I used a program called M1. It dissects the game rom file and I could extract all the tracks. This took a very long time and I ended up with hundreds of sounds, commentator sayings and music. Now I have all of that organized and can make my own audio on the fly. Way Way Way better than trying to record the audio in game, it would have horrible background sounds and whatnot. I probably wouldve given up on the idea if I didnt find that M1 program and got all the sounds by themselves.

 

HERE is the M1 Program.

 

Source Codes:

 

master.txt

slave.txt

 

I am still working on the code and the way it will all work. This is going to be a LONG project, and im sure ill have other projects in the middle of it, but it will get done eventually. If you have ANY ideas for the machine, please email me, let me know what you got! Represent NBA HANGTIME LOVE!