Craziest Pin-Saving LCD Trick Ever!

We love squeezing every last bit of silicon goodness out of a tiny chip, or at least we delight in seeing it done. Today’s analog/digital hack is one of the sweetest we’ve seen in a while. And it’s also a little bit of a puzzle, so don’t scroll down to the answer until you’ve given the schematic a good think-over.

[Claudio Larios] built a tachometer with LCD display, using only an eight pin PIC microcontroller for brains. (Translatrix.) Two pins are taken up by the power supply and one reads a Hall sensor, leaving only three pins to drive an LCD display which needs six signals. The problem to be solved is the fundamental mathematical issue that three is less than six. Now have a look at the schematic.

If you’ve not played with the Hitachi HD44780 LCD controller before, it has four-bit and eight-bit data modes. In four-bit, used here, you only need to send data on D4, D5, D6, and D7. RS selects between command and data mode, and E is the clock signal that latches the data in on a falling edge. Mull that over a bit before reading the next paragraph.


What [Claudio] is doing is essentially using the 10 nF capacitors as little memories! (Look into DRAM if this analogy seems a stretch to you.)

In a first pass, the PIC’s pins are set high or low for a longish period of time (500 microseconds), long enough to charge or discharge the capacitors through the 10K resistors. In a second pass, the values for D5 and D7 are set, and the E line is strobed up and down almost immediately to latch in the values on the no-capacitor lines.

The second pass happens so quickly that the capacitors can’t charge or discharge fully and RS, D4, and D6 read in whatever logic value was set during the first pass. Brilliant! (Oh yeah, this project was about a tachometer. We got distracted by the shiny pin-stretching tricks. We’re sure it’s a fine tachometer.) Did you see how he pulled that off with only three pins?! And no shift register?!?

HaD reader [danjovic] sent us the tip and did a little work on the code, verified that the technique worked, and provided the banner photos of his recreation. Many, many thanks!

