3 Kasım 2013 Pazar

PyQt via QtDesigner

In this post, we will use a Widget created with QtDesigner, transform it to python code and run it with python interpreter in any machine you want. This is really useful for GUI programming in Raspberry pi. Because Raspberry pi comes with a good python support.
My environment:
  • Ubuntu 12.04 LTS
  • Python 2.7.3 (comes with Ubuntu default)

In order to use PyQt with QtDesigner, we have to install required packages:
$ sudo apt-get install python-qt4 qt4-dev-tools python-qt4-dev pyqt4-dev-tools qt4-designer
After the installation open a terminal and write:
$ python
>>>import sys
>>>from PyQt4 import QtGui
If you do not get any errors, that means you sucessfully installed PyQt. With the installation of "pyqt4-dev-tools", pyuic4 is also installed which is able to transform an XML formatted Qt ui file to python code. To check it, write pyu and press tab in the terminal to see the name completely.
I will not explain how to create a custom Widget in Qt designer here, however I'm gonna give .ui file created via QtDesigner here. You can open it via QtDesigner and play on it.
Assume that we have a hello.ui file, open the terminal and write:
$ pyuic4 -x hello.ui -o hello.py
Now we have hello.py to run in python. Note that "-x" parameter is for transforming the xml ui code to fully python code.
Again in the terminal write:
$ python hello.py
Tata! You will see a "Hello World" label in window and change it by writting something to see how it works. Yes, your GUI design in Qt is working as a python code. I love coding in C++, however this will simplify my job while dealing with my Raspberry pi. The hello.ui code is given below:

22 Ekim 2013 Salı

Simple Makefile Including Compilation of Shared Object Library

This post covers two main concepts: a simple Makefile generation and compiling a shared object library within this Makefile.
Directory structure is designed as this:

  • ../MakeFileProj (MakeFile)
  • ../MakeFileProj/inc (Headers: test1.h, test2.h)
  • ../MakeFileProj/src (Source Files: main.c test1.c test2.c)
  • ../MakeFileProj/obj (Object Files: main.o test1.o test2.o)
  • ../MakeFileProj/lib (Library Files: libtest2.so -> test2.c is compiled as shared object library)

The source and header files are given below:

Makefile is as shown below:
As source, test1.c and main.c are compiled and object files are created under /obj directory. However test2.c is compiled as a shared object library and the .so file created under /lib. Finally, the object files and the .so library are linked to create "test" executable.

After compilation succesfully one can try the executable file in console as:
$ ./test
$ ./test: error while loading shared libraries: libtest2.so: cannot open shared object file: No such file or directory
At run-time the executable file cannot find shared object library, so we should add it to LD_LIBRARY_PATH.
$ export LD_LIBRARY_PATH=/home/sezerb/Desktop/MakeFileProj/lib:$LD_LIBRARY_PATH
Do not forget to use your own path, where libtest2.so is located. Then try ./test again:
$ ./test
$ sZr Welcome to MakeFileProject...
$ sZr test1Message: This is not a shared library
$ sZr test2Message: This is a SHARED LIBRARY

This Makefile should be a reference one for our projects...
Take care yourselves!..

25 Eylül 2013 Çarşamba

Creating SVN Repositoy in your Dropbox in 4 steps.


Sometimes while you're coding in your local workspace or writing your thessis it's better to have your source as an SVN repository. You can reach it from everywhere for editing and  doing some modifications.
  1. Install Tortoise SVN or an SVN program to your device and get a Dropbox account.
  2. Create a folder in your Dropbox folder via right clicking mouse button.
  3. Right click on the just created folder and click Tortoise SVN -> Create Repository here...
  4. Go to your source folder, right click on it and  click Tortoise SVN ->Import. Choose the address of the repository folder in your Dropbox folder and it's DONE.
Kind Regards...

3 Haziran 2013 Pazartesi

