вторник, 27 декември 2011 г.

New videos

Finally I succeeded setting up the development environment for building QtEmbedded 4.6.3 application using QtCreator. My intention was to make complete video tutorial on all the process from installing the tools to compiling a "hello world" application and running it on FriendlyARM. Lack of time doesn't allow me to complete it. That's why I decided to publish my video "notes". They have been on YouTube for some time. They are just record of my desktop with no comment. Also here are my text notes I made during the installation process. Hope somebody might find them usefull.

Here are the videos:
How to install the cross-copiler for mini2440 on host PC (Video 1)

How to compile QtEmbedded 4.6.3 for mini2440 (Video 2)

Install QtCreator and set it up for QtEmbedded. (Video 3)

**** PC Installation ****
1. Install the cross-compiler to  /usr/local/arm/4.3.2
 In  PATH variable add folder /usr/local/arm/4.3.2/bin

2. Compile QtEmbedded 4.6.3 on PC. The result of the compilation are the libraries for ARM (libQtCore.so.4.6.3, libQtGui.so.4.6.3 и т.н) and tools for PC like qmake, uic, moc etc. Do it as root
    3.1 Unzip arm-qte-463-20100802tar.gz
    3.2 Enter the  arm-qte-4.6.3 folder and run configuration script (config-options file shown in Video 2):

./configure -prefix /qtbuild/ -release -shared -fast -pch -no-qt3support -qt-sql-sqlite -no-libtiff -no-libmng -qt-libjpeg -qt-zlib -qt-libpng -qt-freetype -no-openssl -nomake examples -nomake demos -nomake tools -optimized-qmake -no-phonon -no-nis -no-opengl -no-cups -no-xcursor -no-xfixes -no-xrandr -no-xrender -no-xkb -no-sm -no-xinerama -no-xshape -no-separate-debug-info -xplatform qws/linux-arm-g++ -embedded arm -depths 16 -no-qvfb -qt-gfx-linuxfb -no-gfx-qvfb -no-kbd-qvfb -no-mouse-qvfb-qt-kbd-usb -confirm-license -qt-mouse-tslib

    The -prefix option determines location of the compiled files. I this case it is /qtbuild
Important: Use exactly this version!

    3.3 Compile (takes more than an hour):
        $ make (or gmake)
        $ make install (or gmake install)

3. Install IDE QtCreator
Make qt-sdk-linux-x86-opensource-2009.05.bin executable:

    LinuxHost>chmod +x qt-sdk-linux-x86-opensource-2009.05.bin

4. Configure QtCreator with path to qmake. The qmake tool uses the project file .pro to generate  Makefile
    From Tools-Options in QMake location add path /qtbuild/bin/qmake and click  rebuild

5. Examples - in folder arm-qte-4.6.3/qt-everywhere-opensource-src-4.6.3 there is en example. Open the  .pro file in QtCreator  and  build it.

*** Configure FriendlyARM ***
The last FriendlyARM came with QtEmbedded 4.6.3 и tslib. If the board is older instead just install the file system rootfs_qtopia_qt4_20110305.img (option "y" in DWN) Doing this you don't have to upload the libraries to FriendlyARM.

This is done in Windows. Next step is to configure IP address and password with passwd command from console.

For applications to be abble to access the libraries global variables have to be set. Set them to use already installed in the file system libraries so you do not have to upload compiled QtEmbedded and tslib libraries. That's why using exactly 4.6.3 version is important.

Remark: check the fluidlauncher to see how you can make variables set on start

export QTDIR=/usr/local/Trolltech/QtEmbedded-4.6.3-arm
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/usr/local/etc/ts.conf
export QWS_SIZE=800x480
export QWS_DISPLAY="LinuxFb:mmWidth135:mmHeight155"
export QWS_MOUSE_PROTO="Tslib:/dev/input/event0"
export TSLIB_PLUGINDIR=/usr/local/lib/ts 

Remark:Change the display size if necessary. This settings is for 7".
*** fonts **
transfer from PC from /qtbuild/lib/fonts/ fonts to
 FriendlyARM  /usr/local/Trolltech/QtEmbedded-4.6.3-arm/lib/fonts
