Lots of LEDS – now I get it!

This is the page that allowed me my “Eureka” moment on how to drive a large number of outputs from a very few number of pins.  If you ever wished you could have 10 or a 100 more output pins – the shift register chips are ones to consider.  I won’t blabber on just follow the link watch the video and you know where to start if it can be applied to your own effort.

http://bildr.org/2011/02/74hc595/ 

Enjoy

Stock Bot – about the 4511 BCD to 7-segment decoder

Not to be trite but you may learn more here wikipedia.org, than here.  This post is intended to fill in some of the background of how the 4511 chip was used in the Stock Bot project.  Let’s dive in and see if it remains coherent.  The chip is designed (I presume) to enable one to use fewer data lines to drive a 7-segment display.  LED displays are common while the one in Stock Bot is a little less so.  A seven segment display has 7 inputs one for each light element.  You would need 7 data lines to drive a single digit and much more to drive additional digits.  This project does not use the data latching features that enables several 4511 chips to drive several digits while keeping the data line count to a minimum.  When you scale the number of digits you really save on data lines and the value of the chip becomes evident quickly.  To be brief, several digits can be managed (like a clock) by locking the currently displayed value into each chip and then unlocking only one digit at a time to effect a change to that digit.  Quickly locking and moving on, unlocking change lock, continue.  If that made any sense you got the idea.  Do this fast enough and large multi-digit displays can be managed – again with 4 data lines and the latch control logic.

Driving the single chip was a fun code experiment.  So let’s look at that.  Like I said on the Stock Bot page I had to learn (re-learn/hack in) C# for this.  When you drive the chip you are essentially sending it a binary code along 4 digital lines.  A 4 line data bus I guess.  Given an integer from 0 to 9 convert, that to binary or otherwise figure out how to set your 4 data pins correctly.

A set of if statements would do that.  A switch statement would do that.  Both I tried as I had to get something started.  Neither felt clean enough to me (don’t get me wrong some of the code is still too ugly to even tell you about yet/ever).  So I worked out what I have below because I knew in my mind something cleaner should exist.  Your improvements are welcome as comments.

    // helper class
    class BCDOutputClass
    {
        byte mask1 = 1;
        byte mask2 = 2;
        byte mask3 = 4;
        byte mask4 = 8;

        OutputPort Bin1 = new OutputPort(Pins.GPIO_PIN_D9, true);   // A
        OutputPort Bin2 = new OutputPort(Pins.GPIO_PIN_D12, true);  // B
        OutputPort Bin3 = new OutputPort(Pins.GPIO_PIN_D11, true);  // C
        OutputPort Bin4 = new OutputPort(Pins.GPIO_PIN_D10, true);  // D
        OutputPort CommaPin = new OutputPort(Pins.GPIO_PIN_D13, false);

        // Constructor
        public BCDOutputClass()
        {
            //
        }

        // Instance Method
        public void Display(byte a)
        {
            a = (a < 10)? a : (byte) 10;
            Bin1.Write((a & mask1) > 0);
            Bin2.Write((a & mask2) > 0);
            Bin3.Write((a & mask3) > 0);
            Bin4.Write((a & mask4) > 0);
        }

        public void Clear()
        {
            Display(10);
            Comma(false);
        }

        public void Comma(bool a)
        {
            CommaPin.Write(a);
        }

        // Destructor
        ~BCDOutputClass()
        {
            // Some resource cleanup routines
        }
    }

Most of this becomes clear if I just talk about the meat of the code in public void Display(byte a).  Maybe not but let’s start there as it is the crux of what makes this (IMHO) better over an if or switch statement.  I have, of course, not tried to figure out if this compiles to smaller code or not – that’s not a concern I have any interest in yet.

The function takes in a byte – the code when running sends in the values zero to 10 when all is normal.  10 is an exception and I should explain that first as the line first executed is a test for values over 10 and if over we revert a to 10. 10 in binary is 1 0 1 0.  Setting the 4 pin data bus to an invalid value.  1 0 1 x (where x means it’s not important) happens to BLANK the display.  This makes the code in the function public void Clear() fairly obvious now why it sends a 10 to Display().

The 4 pins how do they get set?  ok, let us use the digit 9 and now step through the rest of the function.  Pin 9 on the Netduino is connected to A or D0 on the 4511, the lowest order bit (ones). 12 is to B or the twos, 11 is to C or the fours and pin 10 to D the highest order bit the eights.  You can look to the mask declarations to get a feel for the positions too.

9 is binary 1 0 0 1

We need to set line A to true, line B to false, line C to false and line D to true.

(a & mask) what does that do?  “a” is type byte and mask1 is of type byte.  The & says do a bitwise AND of the two values.  What’s a bitwise and – (for now – Google it) but I’ll do the math here and might get it across.

1 0 0 1  (9)
0 0 0 1  (mask1)
-------  bitwise and says 1 only when all are one
0 0 0 1 (1)
Result = 1

1 0 0 1  (9)
0 0 1 0  (mask2)
-------  bitwise and says 1 only when all are one
0 0 0 0 (0)
Result = 0

1 0 0 1  (9)
0 1 0 0  (mask3)
-------  bitwise and says 1 only when all are one
0 0 0 0 (0)
Result = 0

1 0 0 1  (9)
1 0 0 0  (mask4)
-------  bitwise and says 1 only when all are one
1 0 0 0 (8)
Result = 8

Let’s take the results of the first operation.  We got a 1.  There’s more in that line of code (a & mask1) > 0

Greater than zero completes a comparison.  Results in a boolean.  True or False.  The first part will result in a zero when we need a false result and a true value when the result is anything else 1 or above.  In the case, we just ran through, we had a 1 and an 8, both greater than zero, and so had two lines (the first and last) set to true.