Embedded Linux Practical Hints


  • Every embedded linux system requires a MMU (Memory management unit) in order to work. MMU is responsible for handling accesses to memory requested by the CPU.
  • Every system is mainly composed of 4 methods: open, read, write and close.
  • Nowadays linux kernel 2.6.32 and 2.6.35 are robost versions for embedded development.
  • We always need Toolchains for embedded linux development. We should create or copy the toolchains under /opt directory.
  • While dealing with arm boards, one can face with eabi, oabi etc. These are related with D and I busses. eabi stands for 32-bit-fast, and oabi stands for 8-bit slow. One can also face with hard-float and soft-float issues which are confusing. soft-float means implemented on fpga as a software, and hard-float means implemented as hardware.
  • arm-linux-gnueabi-gcc can be the cross-compiler of your life.
  • In order to simulate or emulate embedded linux system, you can use qemu.
    • sudo apt-get install qemu qemu-kvm qemu-kvm-extras
    • For instance, in order to cross-compile a mips architecture you can use qemu-system-mips compiler.
    • In order to run a cross-compiled program in arm architecture just use qemu-arm
  • You always get tar.bz2 or tar.gz while download toolchains or kernel etc.
            tar.bz2->                         tar -jxvf  ....... -C /your directory
            tar.gz->                           tar -zxvf ....... -C /your directory
  • Kernel source code has architecture under the /arch directory. There are template configuartion files for these architectures.
  • For cross-compilation of Kernel source: (an example of arm versatile)
    • $ make ARCH=arm versatile_defconfig
    • $ make ARCH=arm menuconfig
    • Enable EABI from Kernel features
    • $ make ARCH=arm CROSS_COMPILE=arm-angstrom-linux-gnueabi-
    • the cross-compiler appends gcc at the end of arm-angstrom-linux-gnueabi- at the compile time.
    • After the compilation, the output files will be located in /arch/arm/boot/
    • To test zImage (kernel image) via qemu:
      • qemu-system-arm -M versatilepb -m 128M -kernel zImage
      • After run the command above, you will get a rootfs problem, since we do not have it yet.
  • In order to create rootfs or let's say userspace, we can use busybox or System.
  • However buildroot is a really useful tool to build user space. Let's use it:
    • cd buildroot
    • make menuconfig
    • Choose Target Architecture (arm) and Target Architecture Variant (arm926t)
    • Choose Target ABI (EABI)
    • Choose Target Filesystem options ->cpio->compression method (gzip)
    • After the configuartion, save and exit.
    • make V=1
    • the command above will start to build your userspace. V can be between 1 and 10. 1 means low compression, 10 means high compression.
    • After the operation completes, the output is rootfs.cpio.gz.
    • Now we can test our system with qemu:
      • qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.cpio.gz
  • A linux system is mainly composed of:
    • primary bootloader ( cpu )
      • intermediate stage MLO (Mloader which is specific to board producers.)
    • secondary bootloader (FAT file system)
    • Kernel
    • User Space
      • /User Space/boot/Kernel. User Space shall include kernel image too. Because after boot up and the rootfs is mounted, the kernel operations should be done in user space not in fat partition. So, after boot up,  a swap operation is done and the kernel in the user space which is the same as in the FAT file system becomes active.
  • To boot a simple linux system up from SD Card:
    • First of all, divide your SD card into two partitions: boot (FAT) and Angstrom(ext3). You should use a script. Angstrom is just an example, change it according to your system.
    • To FAT partition, copy MLO (MLoader), u-boot.bin and uImage under the boot partition sequentially. The copy order is very important. Because in FAT file system, the files are written with starting adress 0.
    • To ext3 partition, copy uImage under /boot/ with the name uImage.
    • Our SD card is ready now to boot up.
  • To access hardware in a linux system, just check /sys/class/. 
    • cd gpio
    • ls -l
      • export unexport
    • Let's say our gpio is 139.
    • echo 139 > export
    • gpio139 folder is formed.
    • cd gpio139
    • cat direction
      • in
    • echo out > direction
    • echo 1 > value
    • We have set gpio to output and the value to 5.
  • In order to start our target linux system with a program:
    • Write your script that is running your program.
    • copy your script under /etc/init.d/
    • Make sybolic links under /etc/rc*.d (rc0.d, rc1.d, rc2.d...rc5.d) In rc5.d root screen appears.
    • rc0.d and rc1.d are mostly responsible for hardware initalizations, you can start your applications after these two operations.K stands for Kill, S stands for Start.
    • To automatize above operations, write your script, boot up your target system, copy script under /etc/init.d and write command: update -rc.d blabla.sh defaults