*** TSLIB ***
When try to run Qt4 application from console if there is no link to tslibrary an error mesage is shown:
error while loading shared libraries: libts-0.0.so.0: cannot open shared object file: No such file or directory

Make symbol link:
ln -s /usr/local/lib/libts-0.0.so.0 /usr/local/Trolltech/QtEmbedded-4.6.3-arm/lib/libts-0.0.so.0

*** Screen Calibration ***
/usr/local/bin/ts_calibrate - this is the application for calibration
//it can be run from qtopia
*** runnin the application ***
Diasble the Qtopia and run the application with qws option. It makes the application responsible for writing to the frame buffer. 
/myapp -qws


сряда, 14 септември 2011 г.

The display turns white

I had problem with my FriendlyARM board. The display turned bright white occasionally.
The problem started to occure more and more often. It appeared that the problem is in the ribbon cable between the board and the display. About 0.8V are lost along the way. After connecting the display directly to the power from CON8 on the board there are no more display troubles.

вторник, 30 август 2011 г.

петък, 17 юни 2011 г.

Creating web interface (part 2)

This Example shows how to access GPIO pins via web interface.

First you need to install on mini2440 linux kernel with GPIO support.
Unfortunately FriendlyARM comes with kernel without GPIO and SPI support.
If you decide to try to compile kernel take a look at "Kernel Tweaking" link below. There is a good explanation how to do it.
The other option is to download already compiled kernel from
It is for 7" display but for this example only network access to mini2440 is needed.
I'm not going to explain how to upload the kernel image. It's shown in the board's manual.

When the new kernel is uploaded let's first check the access to GPIO from the command line.
Telnet to mini2440 and go to sys/class/gpio folder:

$ telnet
[root@FriendlyARM /]# cd sys/class/gpio/
[root@FriendlyARM gpio]# ls
export       gpiochip0    gpiochip128  gpiochip160  gpiochip192  gpiochip224  gpiochip32   gpiochip64   gpiochip96   unexport

Folders gpiochip0 , gpiochip128 .... represent GPIO drivers for each port. Ports are named A,B,C....
Check the port for each gpiochipX:

[root@FriendlyARM gpio]# cat gpiochip0/label
[root@FriendlyARM gpio]# cat gpiochip32/label
[root@FriendlyARM gpio]# cat gpiochip192/label

Each pin has it's corresponding access number. For example buzzer is connected to GPB0 ( Port B pin 0) and port B is accessible from gpiochip32 so the number to access the buzzer is 32.
Led1 is connected go GPB5. It's access number is 32+5 = 37
Buttons are connected to port G - gpiochip192

Function    Port    Access number
Buzzer        GPB0    32
Led1           GPB5    37
Led2           GPB6    38
Led3           GPB7    39
Led4           GPB8    40
Btn1           GPG0    192
Btn2           GPG3    195
Btn3           GPG5    197
Btn4           GPG6    198
Btn5           GPG7    199
Btn6           GPG11    203

Now open access to the buzzer. :

[root@FriendlyARM gpio]# echo 32  > export
[root@FriendlyARM gpio]# ls
export       gpio32       gpiochip0    gpiochip128  gpiochip160  gpiochip192  gpiochip224  gpiochip32   gpiochip64   gpiochip96   unexport

A new link gpio32 appeared now. Let's check the current direction and make it an output:

[root@FriendlyARM gpio]# cat gpio32/direction

[root@FriendlyARM gpio]# echo "high" > gpio32/direction
[root@FriendlyARM gpio]# cat gpio32/direction

Turn the buzzer on and off:
[root@FriendlyARM gpio]# echo "1" > gpio32/value
[root@FriendlyARM gpio]# echo "0" > gpio32/value

Close the access:
[root@FriendlyARM gpio]# echo 32  > unexport

First stop the Led player as shown on one of previous posts.

The project consists from the following files:
access_num.h     -    definitions of GPIO driver access numbers            

gpio.h gpio.cpp -     class for control of GPIO. Each instance is for control of one pin

readbtn.cpp    -     CGI program that reads the state of the six board buttons and shows
            it in table on a web page. The page is automatically refreshed each
            two seconds.