By now you’ve either gone Aha! or Duh or are scratching your head.  Either way I am done for now 🙂 enjoy.

Now learn that fun math

Not much to say here.  Just DO IT! http://www.khanacademy.org/ is a wonderful site. If you have a passion for learning or re-learning you will want to bookmark the site. I reconfirmed my ability to add and subtract 🙂 I am going to do every math lesson until I top out (maybe at division).

Free learning – if you have kids – create accounts now. This will help every kid and you’ll be sorry if you don’t also sign up like I have and sharpen your skills.

http://www.khanacademy.org/

Math is fun, yes indeed.

I love to listen to these guys chat, Leo and Steve.  Recently I needed to get a friend up to speed on a secure key exchange. Not the simplest topic on the roster.  Just how do we share a secret over the Internet?  While we know others are watching and intercepting our communications.  We do it with math.  Math, when used like this, forces you to want to learn even more math.  Really, math is fun and you will be smart if you learn math.

The first 15 minutes of this podcast prove to me that the more math you can take in the better off you will be in life.

http://media.grc.com/sn/SN-034.mp3 100% relevant regardless of when it was recorded.

Who did not see thing one comming? Verified by…

Visa and others.  The first time the page came up “verified by Visa” you said “cool this is a very good thing Visa is making the web safer”.  If you thought that you can now go to the back of the class.  You should have been thinking what sort of phishing scam is this?  Where is the URL bar for this popup and why would I sign up for this service from this little dialog on some site?  Does Visa even have a website?  Does my bank know about this?

Now for those of you at the back of the class, the zbot botnet has been augmented to shoot phish in a barrel.  You are the phish, unfortunately.  Thank you, Visa for the swimming lessons (NOT).

Click to read more news on the zbot botnet and how it is mimicking the Verified by screens.

http://www.sans.org/newsletters/newsbites/newsbites.php?vol=12&issue=56#sID301

iPad now in my hands – loving it so far.

Working from the iPad today. Not bad. I can find a way to hold it that works well in most positions. Far better than a laptop in every couch position. For the types of tasks I imagine the iPad to do well with – it is great at home so far. Email and web – and the all important links in email to web – these tasks are very easy to manage on the iPad. Nice big screen the screen rotation lock is a great addition. Watching the last 12 hours of an eBay auction also easy to do. Migrating from an iPhone to this iPad is not going to be difficult.

Apple may have in fact sold a competing product to the iPhone. For those of us that find the size ok to have with us all the time why would an iPhone be required? A simple voice only phone will now probably suffice. I guess it all comes down to how do you want to balance your freedom. By freedom I mean, to which piper will you pay for voice and data plans. iPad is another choice. It’s 3G appears not to be locked to a provider offering even more choice. In fact fostering actual competition once the different vendors see the need to acquire these new customers with unlocked devices. Not free but a new unlocked freedom may bring a breath of fresh air to the Canadian wireless market if nothing else.

I’ll be looking for a pay as you go SIM on a USA plan when I next visit the states. To prove this device is 1) not locked and 2) I do indeed have this new freedom. In fact over the next few months I’ll try to have a month to month plan with Rogers, Telus and Bell and thus exercise my new freedom. At the very least I plan to watch how the plans settle in. Once they all become contracts for longer periods and start to look like current cell contracts, then I’ll give up my hope for freedom. Here’s to that never happening and a real competitive landscape forming instead.

I do like the iPad 3G in Canada. I have high hopes for it to make a difference in how people work and play. It will make a difference in mine, the month to month data plan already has.

One reason some will like the new iPad

I am a big fan of Cisco coming down to earth where we can all interact with the technology they produce.  One very powerful tool they have bought and extended is WebEx.  There are not too many in the remote desktop space with the breadth of WebEx.

I see that one of the new iPad applications is a WebEx client.  That’s a perfect personal format to watch a presentation.  On the iPhone the technology was only cool – as the screen was honestly too small.

iPad will rock this application.

McYork is inspired every time we come across one of these “fit to form” applications.

Questions your new phone should be smart enough to to answer

These are practical questions, right?

  • Where was I @ 3:00 PM yesterday?
    • And on Tuesday?
    • How far apart are those?

My calendar is not the source of this information, augmenting it perhaps but the answer really should be an historical GPS location log converted to an address – looked up in contacts and calendar for additional context at the minimum.  Additional follow on questions should be default behaviour, does your phone follow along with the context and answers of your prior questions. That’d be nice.

  • How many miles did I drive last week?
    • And the week before?

C’mon you know when I am in a car (accelerometer data), you gotta!  Was I the driver – perhaps a difficult question to answer.

  • Did I take the Bus in February?
    • What Bus?

Right.  Maybe I take the bus infrequently and only once I recall in February. It went 6 stops and only 2 busses take that route.  I had googled bus routes and found the #314.  Perhaps the #314 was the bus I took as it is one of the 2 busses that have those stops.

  • When I last rode my bike how far did I go?
    • How many stops did I make?
    • Did I stop for lunch?

Coffee Shop Login 1.7 now on-line

This version will now properly bypass the Bell iPhone prompt for your Bell phone number. We don’t have a Bell phone and suspect most of you also don’t (yet). We now detect this annoying page and move on to the normal login page. iTouch users will not have seen this issue because it looks like Bell is able to tell the difference between a phone and a touch.

If anyone with a Bell iPhone can tell us what happens (how the login proceeds and if it remembers you next time) we’d like to try an enhancement so you can use this app too (if/when you switch from Rogers).

Get the new version now in the app store by checking for updates.  Buy it now if you don’t have it http://go.mcyork.com/coffee (opens iTunes).