1 Mayıs 2013 Çarşamba

Dealing with Complex Languages as Hebrew, Arabic etc. as a Programmer

Programmers sometimes have to deal with some complex languages as Hebrew, Arabic etc. For instance, let's say we have to design a user-interface including Hebrew strings. For such situations for you to overcome and for me not to forget and to be able look behind after a while, I suggest you to read the references given below. The first one is explaining character sets and the historical improvement of it. The next one is about an engine which can be ported to your project to handle these language stuff.



http://www.joelonsoftware.com/articles/Unicode.html

http://userguide.icu-project.org/layoutengine

Kind Regards...

9 Nisan 2013 Salı

How to install Dropbox to Ubuntu 12.10

It's a little bit rough stuff to deal with installing Dropbox to Ubuntu 12.10. Because one may encounter some problems during the installation process.

I've found a really useful article about it given in the website below:

Installing Dropbox on Ubuntu 12.10


http://www.bytesbynight.com/wp/?p=214

in terminal:
~/.dropbox-dist/dropboxd
                 OR
add the command to StartUp Applications

Thanks to Chris Jaquet!

P.S. Also note that for SVN and Git repositories, RabbitVCS is useful.

21 Ocak 2013 Pazartesi

Writing Thesis via LaTeX...

LaTeX is a perfect tool for writing your academic stuff like papers, thesis etc.

I suggest MiKTeX to construct your documents. You can download a Windows version installer from the website given below:
http://miktex.org/

MiKTeX includes TexWorks and provides "pdfLaTeX + MakeIndex + BibTeX" option for building your work.

There are so many editors that one can use for editing .tex files. I'm using "Sublime Text 2". It's colorful and really easy to use.

For drawing shapes, figures and flow charts you can use "Dia" tool. You can find the relevant tool from http://dia-installer.de/ website.

Dia is able to export the .eps format which is used in LaTeX for the figures.

To sum up, for a complete configuration to write your academic papers or thesis:

  1. Get MikTex. (Builds your entire work)
  2. Get Sublime Text 2 (It's optional, but really enhances your editing skills)
  3. Get Dia
If I need to explain LaTex in one word: It's a life saver!

P.S. You can use Daum Equation Editor to write your equations in Latex!!! You don't need to learn how to write equations in Latex, just use Daum Equation Editor. It's a Chrome Application.

VIA APC 8950 Board Bring-Up

Nowadays, I have my APC 8950 board having Android 4.0 operating system. Visit http://apc.io/products/rock/ for more details. My aim is to port Debian to this board but it seems like I have a lot of work to do. I'm planning to share the process here in my blog.
Now let's make our plan:

1)Since APC 8950 has armv7 cpu (ARM Cortex-A9), we have to obtain related  cross-compiler for cross-compilation. It seems like I will look for a CodeSourcery one.

2)We need to get the kernel for cross-compilation.
https://github.com/apc-io/apc-8950
Kernel is just standing there, @ link above.
Our system will be a u-boot system so, we need "mkimage" to give headers to kernel image or any other application etc.

3)Since u-boot.bin does not require any operating system, I'm thinking of using u-boot.bin of the board itself. I mean, I'm not going to cross-compile the u-boot. I will just use whatever the board has.

4)Now Android OS is sitting on the nand flash. I do not want to interrupt it, so I'm planning to make an SD card image for Debian port. When SD card is plugged in, and the board is powered on, it will boot from SD card and start Debian.

5)For "RootFileSystem" part, busybox shall be cross-compiled first. Most probably, rcS script will be used for creating root file system. I will share details when I handle it.

This blog page will be updated with incoming progresses. So keep following!..