Part 2 – Getting started with a 128×64 Graphics LCD Display – Screen resolution and locating pixels

The GLCD has a 128×64 resolution. This equals about 8192 individual pixels that you can control as you wish. But how is this done? Let’s see how we reach a particular pixel on the screen.

The LCD screen is actually divided into 2 halves with one KS0108 IC for each half. Each KS0108 IC has the ability to control 64×64 pixels, so both of them side-by-side should be able to give you the complete resolution of 128×64. So, by choosing which one of the two ICs, you can narrow your pixel down to one of the two halves.

Next, each half containing 64×64 pixels has an addressing scheme using the Y address and X address as follows. Lets start with the columns. Each half has 64 columns numbered from 0 to 63. Straightforward enough, not too much to get confused about, each column is addressed using the Y address which ranges from 0 to 63. Continue reading

Part 1 – Getting started with a 128×64 Graphics LCD Display – JHD12864E (KS0108 family)

The GLCD (Graphics LCD) display that I’ll be using in this series is the JHD12864E. Here’s a picture of what it looks like (image stolen from http://extremeelectronics.co.in):

clip_image001

It’s a fairly standard 128×64 pixels display with a backlight. The part number aside, what really matters is the IC driver that is used in this display. The datasheet shows (more on this in a few mins) that it uses the S6B0108 display driver. After looking around on the net, I realised that this is similar to the KS0108 family display driver. So the general method of operation should be similar to the KS0108 but with a few minor differences here and there. Continue reading

Intro – Getting started with a 128×64 Graphics LCD Display

This is going to be a mini-series on how to get started with a 128×64 LCD display. I’ll be going through all the steps that are involved in getting one of these damned things to work and I’ll post links and references wherever necessary.

“But”, you argue, “why do I need to learn this stuff? I can just whip out my Arduino and use the GLCD library and be just as cool!” Well, definitely. The purpose of doing this is not to be “cool”, but to gain an understanding into how this works and what kinds of problems you may face when working on something like this.

I won’t go too much into the pros and cons of which is a better approach. Obviously, libraries are there for a reason and if you’re using a specific development platform/board (Arduino, EasyPic) or a specific compiler for a certain project (AVR-GCC, MikroC, XC8) and you’re on a deadline and have a fairly straightforward task to accomplish, you should go ahead with that.

On the other hand, if LCD.Write(“Hello, World!”) doesn’t cut it anymore and you want to have complete control on a pixel to pixel basis, and/or be able to churn out your own library for a specific microcontroller that you’re currently using (8051, PIC, AVR, MSP) then you should read these series of posts.

On the whole, I will try to keep this series largely microcontroller agnostic. You should be able to read whatever is given here and transfer the learning to any microcontroller or development platform with a small amount of effort.

But for the sake of demonstration, I will be using a PIC16F886 microcontroller here. I have used both AVR and PIC and they’re both excellent microcontrollers in terms of performance, price and availability. But I’m going with a PIC here because I’m trying to learn more about these microcontrollers.

Here’s the table of contents. I will keep updating the links as I push content out:

  1. Intro – Getting started with a 128×64 Graphics LCD Display
  2. Part 1 – Getting started with a 128×64 Graphics LCD Display – JHD12864E (KS0108 family)
  3. Part 2 – Getting started with a 128×64 Graphics LCD Display – Screen resolution and locating pixels
  4. Part 3 – Getting started with a 128×64 Graphics LCD Display – Passing instructions
  5. Part 4 – Getting started with a 128×64 Graphics LCD Display – Pin configuration
  6. Part 5 – Getting started with a 128×64 Graphics LCD Display – Putting it together
  7. Part 6 – Getting started with a 128×64 Graphics LCD Display – Hello World!
  8. Part 7 – Getting started with a 128×64 Graphics LCD Display – Porting a bitmap to the GLCD
  9. Part 8 – Getting started with a 128×64 Graphics LCD Display – Fonts! Fonts! Fonts!
  10. Part 9 – Getting started with a 128×64 Graphics LCD Display – Pitfalls, debugging and troubleshooting

Android and Arduino Serial Bluetooth App – BlueSerial

I’ve finally been able to figure out the entire Bluetooth API of Android and I felt it was more difficult than writing Arduino code in Assembly. In it’s current avatar, I think it’s ready for a Beta release. Based on the feedback I receive, I’ll make a few changes and release the code and put it on the Android Play Store (for which I still need to register a developer account).

A quick how-to about the app – The app can be used to communicate with serial (RX-TX/UART) bluetooth devices. This largely includes devices that are used to control microcontrollers and other electronic projects which use bluetooth to send and receive information. I developed this app to use with a bluetooth enabled robot that I had been dying to build for quite some time now. I think it’s pretty self-explanatory and if it’s not, then I need to work a bit more on it. Continue reading

Scala–Methods vs Functions

An excellent explanation on Scala Methods and Functions:

http://jim-mcbeath.blogspot.in/2009/05/scala-functions-vs-methods.html

Apparently, Methods in Scala are different from Functions. From what I understand, a method is similar to a method in Java – it takes input and produces an output. But a Function is an object. Also takes an input and produces an output, but is an object. Here’s how they’re different:

def f1(x:Int):Int = x*2     //Method that doubles input

def f2 = (x:Int)=>x*2      //Function that doubles input

//f1.toString                    //Cannot be done!

f2.toString                      //Is perfectly valid

For more details, I’d suggest you take a look at Jim McBeath’s explanation.

Check if Binary tree is balanced or not

A quick interview exercise is to write code that checks whether a binary tree is balanced or not. Since a binary tree just begs for recursion, I decided to try it out in Scala. Takes less number of lines than I thought it would and it works. Logic works like this:

  1. If left node and right node are empty, tree is balanced
  2. If neither node is empty, just check that both left and right nodes are balanced
  3. If left node is empty, then right node can go down at most one more level
  4. If right node is empty, then left node can go down at most one more level

Here’s the code for it:

class Tree(val left: Tree, val right: Tree)

def isBalanced(tree: Tree): Boolean = {
  if (tree.left == null && tree.right == null)
    true
  else if (tree.left != null && tree.right != null) {
    isBalanced(tree.left) && isBalanced(tree.right)
  } else if (tree.left != null && tree.right == null) {
    tree.left.left == null && tree.left.right == null
  } else {
    tree.right.left == null && tree.right.right == null
  }

}