Autoit

Autoit

Τρίτη 12 Ιουνίου 2012

Tutorial for Arduino Simulator

What is Arduino Simulator?
    Arduino Simulator is a program written in the AutoIt scripting language which simulates the
behaviour of the Arduino Prototyping Platform.

When to use Arduino Simulator?
     With Arduino simulator you can test the projects (.nag file) that has been created with "Arduino GUI Programmer"

How to use Arduino Simulator
    In order to test a .nag project you must first execute the program. Then navigate to "File --> Open"
and select the project you want to test.
The program will automatically create the appropriate pins and the window will look something like this:
As you see on the right side of the window is a ListView that displays the project rules, so that the user can check on them.
On the left side of the window you can see that there is a label on each pin that shows the type of the pin DI,  DO etc...). Also there is label or input box that shows the state of each pin (LOW, HIGH etc....).And the color of each pin represents the state of each pin:
Red for LOW
Green for HIGH
Blue for analog pins
After that press the "RUN" button to start the simulation
By pressing the button next to the Digital Input toggles the state of the pin from Low to High and vice versa.
By pressing the Up_Down control or pressing the UP DOWN keys on keyboard changes the value of the Analog Inputs. The user can also enter the value manually.
The state and value of the Output Pins will be automatically updated depending the Project Rules.
With the "STOP" button the simulation ends.
The program will not exit when the simulation is active, so first you must press the "STOP" button and then Exit the Program.

Tutorial for Arduino GUI Programmer

What is Arduino GUI Programmer?
    Arduino GUI Programmer is a program writen in the AutoIt scripting language which provides a graphical interface (GUI) for programming the Arduino prototyping platform.

Who will use Arduino GUI Programmer?
    Arduino GUI Programmer provides an easy and simple interface for those who want to use the Arduino platform in simple projects, but don't want to learn the Arduino programming language.

Why use Arduino GUI Programmer?
    Arduino's GUI Programmer main advantages are:
1.Program is fully portable. No installation required, the hall program is one executable (.exe) file.
2.Doesn't require any configuration in order to start programming
3.Doesn't consist of multiple tabs and pages, everything is on one window.
4.Everything is very simple to understand and work
5.Program automatically enables, disables and updates the data of certain controls, guiding the user and preventing errors and mistakes.
    Arduino's GUI Programmer main disadvantages are:
1.Program doesn't take full advantage of the Arduino's capabilities. Doesn't support serial or ethernet control
2.Program writes the generated code in a text file and doesn't upload directly to the platform, so the user must copy the generated code to the Arduino programming software before uploading.

Menu Quick Review
- File menu: Under the "File Menu" are the following options:
        1) New : Create a new project.
        2) Save : Save the current project.
        3) Save As : Save the current project with a different name.
        4) Open : Open an existing project.
        5) Exit: Quit and close the project.
- Tools menu: Under the "Tools Menu" are the following options:
       1) Boolean Calculator: A Calculator like window, by which the user can create rules by writting a Boole's expression.
        2) Boolean Truth Table (2 Inputs): A GUI window for creating rules by filling up a Truth Table.
        3) Boolean Truth Table (custom Inputs): A generalized version of the previous tool.
- Help menu: Under the "Help Menu" are the following options:
       1) About: Shows information for the program
       2) How To: Display this Tutorial.


Pin Settings:
In this section of the program the user can set the type of each pin by sellecting the appropriate one from a drop-down menu. There are 4 different pin types:
 1) DI - Stands for "Digital Input" and can hold the values "High" or "Low". All pins can be declared as DI.
 2) DO - Stands for "Digital Output" and can hold the values "High" or "Low". All pins can be declared as DO.
 3) AI - Stands for "Analog Input" and can hold a value from "0" to "1024". Only pins A0, A1, A2, A3, A4, A5 can be declared as AI.
 4) AO - Stands for "Analog Output" and can hold a value from "0" to "255". Only pins 3, 5, 6, 9, 10, 11 can be declared as AO.
The options available inside the combo box for each pin are the ones that the specific pin can take. Therefore it is impossible for the user to make a mistake in pin types. For example "Pin_2" cannot be set as AO or AI.
Also a unique name can be set to each pin for convenience in rule creation.

