Wednesday, December 30, 2009

A lady who travelled faster than light....

I recently read and much inspired by this old poem:

Once there lived a lady
She could travel faster than light
She left out of home today
And returned back yesterday!
Sometimes the real things are stranger and mysterious.....

Tuesday, December 29, 2009

Gui front end for parallel port controller in Linux

A graphical front end for the parallel port controller in Linux was my dream and I just satisfied it in my Xmas vacation. I used Qt framework from Nokia. I just put here everything I did. Of course you are allowed to download and use it under GPL (GNU General Public License). You are appreciated to modify source code according to your needs.
Now the program supports only on Linux platforms even though qt frame work is independent of platform. The reason is that, parallel port controlling is directly depend upon the OS you are used. You can easily control your parallel port in MS DOS environment, but things become worse when you try in Windows XP. Since the program calls the ioperm() function, you should have root privileges. Otherwise an abrupt exiting of the program occur. You only need to do the following things:
  • Be root, and start the program by ./parport2. Try to open it from terminal at least for the first time in order to track bugs.
  • Click 'Initialize' to call ioperm(). If you are not root, then the program abruptly exits while you click it.
  • Nothing will be happened at outside while you click in 'Initialize'.
  • You can use 8 switches to turn on or off the output data ports.
  • The current output value in decimal is displayed on lineEdit.
Most probably the executable version will not work in your system unless your system configuration matches with mine. So it is recommended to compile entire program using qt. You need to have qmake installed in your system (qt-dev-tools). The compiling instructions for qt program is beyond the scope of this post.

Download parport.tar.gz (1.4MB)

I tested it in my PC and worked without any problem.
Warning: Take care while you play with parallel port. Very rarely, the after effect may fatal.
Note:- This program is intended for educational purposes only. May not be updated until anyone report a bug or a request to modify.

Saturday, December 26, 2009

PHET science simulations for students

PhET interactive simulations - Fun, interactive, research-based simulations of physical phenomena from the PhET project at the University of Colorado.

I found those simulations were good in today's eduction- thanks for university of Colorado. Most of them are intended for Upper and High school students and pre- graduate students. However, if you just spend your time in experimenting with it, I am sure you get something new. Phet interactive simulations create a virtual lab environment. It's just a feeling that to enter into a physics or chemistry lab in a college. You can do anything in your own lab. Nothing to fear. No more comments from teachers...
One more advantage is that, you only need a java powered web browser. You can browse through different lab environments. If you like PhET virtual lab, you can download it for offline usage. Linux(80MB), Windows(97MB) and Mac OS(85MB) installation supported.

Browse phet simulations
Download phet for offline usage.

Wednesday, December 23, 2009

Parallel port programming using C/C++

Parallel port programming is easy with C or C++. Even other languages integrate C/C++ codes to their codes in order to program parallel ports. If you are a beginner in parallel port programming and know nothing about it, just go through this intro page. Nevertheless the efficiency of code, the code may be different for different platforms and need to be compiled with some change in the code.Here we see how to program parallel port(printer port or LPT) in both GNU/Linux and MS Windows platform.
Parallel port programming in GNU/Linux
I am not intended to make a wide description. I am directly give an example and this is what you want. If you are experienced the taste of C, you can easily catch what the program code mean.(We use LEDs to check whether our program run. You can see a simple circuit in the intro page). Connect the circuit described in intro page. to the parallel port properly. Then make new file parport.c and edit the file as shown:

#include stdio.h
#include stdlib.h
#include asm/io.h
#include unistd.h

#define base 0x378 /* printer port base address */
#define value 255 /* numeric value to send to printer port */

main(int argc, char **argv)
{
if (ioperm(base,1,1))
fprintf(stderr, "Couldn't get the port at %x\n", base), exit(1);

outb(value, base);
}



The above program is copied from epanorama. You should compile the program as su (super user) since ioperm() function needs root access. But in my system the above program didn't work. Many of my friends got error while compiling. The solution is to change the 4th line
#include asm/io.h
to
#include sys/io.h

You change the line and recompile only if you get a linking error. Sometimes you get an error like "Couldn't get the port at 378". But this is not a problem due to the port address. You probably may not be su.