ledbuzz.cpp    -     CGI program that reads the query string sent to the web server and
            turns on/off the LEDs and the Buzzer.Then the state of the four board
            leds and the buzzer are shown on a web page as checkboxes.
            The user can change the    checkboxes. When submit button is pressed
            the new states are sent to the web server using GET method and the
            same program is called again.
download the project folder from:

compile with command:
$ arm-linux-g++ gpio.cpp ledbuzz.cpp -o ledbuzz.cgi
$ arm-linux-g++ gpio.cpp readbtn.cpp -o readbtn.cgi

Note: In the project folder there are already compiled binaries ledbuzz.cgi and readbtn.cgi

upload ledbuzz.cgi and readbtn.cgi to the board to /www/cgi-bin folder and give them executable attribute
# chmod a+x ledbuzz.cgi
# chmod a+x readbtn.cgi

Run them from the command line. You should get HTML output

There is no index.html. Open CGIs from PC web browser directly:

Access to GPIO pins explained

Kernel Tweaking

P.S. If you find this articles useful please pay some attention to the ads.
Some of them might be interresting to you too. Thanks.

събота, 11 юни 2011 г.

Creating web interface

FriendlyARM comes with installed Boa web server. 
Web interface can be very useful feature for real life applications. 
It might be used for editing and storing settings to a file or to access the real world - ADC, GPIO, SPI, Serial.

The purpose of this tutorial is to show the basics of creating a simple web interface using CGI in C.

All that you need is mini2440 board with or without LCD and PC with GCC cross-compiler  
On my mini2440 I have SD card installed. If  you do not have any you have to make some changes to the code.

Example 1:
The example consists of the following files:

This web interface opens example.txt text file from the flash and shows it on a web page. 
The user can edit it and store it back.

The first file is index.html. When you type the IP address of the FriendlyARM board into a web browser Boa 
searches for index.html in /www 


    <meta http-equiv="Refresh" content="3;url=./cgi-bin/showfile.cgi">
    redirecting in 3 seconds...

The only purpose of this web page is to redirect the browser to another URL and in particular this is the showfile.cgi

What is CGI? This is a program. It might be a script file or an executable written in no matter what programming language.
You can write CGI in C,Basic or even Assembler. This executable is called by the web server. 
CGI program captures data reading environment variables and the output data is sent to the console. 
The web server captures this output and sends it back to the client's browser.

Two CGI programs are used in this example - showfile.cgi and savefile.cgi
When the web server calls showfile.cgi it reads file template.html from flash and sends it's contents to the console.
The contents of example.txt are sent between </TEXTAREA> and </TEXTAREA> tags. 

    <FORM name="input" action="./savefile.cgi" method= "get">
        <TEXTAREA NAME=textarea ROWS=10 COLS=60>
<!-- /TEXTAREA -->
    <INPUT type="submit" value="Submit" />       <INPUT type="reset" value="Undo changes" />


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
//Open template.html file. If unable to open show error web page and return
    FILE * htmlTemplate;
        htmlTemplate =  fopen("/sdcard/html/template.html","r");
    if(htmlTemplate == NULL)
        printf("%s%c%c\n",    "Content-Type:text/html;charset=iso-8859-1",13,10);
        printf("<H3>ERROR: Unable to open template.html!</H3>\n");
        return 0;
//Open example.txt file. If it doesn't exist a new empty file will be created.
    FILE * textFile;
        textFile =  fopen("/sdcard/example.txt","a+");