Another thing in this section is the "Submit" and the "Clear Settings" Button.
 1) Submit : This button "registers" the type and name of each pin into programs memory.
 2) Clear Settings: When this button is clicked another window pops, prompting the user to select an action.
        - Clear All : This action clears the Settings and the applied Rules. Basically "reset's" the project.
        - Clear Rules: This action clears all the applied Rules leaving the Settings as is.
        - Clear UnSubmitted: This action clears all the Settings that have not yet been used in a Rule. Notice that the Settings that are in use, cannot be cleared or changed because there would be a confusion in the Rules.
        - Cancel: Close the window and do nothing.

Rule Creation Methods:

A) Standard Method :
     This method is accomplised by using the combo boxes at the bottom side of the Program.
     By using this method the user can take full advantage of the programs capabilities. In order to explain how to create a Rule,  we must first explain what is a Rule and the parts that compose one.
     What is a Rule?
       Rule is an expression between inputs and output that detemines the state or value of the output. For example : "Switch Is High => Lights Is High". This is a "single input Rule" that says to turn the lights on when the switch is pressed. An example of a "dual input Rule" is: "Switch Is High AND day_sensor Is Low => Lights Is High". This Rule states that the lights would be turned on when the switch is pressed and the light sensor says that is dark.
     Parts of a Rule
       A Rule is composed by 7 parts.

       1) Rule number : A serial number unique for each Rule. The first Rule is Rule_0, the second is Rule_1 and so on......
       2) Input A : A group of combo boxes which represents the first input. An inputs is composed of three sub_parts:
             a) Input Pin : Is the Pin to monitor as input. Can be every pin that has been declared as DI or AI
             b) Input Comparator : Is the action to examine in the pin. Can be one of the following:
                                                           - ( = equal to )           => Equal to a value
                                                           - ( > greater than )     => Greater than a value
                                                           - ( < less than )          => Less than a value
                                                           - ( >= greater/equal ) => Greater or equal to a value
                                                           - ( <= less/equal )      => Less or equal to a value
                                                           - ( <<>> compare )   => Compare to another analog pin
            c) Input Value : Is the value of the input. Can be either "High", "Low", a number between 0 and 1024 and an expression when the "Compare" function is selected (further analysis in the Compare Function)
       3) Inputs Comparator : A logic action between the 2 inputs (AND or OR)
       4) Input B : Same as Input A.
       5) Output :  A group of combo boxes representing the "Output" of the Rule. Similar to the inputs, the output is composed of 3 sub_parts:
             a) Output Pin: Is the pin to manipulate. Can be every pin that has been declared asDO or AO. Also there two special types of outputs :
                      i) Virtual_Coils : Which are , like "Virtual" Pins that can be used to store the state of multiple pins in one.
                      ii) Counters : Which are like "virtual" variables and can be used to count or store values.
             b) Output comparator: Is the action that the Output pin will do.Can be one of the following:
                                                           - ( = equal to )           => Equal to a value
                                                           - ( f(x)  expression)    => Available only for AO pins. Is used to set a "depending" output Value. eq. Half of the value of an input.
                                                           - ( + Increase by )     => Increases the value of a Counter.
                                                           - ( + Decrease by )    => Decreases the value of a Counter.
                                                           - ( = Set to )              => Set the value of a Counter to a fixed value.
             c) Output Value : The value or state, the Output would take. Can be either "High" or "Low" or a numeric value or an expression.
        6) Delay : A numeric value that represents the time in milliseconds that the Output would delay.
        7) Comments : Simple comments that the user can set for convinience.

Special Functions on Rule creation
1) Compare Function:
When the "<<>> Compare" option is selected the following window will pop.








On this window the user can select the pin to compare to, and the action for the comparison.
2) f(x) - Expression Function
When the "f(x) expression" option is selected the following window will pop.










On this window the user can select the pin to use as "base" for the value of the output.

 Examples of Rule creation using the Standard Method.
     A) Turn ON-OFF lights with a switch.
Two rules are required for this example:
1 - "Switch = High => Lights = High"
2 - "Switch = Low => Lights = Low"


     B) Turn ON-OFF the air-condition when the temperature is over 30'C and a switch is ON.