Parallel port programming in MS windows
Converse the subtitle suggests, this program is not working in the windows environment, but in the MS DOS environment. I think you have basic knowledge of how to compile a C program.

#include stdio.h
#include conio.h
#include dos.h

/********************************************/
/*This program set the parallel port outputs*/
/********************************************/

void main (void)
{
clrscr(); /* clear screen */
outportb(0x378,0xff); /* output the data to parallel port */
getch(); /* wait for keypress before exiting */
}


The above program is also from epanorama. If you try to compare those programs, you can see a very little difference between those codes. Parallel port is a hardware and surely it is depended upon the OS you are using. So you can't write a cross-platform code for the parallel/printer port control. Please note that you can read inputs as well as write as output however, the example only shows the output control. Sometimes your port address may be different, however in most cases it will be 0x378. If it fails try 0x278 and 0x3BC. Read more here.
You can check your program by simply inserting an LED connected in serial with 1K ohm resistor.

Read my post on parallel port control on python

How do we think? A brief introduction

Thinking about how we think is difficult, because thoughts of thoughts are limited by thoughts itself. But learning of how we think is essential in computing as well as AI powered robots. The basic reason of our thinking ability is a special type of cells in brain - neurons. A neuron is not perfectly known to human yet, but many similar models are proposed. The power of neurons is in its networking ability. Neurons are connected to each other and these complex networks may called as neural networks. I am not describing much about neurons because it is beyond our task. It's well enough if you just get an overview from Wikipedia. As I said, many convenient models are there to explain the behaviour of a neuron (Of course, a networked neuron is complex than a single one), but I am just touching simplest one named Perceptron. I will also mention back propagation during the example. I have pasted one figure from Wikipedia because you need it.The area in the shaded square can be considered as a neuron. x1,x2,......x7 are the inputs and w1,w2.......w7 are the corresponding weights (I will tell you what it is). and f is simply a function and outputs y. If the weighted sum of the inputs exceeds a particular threshold (which is previously be set), output y fires out. In actual neurons, y depends on other parameters such as input frequency. Since whole process in actual neurons are chemical, the explanation become rather complicated. But in all models we consider input as well as output signals are electrical in nature.I am explaining once again: first find
x1*w1+x2*w2+.........+x7*w7
If the resultant value is greater than a threshold (Typically 0), y=1; otherwise y=0.
I hope you understand something. But I know most of you are not satisfied because, you don't know what is really going on! Right?
Let me tell an example. This is a story. Here is you, Heroin is you.
Consider you have three friends and you(your brain) thinks that they are:
  • Albert - Your best friend. You have a confidence level of 0.7 on him. You trust him and ask his opinion before every important attempt
  • Deepika - Your classmate. Confidence level 0.3. Good personality.
  • Tom(me) - Confidence level of -0.55. Always say lie. Cheating personality.
These prejudice are taken by your brain from your experience. May be true or may not be.
The problem starts here. You are getting ready to go to your office/college. There are two ways to go. One is short path (easy way). Other is long. But short way has a problem is that sometimes it will be blocked. If you take the long path, you may reach the destination late. But if you choose the short path and in any case if blocked, you can't reach the destination on that day.
Then you come to know that today short way will be blocked. Then you consult your friends. Check their opinion:
  • Albert - Short road is not blocked. Damn sure.
  • Deepika - Someone told me about it. Short way may not be blocked. But I am not sure.
  • Tom - Hey man, road is blocked.
Can I go straight away through the short path?
Let's look how your brain solve the problem. Albert surely says that road is not blocked. Put a value of +0.95 for his opinion. The positive sign indicates that he is opposing. If Albert says sure that road blocked, the value may be -0.95. You don't know much about Deepika. But she may be right. Put a value of +0.1. Tom says it is blocked. So put -0.8.
Here threshold value is 0. If weighted sum is greater than 0. road is blocked. It is good to choose the long way. I not, road is not blocked, choose the short path.

Weighted sum is:
signal strength of Albert * confidence level+ signal strength of Deepika * confidence level+ signal strength of Tom * confidence level
=0.95*0.7 + 0.1*o.3 + (-0.8)*(-0.55)
=0.66+0.03+0.44
=1.13 which is greater than 0.

