RA4

RA4 pin

Electronics is hobby of mine. Whenever I feel like relaxing I get myself PIC, some additional hardware and I make a board. This time I wanted to make LCD driver. Not for full-blown graphic LCDs but for small character ones. Yes, I know that there are solutions freely available for that exact purpose but reinventing a wheel is probably most important aspect of a hobby engineering.

As soon as powered whole mess of parts - nothing happened. Fault was easy to locate - it must be in my PIC code. After spending hours simulating in MPLAB (where everything seemed alright) I decided that board must be at fault. Quick test with LED lights showed that my LCD clock line (E) was dead. It took changing PIC chip and half of hardware before I acknowledged defeat and went down standard road - When everything else failes, RTFM.

As soon as I started looking into datasheet I had one of those enlightenment moments and I recalled similar problem I had on one previous board. RA4 pin (and only RA4) I was using is open-drain input on that particular chip. In practical sense it just means that pull-up resistor is needed for it to be of any use as output.

One cent component was all that was needed for LCD to be alive.

This whole experience was quite humbling since I was dealing with PIC I already knew and I thought that re-reading manual was waste of time. Of course Murphy found a way to teach me a lesson.

ClientLogin

Google offers quite rich API for users of their services. Most of it needs some form of authentication. Without much ado here is my C# implementation. Only limitation is lack of captcha support, everything else should be there.

P.S. If you are interested in Google Data API, you might want to check .NET client library. It is open source project and it covers pretty much whole API suite.

So Long, and Thanks for All the Fish

Illustration

It was easy to recognize me on my way to work - I was one reading from small black device. Not anymore.

Worst thing has came to pass - my BeBook mini is broken. From all symptoms I can deduce that inner glass layer has shattered and that there is no revival here. It was in cover, I did handle it gently (ok, at least I handled it with more care than other devices I own) and I did adore it.

What now? Currently I use my mobile phone (HTC Desire) for reading books but that will not last. Once you start using e-Ink, there is no going back to inferior technologies (as far as book reading is concerned). There is no other choice than buying another book reader. Problem is which one.

Since my kids do like to eat occasionally, my choice is limited to devices under $200. And really there are only two devices I consider worth buying in that range. Amazon Kindle and (yet another) BeBook mini. BeBook is devil I know and it did serve me well. I prefer it mostly for it’s small size and huge capacity (with additional SD card). Kindle is big, bulky and has huge keyboard that just gets into way but it also has huge choice of books and you can use it without any computer near.

I will not make decision this week, probably not even next one, but I am quite sure that next spare money goes to this purpose.

In memoriam BeBook mini (Nov 2009 - Jun 2010).

NTP Server

Few days ago I stumbled upon problem. I had three Windows 7 computers without Internet access and I needed time synchronization between them. It wasn’t really important that time is correct - it was important that time is same. Solution was simple - just make one of computers NTP server and let others synchronize to it (using standard Windows time synchronization). While Windows 7 synchronizes time perfectly over Internet and/or when you are member of domain, it does not include NTP server.

As I tried to install some other software it became clear that I need to stop and DISABLE “Windows Time” service. NTP servers can only work if they can use UDP port 123. As long as “Windows Time” service is running that port is taken by it. For my scenario this service does nothing so disabling it caused no problems.

As I tried few NTP server solutions I got more and more desperate - either they weren’t free (yes, I am cheap bastard) or they would not work as service under Windows 7. After some time I just decided to make my own program. How hard can it be?

While I consider most of RFCs technical descriptions pure beauty, somebody made a mess of this one. All information was there, how to synchronize, which algorithms to use, probably even genealogy of authors - only thing not there was pure and simple ASCII format of UDP packet. Fortunately authors of SNTP (which is mostly compatible with NTP) did much better work with it. That combined with old pal WireShark made this program possible.

As any program that is written in one afternoon, this one has fair share of things not done. First of all, this program was only tested with Windows XP and Windows 7 as clients. While other versions should work, I spent no time in actually testing it.

This server is also not fully NTP compliant. All fields are there and all clients will consider it valid time source but stratum, precision, root delay and root dispersion numbers are just hard-coded instead of calculated. This should present no trouble in local network and if precision in seconds is satisfactory, but it is definitely not time server you would use if every microsecond is important.

Program requires .NET 2.0 and there is no setup. When you extract it to desired folder first order of day is performing installation from administrator prompt (cmd with Run as Administrator is fine). There we just run program with /install as parameter (“tempora.exe /install”) and service will be installed and started (if you remembered to DISABLE “Windows Time” service first). As long as you don’t uninstall it (“tempora.exe /uninstall”) it will start at each startup and it will return current time to all it’s clients.

Download is here.

P.S. Do not forget to DISABLE “Windows Time” service. ;)

[2015-04-25: Program is available on GitHub]

IsNullOrWhiteSpace

When one deals with user input, it is quite useful to check whether user entered anything. Definition of “anything” is not necessarily same for developer and user.

Quite often user will consider one accidental space to be nothing at all. To implement proper check developer would need something like this:

if (string.IsNullOrEmpty(text) || (text.Trim().Length == 0)) {
    //Text is empty.
} else {
    //Text is not empty.
}

Code is not difficult and it is pretty obvious. Hard part (at least for me) is remembering to add this text.Trim().Length==0 condition. Some time I just forget.

.NET 4.0 brings little bit of syntactic sugar in this area:

if (string.IsNullOrWhiteSpace(text)) {

It is basically same code - just a little bit shorter and, thanks to IntelliSense, much easier to remember.