93 thoughts on “Craziest Pin-Saving LCD Trick Ever!

    1. What happens if your touchscreen is slightly off or forgets calibration when ordering the 16 pin one and it clicks order for the eight pin package?
      Or you type your keyboard faster than you can think and press tab and enter a few too many times?

      Might as well make the most of what you got I’d say.

    2. On the other side:
      – If you got 10 8-pin micros and 2 16-pin micros at hand and the brainpower to pull things like this off, there’s nothing stopping you.
      – Availability – our local shop has plenty of ATtiny85 but no 84, and wherever the 84 can be bought, the price is unreasonable.
      – All those ATTiny85 development boards with bitbanging USB are hella cheap.
      – If you’re trying to shave off as much of your BOM as possible, you might want this trick and a couple more.

      I’d just put a shift register though, but I can imagine not having one at hand and it’s likely to happen in certain circumstances.

      1. space saving and part counts I don’t think so, r/c is two extra parts per pin and you have to tie them to a supply.
        ‘local shop’ I can’t imagine being able to go to a local shop and buy components. must be great!

        1. Well, 6 extra parts per pin vs shift register. Depends on what’s cheaper to add to the board – there might be the case of already having same caps and resistors on the board, so it won’t cost more in terms of assembly =) It’s not such a big deal, of course, just a case that’s rare enough to appear.

          Yeah, then there’s also lack of shops in certain areas, or weekends/holidays when you just want to finish that damn project and every bit of ingenuity counts.

          Also, the board layout and code seems simpler compared to the shift register approach. That’s an advantage in my book =)

        2. this is why I am my own local shop. IC’s are cheap and storage is easy so I buy gobs of common chips every time I have a little extra cash. Ali Express and Jameco are your friends….

        1. The winning move is to take the comments as humor. Everyone knows that humor and laughter have to do with an interrupted defence mechanism. So humor keeps your emotions in check. And you learn the most when your emotions are calm.

          See how the comments actually make you smarter?

      1. If there’s absolutely no thing to complain about, there’s no point in commenting in the first place. The very definition of inane is an online comment board full of “Kudos!” or “Awesome you rock!”. If it’s really that good, give the guy a dollar or something.

        A cat lives on praise, a dog by pats on the head.
        -old proverb

          1. Naturally. If there’s nothing to say, then don’t say it. If there is, then say.

            Should one a man of wisdom meet
            who points out faults and gives reproof,
            who lays a hidden treasure bare,
            with such a sage should one consort.
            Consorting so is one enriched
            and never in decline.

            Let him exhort, let him instruct,
            and check one from abasement.
            Dear indeed is he to the true,
            not dear is he to the false.


    3. And how do you proceed if you are in the middle of the Sahara desert at an 8 million dollars oil drilling rig which is about to explode, and you have only five minutes and an 8-pin microcontroller available to build the safety controller which should trigger the hole seal procedure? You tell the supervisors and the investors you have to buy a 16-pin part? Or you carry on with whatever you have available, fix the damn thing, save the day and get your pockets filled with $$$?
      Congratulations for this hack.
      This is brilliant.

        1. Nope… even in my dreams I did not ran a TV show. You don’t have time to do such things if you live in Eastern Europe. But I’ve been in that scorching hot place as a maintenance/automation engineer. It was the closest place from Hell where human hearts were still beating. And I’ve been through all sorts of weird situations where experience – and most important – were extremely helpful.

    4. Maybe, like me, he doesnt have the money to go buy a new part and has to work with what he can find cheap/free?

      Things are changing for me and I can now start buying parts, but when I have needed a part, and couldnt buy it I had to go find it, or find something that I could “bend” to do the job. You can be critical sure, but in this case it just comes off as smug. Remember some of us lack the financial resources that so many people take for granted.

      1. woah lots of angry people here huh? I never said he was a dickhead for doing it or anything, i’m not trying to have a go.
        david I’m in your boat, I can’t afford to buy a handful of neopixel rings and keep them in my junkbox just because they look cool.
        all I’m trying to do is let people know that just because the 8 pin is half the size doesn’t mean its half the price, and even though these r/c parts cost fractions of pennies it adds to the cost and complexity.
        doing something interesting like this is great and you should relish the opportunity if it presents itself. I’m not saying its not.

    1. He’s probably not using the programming data and clock pins. It would definitely save development time. Also I seem to remember on the 8-pin PICs that there is usually one that’ll only do input.

    1. I was wondering the same thing, but at what point do all the additional components required to hack the system exceed just plopping down a shift register?

      I actually do like this hack. Not only is it a fun thing to just play with, but you can argue that you can reduce your BOM cost in this instance. But that only goes so far before you’re actually costing more to hack it :)

    1. It’s only a small text display. If it does go wrong, you get a bad character, til the next time it’s refreshed, not life or death. As long as he uses a long enough charge / discharge time, and the LCD is quick to sample the pins, should work fine. It’s a smart idea!

    1. nciswatch,

      I thought of this EDN article too, but we should give the author his due.

      While he may be using the same technique as described in that EDN article to strobe the E & RS lines using only one output pin, the technique he describes to setup D4-D7 using only two output pins is not the same as that EDN artlcle,

      I’ve read a dozen or so posts about how to drive LCDs and this technique is something I have not seen described anywhere else. Kudos to the author for coming up with this clever hack.

  1. Add aging and temperature, and this neat trick goes kaboom.

    Circuits like these tend to fail when you need them the most, and expect it the least.

    There’s a reason why we ditched RC circuits and now use counters everywhere.

    Ok, I may be a little bit biased, because I have to design electronics that works from -40 to +125°C, over 20 years.

    1. However, aging and temperature variation is solvable too. If you can switch the output back to an input you can calibrate the charge/discharge characteristics occasionally. That would also be advisable with [meme]’s suggestion of multi level, but then you’d probably need an ADC input.

    2. As long as the time constant is many times longer than required, variations in the R and C shouldn’t keep it from working. Most circuits don’t have the luxury of being able to build in a 100x safety margin.

      1. Yup. It’s a bizarre capacitor or resistor that goes off by a factor of 10 with age or temperature. You can build in as much margin as you want in the software. Since it’s just sending a few bytes to the LCD, there’s no great hurry. Seems pretty foolproof to me. Eventually the heat death of the Universe will stop all circuits working, but til then there’s plenty of decades old circuits still doing their job, solid disc capacitors and ordinary resistors don’t change that much. If ancient TVs can still work, this simple little hack will.

    3. So, develop yourself a LCD that works at 125.C . It’s not a new standard, just an approach that might comes in hand sometimes (i.e.DIY projects). Don’t worry, NASA is not going to use this!

      1. To be honest, I have Roman Blacks site bookmarked for years, as it has some neat tricks. I saw that Shift1 system a long time ago AND I use 1-wire devices regularly, and I never made the connection. But it really looks very similar. Thanks for the observation!

  2. Wonder if this could be used to run a clock along side data over a single wire into a shift register?

    Sounds like another back of the drawer experiment waiting to happen…

    I’m thinking along the lines of a single parity/enable (logic high) bit tacked on the end of the (byte long) packet so when the buffer is full the parity/enable bit triggers a send-parallel and clear by switching such circuits on. Could be an 8th bit or 9th bit (byte+logic high).

    1. I did something along those lines in college. I used two 5 bit shift registers, and the first bit shifted in must always be a 1, the second bit is the command/data line, and the rest are the 8 parallel pins. the leading 1 bit would trigger an RC circuit at the end of the chain that would trigger the LCD to read the 9 input pins, and then clear the shift registers.

      1. I honestly skipped reading the article and went directly to complain in the comments (click on coment link from the blog). In this day and age of fake news and ads disguised as news one can’t afford to click a baited headline.

        1. I agree. Can’t stand watching all that trash on CNN in this day and age.
          Title was mildly clickbaity, but it’s Hackaday… I know they’ll at least have content on the other side of the link.

      2. Actually yes, because my brain automatically disregards clickbait-style titles as trash, which gets subconsciously ignored.

        Always err to the safe side when it’s a choice between ‘attention grabbing’ and ‘actually factual’ in these modern tabloid times.

        I actually only reluctantly clicked the “comments” link due to the amount of comments displayed, just to see how people would tear the title to shreds.

  3. Clever trick! I can’t get these envy guys trying to find drawbacks, I guess they do this to justify the fact they didn’t have the same idea before. When you have your own clever idea you won’t need to act like this. Einstein is criticized until nowadays for some envy smartasses that are unable to do any better. Shame on you…

  4. Kind of an analog shift register.

    Th author of the article hasn’t been taught Obama-core math though or they would know this is clearly wrong: “The problem to be solved is the fundamental mathematical issue that three is less than six.”

    I’m having to hire a math tutor for me daughter because I can’t figure out why 3 is no longer less than 6 either.

  5. That’s ingenious!! I have myself used the same trick before to gain one pin but as many others here I have then stopped after that and never thought about pushing this idea farther. That’s why I got amazed and shocked at the first sight of this circuit and I couldn’t help but assembling this circuit to see it working and probe it with my own scope!

  6. I read a comment here complaining about the two extra parts per pin.

    Considering that the addition of an RC filter per every pin is necessary for an EMI robust design in any case, this is no extra parts count at all.

    You could argue about the minimum necessary signal riste time in case the display has a CMOS input stage without Schmitt-Trigger inputs.

  7. analog memory, let me see
    1) can be made at home without needing any memory chip to speak of…
    2) works for situations like this and solves a problem
    3) allows you to hack a board that does not have room for a shifter
    4) pisses off everyone that thinks this is an unacceptable use of spare time because you could just buy a bag of 1000 shifter ICs for pennies each, yeh, and i could also buy a bag of… but not everyone buys stuff online or lives in shenzen or near an abandoned electronics lab from the 80’s

    it’s a win in my book!

    1. and the comment of being able to add-in 100x margin of error is spot-on, there’s no way a 10nF cap will be down to less then 1nF in less then 50 years unless the board has water-damage, in which case ALL components will degrade much faster.

      and even then, the code can always be adjusted to use 500x margin and you still will not notice any speed hit; unless your using a “substance” (or a mix) to temporarily slightly enhance your retinal update speed. this may cause counter after-effects and addiction.

  8. I looked for the term multiplexing in these comments but didn’t find it used anywhere. This RC time constant multiplexing scheme is a brilliant hack IMHO. Intel used multiplexing on the 1101 DRAM chip for the address lines because of similar pin constraints but used the full voltage swing to the ground and positive rails. In fact an excessive RC time delay was/would have been disastrous in that environment. This trick however, requires, that digital intelligence exists on both ends of the bus for the clocking in of the multiplexed data information delayed by the RC time constant and that makes it a great idea. Music has been sent serially over a single line and reassembled at the point of use especially in commercial airplanes to also save weight in the fuselage and I’m sure there are many other applications for saving pins that would be achieved by using this trick. But the RC time constant would only be effective when the bus length is short enough so that the wires don’t introduce enough of its own resistance and capacitance to affect the engineered RC time constant…

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.