The brain successfully derived a decision for you. It is almost sure that road blocked with a confidence level of 1.13. Did you notice the analysis of Mr.Tom's opinion. You think tom is cheat. So the opposite of what he tells will be right. If you didn't understand the meaning of previous sentence just read one more time because some interesting things hidden in that sentence.

Ok, let's continue our story. Then you started going straight away through short path. You started journey in your own car but Alas! road is blocked. You couldn't just believe your eyes. but suddenly you realize the fact that you can't reach your destination today - you trapped in a huge road block.
Here, your brain attempts to rewire the entire circuitry inside it. Your thoughts were entirely wrong. Both Albert and Deepika was wrong, but Tom was right. You change the congedence level as,
  • Albert - 0.4 - I can't blive he cheated me.
  • Deepika - 0.1 - no coments.
  • Tom - 0.2 - oh, sorry Tom.
The actual working principle of neural networks is far deviated from the above story, but the fundamental thing in both is same. Actual neurons has a lot of diifernces and complexities than the neuron models

Tuesday, December 8, 2009

Go on with pyS60

I got a very good feedback from my previous post: "How to simulate PyS60 in your PC". As the request of opentechlab readers, I am attempting to write a brief beginner level tutorial on pyS60 emulator.

Once you are successful in installing and setting up the environment (If you didn't set up yet, click here), it is the time to go on.

Start the emulator program from:

Start->All programs -> S60 Developer tools -> 3rd edition FP2 SDK -> v1.1 -> Emulator

You probably need to wait for a couple of seconds to load it if your system is slow. Then a medium sized window with a full fledged mobile phone appears on the screen.

Now you need to open python. Just do as in your mobile phone. it's in Menu -> Installations -> python.

Now it's ready and do what you want.

Hacking python script

Select options -> Run script ->ball.py

You can move the ball anwhere in the screen. It's a physics simulation example in python. You can see the actual python script by opening ball.py file using any editor (notepad is not recommended. programmers notepad is good). The file is stored in :

C:\S60\devices\S60_3rd_FP2_SDK_v1.1\epoc32\winscw\c\python

Search for the word 'blobsize'. Then you can find a line like:

blobsize = 16

Change the value of blobsize into 25 and save it. Then open ball.py in emulator. Did you notice any change? Similarly you can change acceleration, gravity (what about changing gravity into -0.01 ?) etc.

Developing your own programs

I am just starting with a hello world. Here is the program.

1)Simple hello world

print "Hello World!"

2)Say, hello world

from audio import*

say("Hello World!")

3)graphical hello world!

import appuifw
appuifw.note(u"Hello World!", "info")

It is good practice to make a short cut of python on the mobile desktop by changing options in settings.

Monday, December 7, 2009

How to simulate PyS60 in your PC

You can do your experiments in PyS60 without touching your mobile phone. The experimentation is easy while you set up everything in your PC. Here I am explaining how to set up the PyS60 environment in WinXP platform. I didn't try this attempt on my Linux yet. I will surely post about it if I get some good mobile stuff on Linux. This will be a boon for python developers in Nokia S60 mobile phones. But rarely it can be seen that some python scripts works neatly on simulator may cause strange responses on your real world system. I would like to here about it if you get any funny experience on your S60 device.
Download the required things:

1)Download S60_3rd_Edition_SDK_Feature_Pack_2_v1_1_en.zipfrom the following link:
http://www.forum.nokia.com/info/sw.nokia.com/id/807ec36d-0a8e-4bda-8e10-4d5e5bb4764a/S60_3rd_Edition_SDK_Feature_Pack_2_v1_1_en.zip.html


2)You can find ActivePerl 5.6.1 build 635 here:
http://downloads.activestate.com/Act...SWin32-x86.msi

3)Download PythonForS60 _1_4_5_SDK_3rdEdFP1.zip from http://sourceforge.net/projects/pys60/files/

