Thursday, May 21, 2009

That damn flippity flop music

Otherwise known as flip-flops - these are handy structures that store 1 bit of information - a 1 or a 0. Imagine 8 of them put together and BAM - 1 byte of memory, or imagine 8589934592 and again, BAM, a gig of memory!. So I dont really need much memory for my application as it is all going to be controlled by a laptop which has its own memory anyways. What I do need, though, is a way of remembering if a button has been pressed or not in hardware. This is because (and i cant remember if i talked about this earlier) i cant guarantee that ill be checking the state of a switch while it is actually pressed, so the next best thing is to work out if it was pressed.

Now theres a heap of different flip flops that one can use: SR (set-reset), JK (not sure what that stands for) and more. I have elected to go with an SR type flip flop, which I made myself out of a couple of NAND gates. I reccomend spending some time on this site: learning how stuff works. If you check out the SR flipflop (unclocked) on that site, youll see a part of the circuit im creating.

So i couldnt find any SR flipflops in a handy dandy IC package so i decided to make my own out of the heap of nand gates i had lying around. I got a little lazy and decided to do it all on a breadboard.Breadboarded NANDS to make flip-flops

Those wires hanging off are going to be terminated with a standard 40 pin IDE cable, and connected on to the actual input board (more about which later).

Thursday, May 14, 2009


Been a bit lazy lately, been trying to buy our first house, and it is consuming a lot of my time, and is exceedingly frustrating. Aaaanyway here is a post about inputs!

So we've more or less got lights working, but now we're going to need a way to detect what buttons have been pressed and when. Remember how the 4094 chips were serial in, parallel out?? Well we're going to use a slightly different chip called the 74HC165 (which will be affectionately known as a 165 chip from now on). It takes parallel inputs, and converts them all into a handy dandy serial output for you. They work in much the same way as the 4094 chips do, but instead of setting a bit to 1 or 0, we will be reading a 1 or 0 bit to determine the current state of a switch.

Initially i had breadboarded this and it worked out fine, however when i started wiring this up to actual switches on the pinball machine, i ran into one major problem - which was almost a show-stopper. See when a pinball runs over a switch embedded in the playfield, the switch is only pressed momentarily. Now unless im checking the state of the switch at that exact time, the switch is going to read 0. Since I cant guarantee that the state will be read when its pressed down, this means i would miss out on some switch presses, which is a bad thing (tm).

Back in the day when i was writing video games for a living, we had something called a was-pressed state as well as an is-pressed state for each button. So at any stage we can know if the button is currently pressed or had been pressed in the past. I wanted to implement something similar for the pinball (maybe without the is-pressed as all switches will be momentary). I realised that i needed to do this with hardware, so i'd need a flip-flop. A flip flop can store exactly 1 bit of data, and in this case will be storing a switches state. There are various different kinds of flip-flops which work slightly differently, however i decided to go with a simple S-R (set-reset) model, which i made myself.

Next post will be alllll about flip flops for your reading pleasure.

Wednesday, April 15, 2009

4094 chips II

Following on from the previous post, here is where ill talk about what each of the 4 input pins on the 4094 chips do. These pins are Output enable(OE), strobe, clock and data.

Easiest one first: the OE pin is pretty much a global 'all outputs on/all outputs off' switch. I cheat here, because i dont really care if the lights are in a weird state before i start my program (if i cared, id keep OE low until i was ready to start doing stuff with my lights), ill just jump this pin directly to +5v. This probably isnt the best thing to do, but hey, it works and also saves me a pin. Additionally, i had trouble with this pin when supplying it from a parallel port (no such trouble using the basic stamp though). Keep this pin in mind when you are testing, as i kept forgetting about it and wondering for hours why nothing was working.

So now in order to set some states to my lights you do it in REVERSE ORDER. This is because the chip (or chain of chips) are shift registers. meaning the first bit you output gets put in slot 0. The second bit you output gets put into slot 0, and at the same time, whatever WAS in slot 0, gets shifted down the line to slot 1. So you start sending data like so: Send a state, then PULSE the clock pin. Pulsing means go 0->1->0 (or low,high,low) - this also assumes that clock is always set to low - which it should be. So repeat this process till all of your lights have been output. After the last clock pulse, all you should have to do now is pulse the strobe pin from low to high and back to low. This actually puts all the states that you just input into an 'active' mode and sets the 4094's outputs accordingly (there would have been no visible change to the output states until the strobe was completed).

