GameClockDuino : Game timer

I play Go. It’s a really great oriental game played between two people. Takes about 90 minutes to play, has a handicap system to allow better players to play beginners, with each having a fifty-fifty chance of winning. It’s easier to learn than Chess. Computers are rubbish at it. It’s huge in the far east, on the internet and of course at some local clubs.

I’m fed up with the lack of a byo-yomi/fischer timer for blitz games played at the local club with mechanical clocks… Time to get inventive…

Here’s how it turned out…

img_2183

Click on to find out more on how this was made…

The Challenge

Create a games timing clock, for Go (or Chess I guess, but it won’t get used for that all the time I have it) which handles all of the common timing systems :

  • absolute – Each player gets X minutes to complete the game. If the count-down timer gets to zero, they loose on time.
  • canadian – Each player gets X minutes initially to use as they wish. When the count-down timer gets to zero, they get Y1 minutes to make N1 moves. If they’ve not made enough moves when the Y1 count-down timer gets to zero, they loose on time. If they use all their N1 moves, then they get another Y2 minutes to play N2 moves, and so on until the game finishes. Mostly N2=N1, Y2=Y1…etc, but sometimes things differ, for example Nn=N(n-1)+5 causes the time pressure to increase as more time periods pass.
  • byo-yomi– Each player gets X minutes initially to use as they wish. When teh count-down timer gets to zero, they get P “periods” or “lives”. N seconds are given whenever it’s your turn to move. If the N count-down timer reaches zero, then you get an extra N seconds at the cost of one of your P periods. If P reaches zero, you’re into “sudden death” mode which means the next time your N count-down timer reaches zero you loose on time.
  • fischer – Each player gets X minutes initially. Timer counts down. After each move, you get Y seconds added to your time. If the counter gets to zero, you’re out of time.

The cheapest commercial alternative I’ve found for this costs about £70. So if I could make it cheaper than that it’d be amazing.

It’s also got to be

  • battery-powered and mobile. Optional “brightness” settings to allow for longer battery life. Optional “sleep mode” if it’s paused, but not used for a while.
  • strong, so players getting carried away can really smash the “I’ve moved” button with force and feel good after.
  • wipe-clean, as the environment is a pub, where beer sometimes gets spilled. I’m not saying it’ll be submerged, but minor spillages do happen.

User Interface

per player

  • digits (8)-
    • h:mm:ss time indicates what time is available – flashes when the player with “0:00:00” is out of time, when everything else stops.
    • n : time periods available
    • nn : number of “moves to play” in the current time period
  • leds
    • “your move” – flashes quickly when “running out of time warning”
  • buttons
    • “I’ve just moved”
    • “give opponent extra time” (on system unit)

shared

  • buttons
    • “+”
    • “-“
    • “mode”
    • “pause/start game”
  • power on/off switch
  • power on LED

Total of 16 digits, 3 LEDs, 8 buttons.

design

design2

I think the “switch boxes” need to be optional. The”I’ve just moved” button and “your move” LED also need to be on the main unit. I could see those wires getting in the way sometimes, or too bulky to deploy in some cases.

Hardware design decisions

LED Segment Control

Maxim 7219 with common cathode 7-segment LEDs. See the articles on the Arduino playground. I have two 7219s and twenty LED digits already in my bits box, as I over-ordered when I built my last timer-based project, so will probably follow this approach for the 16 digits, but may need another IC for the 10 separate LEDs.

Other approaches I could have used :

  • BCD-to-7segment decoder chip (74LS48) plus a 1-to-8 decoder (74LS138).
  • A bank of 4026’s.

Thanks to Russ from SoutHACKton for the last two suggestions. I’ll need to start reading about these chips…

or

I read up on these, but as I had the 7219’s I’ll try them one of those options for my next project I think.

“switch box” design

To cater for the “spill-resistant”, a “gland” is needed where a wire feeds into the “switch box”.

The switch needs +5 and a return wire which can be detected in the “main box” and the LED needs a switchable +5 for the LED, a LED resistor, and GND. That’s a total of 4 wires, so some telephone or ethernet cable should do the trick.

I am using two die-cast aluminium boxes to house the switch + led, probably bigger than I need, but big enough to be really stable when struck by a player.

The LED will be beneath a hole in the casing. The gap between the case and the LED is sealed with PVA/wood glue, which dries clear, is waterproof, and helps keep the LED in place. It has to be flush with the outside of the case, so it can’t be “pushed in”.

“Main box” design

The “main box” needs 3 things really. Two LED segment display boards, and a “brain” board, on which the 7219s and ATMega168 are mounted. The “display boards” need 8 segment lines, + 8 digit lines = 16 lines coming from teh “brain board”.

Connecting the three boards together will be a pain. They need to be detatchable so that I can take it appart to fix dodgy soldering during the debug process…etc.

See images below for how this was done.

Which Arduino to use inside the box ?

