Thursday, June 11, 2015

Demystifying LCD Pinouts

Recently I bought a couple of LCDs from China. The LCDs were listed as 1.8" SPI TFT LCD and the specified resolution was 128x160.

Once receiving LCDs I realized that the pinout printed on silkscreen had:

  • SCK
  • SDA
  • A0

This got me confused because A0 and SDA are I2C standard terms but SCK is SPI term?

Engineering (Reverse):

Here is my attempt to reverse engineer the two LCDs:

After some some reverse engineering on two different types of modules and going through the LCD datasheet I realized that the connections map as below:

LCD   -   Bus / Meaning
Vcc   -   Vcc
Gnd   -   Gnd
CS    -   CS (Chip Select)
Reset -   Reset (Module Reset)
A0    -   D/C (Data / Command)
SDA   -   MOSI (Master Out Slave In) SPI
SCK   -   SCK  (Serial Clock) SPI
LED   -   LED Backlight +V (~3v - use a current limit resistor)

I tested one of the LCD using an Arduino compatible system and it worked fine. The other one still needs to be tested. I may have destroyed my modules during RE so take care when you go on a similar quest.

Bottom line:

Do not hesitate to buy cheaper modules from China based manufacturers. All you need to do is some research and development. Please share your findings.

Wednesday, June 10, 2015

Using CU as terminal emulator

Many of us use Linux as primary development station for microcontrollers. Long time back I discovered a simple terminal emulator or Linux called CU ( From it's man page - Call up another system / Call Unix). CU was originally developed to connect to other UNIX systems using serial modems or null-modem connection. This was before network systems like Ethernet or Token Ring were developed. I still remember in my UNIX lab 8x dumb terminals were connected to a server with one Eight Port serial adapter in good old days.

CU is a very low footprint terminal emulator for Linux / UNIX based systems.

Only thing that you would have to remember is how to connect and disconnect from the terminal.


I installed CU on xUbuntu using the following command

sudo apt-get install cu

This will ask for your sudo password and install cu with all dependencies.

Now, to run cu (or any terminal emulation program)  following minimal parameters are needed:

1. Port number
2. Speed of the serial port

I connected an PL2303 based USB to serial adapter to my Linux machine and it detected it as device ttyUSB0. I found the device name using Linux command "dmesg" as it appeared right after I connected the hardware device.

Here is the sample output of the dmesg command (your experience may vary):

[  215.320221] usb 1-2: new full-speed USB device number 3 using ohci_hcd
[  215.877355] usbcore: registered new interface driver usbserial
[  215.877364] USB Serial support registered for generic
[  215.877383] usbcore: registered new interface driver usbserial_generic
[  215.877386] usbserial: USB Serial Driver core
[  215.885268] USB Serial support registered for pl2303
[  215.885284] pl2303 1-2:1.0: pl2303 converter detected
[  215.917802] usb 1-2: pl2303 converter now attached to ttyUSB0
[  215.917818] usbcore: registered new interface driver pl2303
[  215.917821] pl2303: Prolific PL2303 USB to serial adaptor driver

So this confirms (in my case) that operating system recognized that USB<->Serial hardware as ttyUSB0.

Each individual case may be different as your operating system can recognize it as a different device. Use the device name that is reported by your OS.

So, now we got one parameter that we need to pass to cu command and that is the port number or a port device (UNIX).

Now we need to determine what speed we need to connect to that terminal / target device. The speed totally depends on your target device. For example I'm connecting to a GPS Engine (target device) chip that communicates at 9600 baud.

This is the simplistic setup as I am not discussing the parity, start bits, stop bits, flow control etc. If your device obeys a certain protocol, you can specify that at cu command line.

Here is a manual page for cu on Linux systems:

You can specify other parameters (from man page) as below:


--nostop   #Turn off XON/XOFF handling (it is on by default)

-h, --halfduplex #Echo characters locally (half-duplex mode).

You get the point by now...


I connect my GPS device (9600 n,8,1) with cu as under:

chetan@xubuntu:~$ cu --line /dev/ttyUSB0 --speed 9600


As you can see that I was able to successfully connected to the GPS device using command

cu --line /dev/ttyUSB0 --speed 9600

I was able to successfully communicate with the device at 9600 N81 @ port /dev/tty/USB0

At the end you see a command "~." this terminates the cu session. When you are ready to disconnect with your device (GPS in my case) just type a ~ and a . (dot) and hit enter. You will then be disconnected from your device. You need to remember the disconnect procedure as CU would not provide any help in the session.

Logging Output:

In case you want to log output of the session you can start "cu" with "tee" as below:

cu --line /dev/ttyUSB0 --speed 9600 | tee logfile.txt

this will log your session output in file "logfile.txt".

Bottom Line:

CU is a great lightweight program to communicate with serial / UART / USART  devices available on many UNIX platforms including FreeBSD. Please comment.

Saturday, September 08, 2012

Gerbmerge errors

Continuing from my previous post, Installing gerbmerge on recent installation of Ubuntu Linux (12.04-LTS) causes installation to fail with error

Traceback (most recent call last):
  File "", line 41, in
    DestDir = os.path.join(DestLib, 'gerbmerge')
  File "/usr/lib/python2.7/", line 68, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'

This is caused by variable DestLib not being set properly by following line in

DestLib = distutils.sysconfig.get_config_var('LIBPYTHON')

Maybe with new version of python distutils.sysconfig.get_config_var('LIBPYTHON') returns nothing.

In order to fix this, change the above line to

DestLib = '/usr/local/lib/python2.7/'

If your python local library path  is different, substitute your own path in the line above.

I'm not too good at python but maybe "sys.path" can be used to set the library path.

Please comment if this works or doesn't work for you.

Friday, August 03, 2012

WD Passport :-(

Some time ago I bought a Western Digital Passport 750GB drive from Costco. I used the drive for offloading my laptop SSD. Recently while I was moving some files off of my SSD I encountered a few delayed write errors (Windows XP). I connected the drive to my ubuntu machine and ran a drive test. Figured out that it had 15 bad sectors that were ready to be remapped. But in any case the drive won't mount at all on any of the OS.

I decided to open the drive and connect directly to a serial ATA port to get direct IO access. I opened the cover and found out that the drive had no SATA port! Instead it had a USB soldered on the drive logic-board. Bummer!

Since then, I have decided not to use WD passport and switched over to Seagate GoFlex that has exposed SATA connector at the bottom. I took some pictures of the connector and will post soon.