Two rules are required for this example:
1 - "Switch = High AND temperature > 30 => air-condition = High"
2 - "Switch = Low OR temperature <= 30 => air-condition = Low"



















































Manage Projects
    Arduino GUI Programmer can manage many projects which can be saved and processed at a later time.
Each project can be saved in a single (.nag) file. To save a project navigate to "File -->Save" or
"File -->Save as". To create or open an existing project navigate to "File --> New" or "File --> Open"
The name of a new project is by default "untitled". When executing Arduino GUI Programmer a new project
is by default oppened.

Set Pin Settings - Submit button
     After execute Arduino GUI Programmer,  user must set the "Pin Settings". Each Pin can be declared
as Digital Input (DI) or Digital Output (DO). Certain pins are able to be declared as different types also:
Pins 3,5,6,9,10 and 11 can also be declared as Analog Outputs (AO).
Pins A0,A1,A2,A3,A4,A5 can also be declared as Analog Inputs (AI).
The user can also assign a unique name to each pin, so that the pin will be easily recognisable.
Below is an example of Pin settings:

The available settings in each pin are the ones that each pin can be declared at.
If the user doesn't enter a name to a pin then the program automatically assigns one.
When user is done with Pin settings then must press the "Submit" button το register the settings.
By pressing the submit button, the program disables the declared pin, to prevent user from making
accidental changes.

Clear - Change Settings
     Changes at the Pin Settings are not possible after a setting has been submitted. The reason is that
if a pin has been used in a Rule and user change it's type (from DI to DO) or it's name, the program
may crash or generate faulty results. So in order to delete-change a pin setting that has been submitted
, the so far apllied rules must be deleted as well.
When the button "Clear Settings" is clicked then another window pops up.
The choises are:
"Clear UnSubmitted" clears the pin settings that have not yet been submited.
"Clear All" clear all the Pin Settings submitted or not. Also will clear all the rules that have been applied
so far. So the "Clear All" button basically "resets" the project.

Rule Creation
    The program's Rules can be created at the "rule combos" as shown below:

When user selects the pin, which is the top of the three combos in each input, then the other 2 combos
will automatically update to give the user the appropriate options.
Changes at the values and pins are possible, also the "Clear Rule" button clears all the combo boxes
to create the rule from scratch.
After the rule is completed the "Apply Rule" button must be clicked to register the rule.

Opposite Rules
     An opposite rule is a rule that functions exactly the opposite way from a given rule.
For example if a rule is : 




The opposite Rule would be :




The "Auto Create Opposite Rule" Check box.
Allows to the program to automatically create an "opposite" Rule,  so that the user don't have to.
The "Auto Create...." feature works only if a new rule is apllied and not when modifying an existing one.

Modify - Delete an apllied rule
   A user can modify or Delete an apllied rule by selecting the appropriate number on the "rule count"
combo and clicking on "Load Rule" or "Delete Rule" button.


After Modification the "Apply Rule" button must be clicked to register the changes.

Generate Code
     After the rules are completed Press the "Generate Code" button to create a .txt file with the Arduino code. The generated file is named after the current project.






Τετάρτη 7 Μαρτίου 2012

Remote File Open using Autoit

Well here is the situation.
I have a pc connected to my TV in the leaving room. Also i allways have a netbook close to me.
The bluetooth keyboard-mouse i use on the pc is not very convenient. So i want to navigate to a youtube video or a media file on my NAS from my netbook and view it on my TV. I searched all over internet for such a program but couldn't find anythink good. So i desided to make an autoit script that could do exactly that.
In order for the program to work you must execute it from a shared folder in the pc.
After that i search what i want to view (youtube video or file on my NAS) from my netbook and using the same script i "send" the link to my pc.
The script has the abillity to send each link to more than one pc's at the same time. So i found a good use for it in my office. When i see an interesting site on the internet i send the link to my coworkers pc's and the site automatically opens on their pc's to. Of course there is a security isue when trying to send an executable file, but in such a case a confirmation window pops up asking for the user to execute the file or not.
The script also has the ability to send simple commands to the host pc for example go to full screen and thnks like that.

The source code and a compiled executable can be downloaded from here:

Enjoy and remember "Coding can be fun when you do it your own"