So far, I’ve only used arduinos in my projects, so sticking with that platform seems like a good idea. However… I saw this article :Stripduino – Arduino on a stripboard, and thought that it looked fun creating my own arduino board from components, then I get to lay them out on a board myself, and perhaps learn more in the process.

So I did as Icecreamterror suggested, and ordered the parts I didn’t already have from BitsBox.

I also ordered an AVR programmer, Ok, so it’s not within-budget, but I’ll be able to burn my own boot loaders from now on too, and do on-board re-flashing. That’s if I can figure out how to use it.

The Amtel ATMega168 chip arrived, with a load of other bits, and I laid them all out on my breadboard (thanks to the Icecreamterror adding schematics to his article). Transferring that to a board, and using the fact that the ATMega168 is on the same board as the 7219 chips seems ideal

Connecting my ATMega168 on the breadboard to my AVR-ISP500 programmer

Once the parts were on the breadboard, I hit the next problem : How do I put a program onto the ATMega chip ?

Answer : Wait for the arrival of my AVR-ISP500, from Olimex. It’s one of the cheaper programmers (circa £26), but it does support chip-recovery (apparently) if I mess up the chips fuse settings, and block myself out.

Then I had the problem of how to connect the programmer to the Amtel chip on a breadboard.

read about it in a small article here

img_2079

Incidentally, here’s the incantation I used to flash the program onto the ATMega168 chip…

~/projects/sketchbook/GoClockV3/applet$ /opt/arduino/hardware/tools/avrdude
-c stk500v2 -P/dev/ttyACM0 -C /opt/arduino/hardware/tools/avrdude.conf
GoClockV3-sketch-p m168 -U flash:w:GoClockV3.cpp.hex

ATMega168 timing clock running slow

Burning a program onto the 168 was easy once I gave up with the Arduino IDE.

I compile the sketch, then try to deploy it (which fails) then use the program “hex” file in the sketchbook/<sketchName>/applet folder which gets left behind with an incantation to invoke avrdude directly. I’m not using a boot-loader, as I don’t have any serial-programmer on the stripped-down breadboard layout.

Brilliant ! I’ve got it working, but… the chip is running really slow, about 1/15th of real-time. When I said delay(1000) in a sketch, the program delayed for 15 seconds instead of the one second I expected. I knew something was up….

Further reading reveals that the 168 has an internal crystal running at 8MHz, but also a fust bit which divides the clock by 8 to bring it down to 1MHz. So that’s what my program was seeing.

Knowing this it was then only a metter of burning hfuse:0xDF and lfuse:0xFF values to get the 168 to use the external crystal.

So now the 168 on my breadboard is able to run programs, I can transfer it to stripboard and solder…

img_2082

A display board…

Plans, front (top) view of the right panel, copper-side view of the left panel. Labels which are the same are connected with wire.

img_2129img_2131

img_2087

Figuring out a way to connect the display boards to the processor board…

Using a line of header pins which will slot in, and suspend the processor board.

img_2081

img_2070

Paint the LED digits, so they are as black as I can get them. They are less conspicuous that way.

For the wire, I’m using 0.19cm guage “pencil wire”. See http://www.rrunner.co.uk/wire/bobbins.htm

it’s covered in an enamel coating, which burns when in contact with solder… so connecting all the ‘a’ segments of all the digits is just a matter of threading them all together, then holding the wire in-place with the solder. Easy-peasy. Point-to-point soldering.

I used acrylic paint for this. Matt black.

img_2086

With a bit of foam, cut-out the LED shape, so I can hide the wires and resistors which would otherwise show…

img_2088

Bolt the two display boards to the front panel…

img_2090

The processor board will lie across both displayboards.

img_2089

Looking good so far… though one of the display boards isn’t finished.

Connect the strip-duino onto the header pins, so that it hangs off the display panels.

img_2091

The case

img_2076

img_2074

The wires in the case are connected to a really narrow piece of strip board. It’s function is just to connect to a row of header pins.

img_2181

These pins slot into the processor board to provide power, switches, and LEDs.

img_2180

img_2182

img_2184

Software

The trick I discovered via some forums was that there is a “right-arrow” icon in a box on the Arduino IDE. Use it and you get a new tab, which you can #include into your main program. This is pretty convenient if you want to keep structures separate from implementation code.

17thNov: Nearly complete. I’ve added a pause button, and 2 configuration buttons, and changed the original buttons (the metal ones were too hard to press).

I’m not done completely yet, but here is the code so far :

go_clock_sketch_v5

 

 

 

Advertisements
This entry was posted in Electronics and tagged , , , , , . Bookmark the permalink.

2 Responses to GameClockDuino : Game timer

  1. angel says:

    hello, im very amazed with your digital chess clock. that’s a count down timer right? where can i find a schematic diagram of that? i have to make one because it is our project in our logics class. thanks and God bless!

  2. Other approaches I could have used :

    BCD-to-7segment decoder chip (74LS48) plus a 1-to-8 decoder (74LS138).
    If possible would you please share with me the tutorial of game Clock implementation using the above two chips?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s