First install ActivePerl because S60 SDK requires it.
Then install S60 SDK. Please note to install it in C:\ drive to avoid confusion.
Extract PythonForS60_1_4_5_SDK_3rdEdFP1.zip. Then you get another archived file sdk_files.zip.
Extract it again and you get a directory named 'epoc32'.
Copy this directory into "C:\S60\devices\S60_3rd_FP2_SDK_v1.1"
Then probably Windows XP asks to replace the already existing folder 'epoc32'. Click yes.
You have done. Cheers!

Sunday, December 6, 2009

Don't believe your eyes!


Don't believe your eyes, because everything you see, touch and feel is just a feeling only. Consider you are traveling in a space ship. No way to look outside. Space ship is traveling with higher velocity. If there is an obstacle present in front of the spaceship, sensors feel the presence of obstacle and it is reported on your computer. Then you turn the spaceship left or right. Then sensors feels that obstacle is removed (not obstacle, you!) and computer indicates that you can go straight way.
The above explained is a successful turning. But here I go in a something different way. The sensors are intelligent enough to send a fake signal that "there is some sort of obstacle" on the monitor. Actually, there is nothing in front of it. But your computer shows some obstacle. So you put a signal to turn right. Then the sensors shows that "now obstacle is removed. Go straight". You feel that you done well, but the sensor and the computer system really cheated you. Sometimes it was not a cheating, because ,there will be a possibility of thinking that there is an obstacle.
Our brain is not much different or error free in similar cases. If you are think that you know the universe, I think it is actually bad. Things you feeling from the surroundings may be different from reality. Your eyes are similar to the spaceship sensors. Not only your eyes, every sensors just see one phase of the reality. That really implies that knowing reality is too difficult.
I am not going too inside. I am not a philosopher. So let's have a fun. just go thruogh this link. A number of good eye illusions are included. Here I give a puzzle from eyetricks.com - Find which is longer?

Why there is so many constants in equations?

I will tell you the secret of constants in mathematical equations. They are not intruded or the error or nothing, but it is essential part of the equation. I will tell you some facts while going on your story. I will exemplify what you want in this story.
Consider you are a young scientist. You close your room's door and start experimenting on something when you get leisure time on Sundays. You are doing something seriously on your table, with an electrical circuit. Your aim is to find the dependence of a node voltage X (ie, a voltage in a part of the circuit). You came to know that X depend upon the supply voltage V. You start experimenting and plot graph of X for different values of V. Then you
got a graph like this:
It is perfectly linear. So you write,
X is directly proportional to V
To be more specific, X increases for an equivalent increase in V. You repeated your experiment and plot another characteristics with time. This time, your supply voltage kept constant. Plot X with time t.

From the plot, it easy to find that dependence is,

X is directly proportional to e^(-t)

Then from the above town experiments, you can write that,

X is directly proportional to V*e^(-t)
ie, X = K*V*e^(-t) where a K is the proportionality constant.

You can find K from single experiment. Once you got the value X when for a particular V and t,

K = X/(V*e^(-t)

But I want to tell you that your experiment as well as your mathematical expression is not perfectly true. A true dependence of X on it's environment will be very complex and tedious to express in mathematical form. Your X may depend on the atmospheric pressure, temperature, material properties,...raining in New Delhi,.....war on Iraq and so so.
After several years, you repeated your experiment and find that X depending on temperature also. Temperature has a direct linear relationship (like V) on X. But last time, you didn't got it. What's the reason? You were not aware of that, you did the experiment in room temperature itself. But this time you get different answers in day and chilled night. Now you modify your equation as,

X is directly proportional to V*T*e^(-t) where T is the temperature
X = L*V*T*e^(-t) where L is the proportionality constant.

Here I want a point to stress. Do you think your previous equation was wrong? Not at all. It is correct in an isothermal environment. But it become wrong in a temperature varying environment. A single measurement depending upon many things in the surroundings. But many of them can be ignored, because, they have less relationship with X. Something can't be ignored, but they may not be measurable (such as number of electron collision per second).In such cases, just put a constant for that, as long as they are constants. To be more clear, if your experiment depends upon the radius of earth, just put it as a constant in your equation. But when you do the experiment in moon, your experiment may troubled, unless you replaced the radius of earth with moon. I meant that variables can be considered as a constant or variable according to the environment.