4094 Serial-in-to-parallel-out chips

This is the part of the blog that gets a little programmer-ey - this post will outline how the 4094 chips work.

Firstly your basic stamp/parallel port/whatever that you are using to control the pinball machine only has a finite amount of outputs (probably 8 or 16 or something). The parallel port has 8 (more if you cheat a bit - or so im told) and my basic stamp has 16. Hobviously, this is well less than what im going to actually need if i want to control 40-odd lights and 20-odd switches. Standard pinball machines use a light/switch matrix, which from what i can guess, strobes each row of the matrix in order from top to bottom while turning on or off the required columns to light up the controlled playfield lights. I speculate that as this happens very fast and due to the fact that its using incandescent globes that take a while to turn off, it can give the illusion of always-on lighting. Anyway with the light matrix idea for up to 49 lights, i'd need a 7x7 matrix, which would still take up a good 14 pins. A good saving, but still too many.

Myself and some former workmates had once tried to make a pinmame hw board unsuccessfully, and had shelved the parts. I dutifully ninja'd these parts home and started trying to figure out how the 4094 chips worked (note that 595 chips will do pretty much the same thing, but i either couldnt find them or they were more expensive).

Off the top of my head the exact chips i had were: 74HCT4094. The other similar chip is the 74HC595 (more info and comparisons on the two from here: Also note that i learned most of what im spewing out here from that website.

Basically what the chip does is take some input from 4 (thats right, 4!) pins serially, and set a bunch of outputs (LED's) states. For example if i have 8 led's and i want every second one on, i (and this is abstracted and pseudocoded) say: "OFF,ON,OFF,ON,OFF,ON,OFF,ON". The chips goes 'ok thats the pattern, ill just set my output pins to these states - no worries'. In real life (irl) this is slightly more complicated, but thats the basic gist of it.

Ok so there are 4 input pins that we care about ont he 4094. These are data, strobe, Output enable (OE) and clock. Additionally, im powering all this from +5v DC (this includes all the led's). The chip has 8 parallel outputs, AND is so cool that you can connect multiple 4094's to each other and get n (well some large number - but the bigger it is, the slower stuff will work) led's working all from the same 4 pins!. I have 6 all lined up and working in mine thus far.

Lunch time is over! Detailed info on how to use the chips coming up later!

Friday, March 20, 2009

Transistors n such

So since I had to learn how transistors work and what they actually are, i thought id write about them. Transistors are cool - apparently most everything electronic you have ever had anything to do with (post invention of the transistor) had one or more transistors in it. Quick disclaimer: what im about to write about may be horribly inaccurate and possibly wrong, but is what i understand about transistors.

Soooo transistors have 3 legs on them, called Base, Collector and Emitter and they work like this. If you give some current to the Collector leg then nothing much happens. If you give current to the Base leg only, then i think that you will see it pop out the emitter (provided of course that it is connected to ground or whatever). Now heres the fun part: Give some current to Collector AND to the base, then you get base + collector coming out of the emitter. So pretty much its like a switch between Collector and emitter that you can turn on or off (or steppings thereof) by supplying some (much lower) current to the base leg.

Say for example you have a basic stamp or something that only supplys 10ma (i made that number up but what it supplys is low enough) but you need 100ma to run all your led's and whatnot. Easy, just point the 10ma to the base of your tranny that has 100ma on its collector. Now its emitter has 110 coming out of it.

Now it gets a touch more complex than this as there are various different transistors out there that can handle different max voltages/currents and need different amounts of voltages/current on their base to turn them on or off. I use a 182b transistor for my stuff as it is a general multipurpose tranny that (luckily) does what i need it to do.

Oh heres a fun fact. If a tranny is completely off or completely on, then it generates not very much heat. If it is partially on, then it will generate heaps of heat as it is actively curbing the amount of stuff (current/voltage/whatever) going thru it, and the stuff that isnt getting through is being disappated as heat. This is why (i assume) some trannys are attached to heatsinks.

Something else to be aware of is that trannys can come in different packages and the pinouts may change. Read the datasheet on your trannys to work out which pins are B, C and E. Additionally there are 2 types of transistors: NPN and PNP. I just described an NPN transistor.

Thursday, March 19, 2009

Lighting (controlled)

After the Gi was done and working (pretty much a no-brainer - just connect it all up to 5v and you're laughing) it was time to move onto the controlled lighting. First thing I did was to wire up all the lights. I had picked up some phone cabling (i think) which had 4 cores through it. The controller IC's im going to use have 8 outputs, so that worked out well, just wire up two sets of 4 to each controller chip. The fact that the cables were grouped in 4 made the back side of the machine a lot neater (but probably not as neat as from the factory).

While all this was happening, i had ordered a basic stamp from parallax ( - the bs2sx OEM model (OEM coz i didnt mind building it myself, and also it had a serial port built into it, as well as handy dandy outputs that i could plug into an IDE cable).

Link to the bs2sx:

Next my main problem was that the basic stamp i chose has only 16 in/out pins for me to play with, which is well under the 43-or-so lights that i needed to control. I thought about a heap of solutions to this, such as an output matrix and flip flops, but the simplest solution is to do it the same way as the pinmame-hw guys - that is to use some separate IC's which are serial in, parallel out chips. 74HC4094 or 74HC595 (which as far as i can tell do the same thing, but with slightly different pinouts).

As it turns out, I had a handful of these chips still floating around from a previous failed attempt at making the pinmame HW circuit. The best move I made here was to purchase some breadboards and prototype the hell out of these things to get a good understanding of how they worked.

(Prototyping the IC's - i used an itermediate board between the basic stamp and the chips, connected by IDE cable - which the stamp fits into perfectly.)

I was basing my design off the pinmame-hw (but using the stamp instead of parallel port) which can be found here: Turns out that they got most of their HW info from another very handy site here:

So after a heap of prototyping and soldering i finally had created my first prototype hardware board for the qbert pinball machine.

(Top of the light interface board)
(Rear of the board)

Pro-tip: use the chips to control transistors which allow current from an alternate power source, as i doubt the chips would be able to provide enough power to light all the lamps. Next post will cover some basic transistor theory!

Tuesday, March 17, 2009

Lighting (GI)

The first thing I did with this project was to pull off all the wiring, and lights. I unscrewed each and every light socket and pretty much cut the wires to each of the coils and switches, as i planned on wiring it all up myself later.

(playfield underside with wiring and lights removed)

I then had to work out how i was going to mount an LED in place of each globe. The solution I came up with was to solder a resistor onto the -ve leg of the LED, then solder the +ve leg into the light socket, while wrapping the -ve leg around the outside of the socket like in the image. From there mounting the LED was trivial - just screw it into the existing hole, and wire it up.

(LED + Resistor in a socket - early version - subsequent attempts got neater)

First thing to do was all of the GI (general illumination i.e. always-on lights). I chose to use 5v DC for all of the lights, as the microcontroller I bought can run off 5v, too (more on which later). As this was my first attempt at anything electronic related, it took some learning of soldering skills etc, but I got much better at it as work progressed.

(half of the GI complete)

Monday, March 16, 2009

PC controlled pinball machine (Project Overview)

Here's my first post. Blogging kind of goes against everything i stand for, but im doing this cool pinball project thing at home, and thought i might write about what im doing and how im doing it to help other people who might want to try something similar.

I aquired an old q-berts quest pinball playfield from the local pinball people and decided that i wanted to turn it into a coffee table. Bear in mind it was the playfield only, with a heap of components and wires etc on it. These wires had all been unceremoniously chopped off where they would have gone into the cabinet to be controlled/powered etc.

(the playfield as i got it)

Initially all i wanted to do was control the lights so i could plug my coffee table in and have it light up. From there it grew into a desire to control the lights using code. I found the pinmame-hw site ( and started playing around with electronics and things, and it kind of just grew from there.

As i get around to writing more - ill go through all the different stages of the project to date, how I accomplished them and any problems/issues I had to overcome.