A PIC powered pair of electronic dice

[Timothy] is honing his microcontroller skills with this electronic dice project. In addition to giving him an opportunity to work on some code, the use of an 8-pin chip provides a design challenge for driving the twelve pips and providing a user input.

The project started off with some $4 strings of LED Christmas lights. He promptly disassembled the strands, each yielding 100 LEDs. The microcontroller he chose to work with is a PIC 12F629. It’s DIP8 package provides six I/O pins to work with. When examined closely you will find that the pips on a die are always present in pairs with the exception of the center pip. This means that only four pins are needed to drive one die. You can see a pair of transistors above; one is a PNP, the other an NPN. These are both driven from the same uC line, which toggles between the pair of die. This accounts for 5 of the available pins, with the sixth monitoring the push button.

Comments

  1. I like projects that use 8-pin chips. They always look so neat.

    Few suggestions:
    1. RA3 has internal pullup option and does not need an external pullup
    2. 7 + 7 = 14 LEDs, drivable via charliplexing using 5 pins. This configuration would avoid the need for external transistors and resistors (max duty cucle will be small, and current is limited by PIC’s IO pins)

    • Erik Johnson says:

      To the *plxing; you lose the brightness going this route.

      • Compared to the current route?

      • Erik Johnson says:

        Exactly. Current one plexes 2 elements, charlie plexes 14 elements, or 7x dimmer

      • Nova says:

        Not necessarily true, when charlie-plexing you can push higher currents through the leds to help make up for the difference in time spent off.

        Almost all LED’s have an extra rating called pulse-current which usually specifies the duty cycle as well.

      • SavannahLion says:

        Besides pushing higher currents, the trade offs includes excluding the resistors (reducing parts count), increased wiring complexity and increased programming complexity.

        It’s the last two that can cause problems. If I feel like being slick and use Charlieplexing in a project, I have to keep careful track of any changes in the wiring and write copious notes in my routines because six months later I’ll come back and go, “WTF was I thinking?”

        To figure it out in the shortest amount of time usually involves copious amounts of caffeine, alcohol, or mind altering drugs or some combination of the three.

        My body can only take so much abuse.

      • timothyscarlson says:

        @SavannahLion:

        I know what you mean about your body being abused. Mine’s been through the wringer – I’m surprised I can still do what I do.

        As far as “WTH” feeling when going through old projects – I have had that before, even to the point of vocally criticizing code (and the programmer) to my colleagues, only to stumble across _my_ initials in the code. Oy!

        I am currently reworking one of my first projects that I worked on after my strokes, a remote-controlled AC outlet. Besides being really ugly – my soldering skills weren’t quite back to snuff yet – it wasn’t put together well. I plan to use it for my Christmas lights on the office patio, just point the remote through the window and turn the lights on and off.

        BTW: Thanks everyone for the comments, and thanks to Hack-A-Day for posting my project!

    • timothyscarlson says:

      RA3 does not have a weak pull-up. Per the spec:

      3.2.1 Each of the GPIO pins, except GP3, has a individually configurable weak internal pull-up.

      So the 10k pull-up I included in the design is required. I tried it without the 10K pull-up, with the /GPPU bit in the CONFIG register set to both ‘1’ and ‘0’, and – it doesn’t work. Either it sees the button as always pressed, or there are spurious glitches on the line. And the ‘roll dice’ button doesn’t work.

      As to the charlie-plexing – I could put RA2 on the anodes of one set of LEDs and the cathodes of the other set and then use that to select the die face. I’ll try that out on my next board. I’m making Christmas presents – heh – so there will be quite a few made.

      Most of the resistors are on this board because I have to connect the PICKIT2 dongle to it for in-situ programming. When I get to the ‘production’ versions – IE: the ones I will use for gifts – the PICs will be pre-programmed and I won’t need the ISP header, socket and most of the resistors. If the charlie-plexing works, that will _really_ reduce the part count.

      Thanks for the ideas!

  2. dattaway2 says:

    These are the kind of hacks I love. Few pins, minimal parts, yet lots of I/O.

  3. Alex Rossie says:

    Repost for starters also this is a ridiculously old in terms of hacks.

    By that I mean using an 8 pin microchip PICs to control 14 LEDs to create 2 dice.

    Granted not using a 12F508( cost 58p per 1) but the 12F629(cost 1.08 per unit)…

    It’s been on this site at least once before and is also in this famous PIC introductionary book http://www.amazon.co.uk/PIC-Microcontroller-Personal-Introductory-Course/dp/0750666641

    • timothyscarlson says:

      I used the PIC 12F629 because it was what I had, other than a PIC 12F1840 which really would have been overkill. I like the 12F629 as it is versatile for a lot of different projects. Plus a little faster (8mhz), which allows me to do bit-banging I2C at around 80Khz.

      I haven’t seen the other die projects out there – I previously did a single die version, which display two die values on one die by ‘flashing’ between the values. I guess the evolution of projects that use an I/O limited micro seem to follow similar paths.

      I used to be a hw/sw engineer for various startups and larger companies – but have since been sidelined by 4 brain stem strokes. I can’t do fine soldering anymore, so I stick with through-hole components and DIP ICs instead of surface mount. I mostly just do these type of projects to keep my skills honed and not go stir-crazy in my forced retirement.

      The most important thing to me is I have fun doing these projects – some small (like this) and some big. Can’t work anymore, so I might as well hack!

  4. andar_b says:

    “pair of dice” or “toggles to the opposite die”

    Very clean looking project though. :)

  5. Circuitmage says:

    Next Project: Dodecahedron capable Bag-O-Dice in one.

    ?????

  6. timothyscarlson says:

    I’ve posted the code, if anyone is interested.

  7. spiralbrain says:

    Cool, how about adding a shake sensor to this:

    http://www.electrodragon.com/?product=vibration-switch-sensor-sw-18020p

  8. Anonymous says:

    For you mikroC fans out there..
    http://pastie.org/5127139
    It’s for 12f683 (the only available Friday night).
    Tnx Timothy, you saved my weekend.

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

Follow

Get every new post delivered to your Inbox.

Join 91,402 other followers