//start sending template.html to the console
    char row[1000];
    printf("Set-Cookie:MY_COOKIE=ThisIsCookieJustForFun\n"); //This line is only to demonstrate how to set cookie
    printf("%s%c%c\n",    "Content-Type:text/html;charset=iso-8859-1",13,10);

        if(strstr(row,"<TEXTAREA") != NULL)
            if(textFile != NULL)
            {//send example.txt to the console
    return 0;

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
//Open example.txt file.
    FILE * textFile;
        textFile =  fopen("/sdcard/example.txt","w");

    char * query;
    query = getenv("QUERY_STRING");

    printf("%s%c%c\n",    "Content-Type:text/html;charset=iso-8859-1",13,10);
    if(textFile != NULL)
    {// save file to disk
        //cut the beginning if it starts with "textarea="
        if(strstr(query,"textarea=") != NULL) fprintf(textFile,&query[9]);
        else fprintf(textFile,query);
        printf("<H3>File example.txt was saved to SD card</H3>\n");
    else printf("<H3>Failed to save example.txt. Reason - unable to open file for writing.</H3>\n");

    printf("<a href=\"./showfile.cgi\">Return to edit example.txt</a>\n");

//Nex code is just for fun.
    printf("<HR><BR><BR> Now let's read some environment variables just for fun<BR>");
    char *envvar;


    return 0;

Compile it with command
arm-linux-gcc showfile.c -o showfile.cgi
arm-linux-gcc savefile.c -o savefile.cgi

When "Submit" is clicked on the web page content of the text area is sent back to the web server
and savefile.cgi is called. (Note the FORM tag in template.html)
Used method is "GET" and data is retrieved from the environment variable QUERY_STRING.
If "POST" method is used reading data is read from stdin.
NOTE: When data is sent back to server some special characters are encoded to %XX format. They have to be decoded before saving them to file. To keep this example simple I omitted this step.

Only for demonstration a cookie MY_COOKIE is set and reading some environment variables is implemented.

Upload files to the board:
index.html    -- /www
showfile.cgi  -- /www/cgi-bin
savefile.cgi  -- /www/cgi-bin
template.html -- /sdcard/html

change permissions to execute cgi files with:
[root@FriendlyARM cgi-bin]# chmod a+x showfile.cgi
[root@FriendlyARM cgi-bin]# chmod a+x savefile.cgi
If you miss to do it you will get error 

   502 Bad Gateway
   The CGI was not CGI/1.1 compliant.


HTML Tutorial

More on CGI

cgic: an ANSI C library for CGI Programming
Excellent library that can save you a lot of typing.

iniParser: stand-alone ini parser library in ANSI C
This is excellent library if you have to save and retrieve data from ini files.

понеделник, 20 декември 2010 г.

Uploading new font

It is possible to upload True Type Font  to the FriendlyARM

1. Upload the ttf file to /opt/Qtopia/lib/fonts

2. Edit the file fontdir which is text file and on a new board is empty.
Add a line with  format:
name file renderer italic weight size flags
nameThe name of the font format, e.g.,Helvetica, Times, etc.
fileThe name of the file containing the font, e.g., helvR0810.bdf, verdana.ttf, etc.
rendererSpecifies the font engine that should be used to render the font, currently only the FreeType font engine (FT) is supported.
italicSpecifies whether the font is italic or not; the accepted values are y or n.
weightSpecifies the font's weight: 50 is normal, 75 is bold, etc.
sizeSpecifies the font size, i.e., point size * 10. For example, a value of 120 means 12pt. A value of 0 means that the font is scalable.
flagsThe following flag is supported:
  • s: smooth (anti-aliased)
All other flags are ignored.

For example to use Hebar for applications with cyrillic interface I add:
hebar hen.ttf FT n 50 0

Now without restart the font is accessible from Settings-Appearance-Font 

неделя, 19 декември 2010 г.

Stop the LED player!

If you need to use those GPIO pins connected to onboard LEDs the LED player should be stopped. To do this telnet to the board and with vi open this script file /etc/init.d/rcS

[root@FriendlyARM init.d]# vi rcS
(The beginning of the file omitted)
/etc/rc.d/init.d/netd start                      
echo "                        " > /dev/tty1      
echo "Starting networking..." > /dev/tty1        
sleep 1                                          
/etc/rc.d/init.d/httpd start                     
echo "                        " > /dev/tty1      
echo "Starting web server..." > /dev/tty1        
sleep 1                                   
#/etc/rc.d/init.d/leds start                                        Comment out these lines!
#echo "                        " > /dev/tty1
#echo "Starting leds service..." > /dev/tty1
#echo "                        "           
#sleep 1                                   
/sbin/ifconfig lo               
/bin/qtopia &                             
echo "                                  " > /dev/tty1
echo "Starting Qtopia, please waiting..." > /dev/tty1


Thats it. You can also remove  "sleep 1" and win two seconds faster boot time.