Παρασκευή 24 Φεβρουαρίου 2012

Gmail Checker using Linux Bash

What do you usually do when you want to check your mail ? Propably the answer is "I open a browser and navigate to gmail". Well this is what i usually do also, but sometimes i want to check my mail with another way. So i wrote a Bash Shell script that does exactly that, checks my gmail acount and outputs the results on the screen. The way the script works is similar with another script i made the "Gmail Commander".
I know that Gmail Checker is a very simple script and not so usefull but it can be downloaded from here:
Enjoy

Aaaaaaaaaaaa, not to forget "Coding can be fun when you do it your own"

Δευτέρα 20 Φεβρουαρίου 2012

Gmail Commander using Linux Bash

Have you ever been in a situation where you are away from your home or office Linux computer
and you want a simple information from it, you just want to execute one line of code in command line and get the return? Well if you have, you know that in order to do so there should be a port forwarding enabled in your router, an ssh server running in your Linux computer and an ssh client (ex. putty.exe) installed in the computer you are temporarly at. With "Gmail Commander" you don't have to go through all that trouble, you simple send a mail in your gmail acount with the code you want to be executed and in a few moments you get another mail with the return of that command. How cool is that.
"Gmail commander" is a simple bash shell script that can run in every machine that has Linux and a network connection. Unfortunately in order for the script to run correctly you should set up your computer to be able to send mails from the command line, but don't worry i'll post another script that does exactly this.
"Gmail commander" monitors your mail inbox using this web page "https://mail.google.com/mail/feed/atom"
(This is a web page that shows only your unread mails. It shows only the subject, author and time of a mail)
When "Gmail commander" spots that there is mail in which the subject begins with "remote_command", then checks if the author of that mail is your self (this is done for security reasons), after all that, executes the command that is in the subject and mails back the reurn.
The mails subject should be in the form "remote_command:actual command" (without the quotes)
For example if you want to view the files in your Desktop you simply send a mail with a subject :
remote_command:ls /home/user/Desktop/
You can download the install_ssmtp.sh and gmail_commander.sh from here
untar in a folder and execute install_ssmtp.sh, then execute gmail_commander.sh
Enjoy and allways remember "Coding can be fun when you do it your own"

Κυριακή 19 Φεβρουαρίου 2012

Power Server using Linux Bash

We all have heard of various types of servers (mail server, DHCP server etc...), but what is a "Power Server"? Well the answer is simple. Power server is a script that checks the power (AC 230V) on our home or office and shuts down network computers when there is a power failure. Of course someone could say "isn't that feature allready embedded on a simple-local UPS ?"
Well ... Of course it is, but think all the trouble to set it correctly.
First you have to connect the UPS with each PC usually with a USB cable, then you must install the UPS software on every PC, after that you have to configure that software on every single computer on the network and last but not least, every now and then you must check that the software is running correctly and it has not been disabled by the PC's user because he or SHE didn't know what that tray icon is for.
All you need to run the "Power server" is a cheap laptop which is running a version of linux with "bash shell" and has a network connection (practicaly every laptop of the last 5 years). All the computers and network switches must be powered from UPS. The laptop that serves as the "Power server" must NOT be powered from UPS.

The way the script works is simple:
-------------------------------------------------------------------------------------------------
First check if the AC adapter is off-line
__if so wait for 30 sec and check again (in order to avoid action in a brief loss of power)
____if power is down after second check then
______send the shutdown command to the network computers
______log the power loss and
______store that the computers have been shutdown
____if power is on-line the second check then
______log it as a brief lose of power
If the ac-adapter is on-line then
__if the computers have been previously shutdown then
____wake the computers that must be allways on-line (NAS, server etc...)
____log that the power is on-line again and
____store that the computers have not been previously shutdown
__if the computets have not been previously shutdown
____display an "everythink is OK" message
-------------------------------------------------------------------------------------------------
Of course you can add some extra features like sending you an email on power fail and thinks like that.

You can Download the code from here:
-untar the file, make the necessary changes to the file remote_server.sh according your network using vi or nano and then execute the file remote_server.sh

I am sure that there are better and more sophisticated ways of doing all this power management but i had a good time exploring bash shell coding.
Always remember "Coding can be fun when you do it your own."