Thursday, 28 January 2016

Optimized server access for vehicle automation using ANDROID

Optimized server access for vehicle automation using ANDROID
G. Anand,
Email id- anandg.embedd@gmail.com,
Mobile No- +91 9994879483



ABSTRACT:
            With the development of technology and the continuous improvement of people's living standard, people are in pursuit of automated, intelligent and convenient control systems. Automation or automatic control is the use of various control systems for operating equipment such as machinery, processes in factories, boilers and heat treating ovens, switching on telephone networks, steering and stabilization of ships, aircraft and other applications with minimal or reduced human intervention. Automation is not completed without wireless communication. Wireless communication is the transfer of information between two or more points that are not connected by an electrical conductor. Nowadays server based remote car control system plays an important role in day-to-day life. In this paper advancement is introduced in remote controlled car using ANDROID mobile phone. Remote control involves controlling the car and tracking the car’s position. The new idea introduced is used to reduce the workload of a server and to reduce the time required. In this method server workloads is reduced by making a communication between user’s mobile phone and the module in the vehicle through internet.
 
INTRODUCTION:
               Nowadays smart phones are becoming more powerful with reinforced processors, larger storage capacities, richer entertainment function and more communication methods. In recent years, an open-source platform Android has been widely used in smart phones. Android has complete software package consisting of an operating system, middleware layer and core applications. Different from other existing platform like iOS (iPhone OS), it comes with software development kit (SDK), which provides essential tools and Application. Android is a mobile operating system (OS), based on Linux kernel and designed primarily for touchscreen mobile devices.
               The Internet is a massive network of networks, a networking infrastructure. It connects millions of computers together globally, forming a network in which any computer can communicate with any other computer as long as they are both connected to the Internet. The World Wide Web, is a way of accessing information over the medium of the Internet. It is an information-sharing model that is built on top of the Internet. An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication. An IP address serves two principal functions: host or network interface identification and location addressing. Its role has been characterized as follows: "A name indicates what we seek. An address indicates where it is. A route indicates how to get there.
   With the help of internet, vehicle can be tracked and controlled using android mobile. A vehicle tracking system combines the use of automatic vehicle location in individual vehicles with software that collects these fleet data for a comprehensive picture of vehicle locations. Modern vehicle tracking systems commonly use GPS technology for locating the vehicle, but other types of automatic vehicle location technology can also be used. Vehicle information can be viewed on electronic maps via the Internet or specialized software. Urban public transit authorities are an increasingly common user of vehicle tracking systems, particularly in large cities.
   Consider the system which consists of vehicle module, server, and mobile phone. In order to track the vehicle’s position remotely, communication between mobile phone and vehicle module is essential. Vehicle module consists of GPRS unit for communication and GPS unit for location identification. Mobile phone should have GPRS facility for the purpose of communication. If the user wants to track the location of the vehicle or to control the peripherals, the communication between mobile and the module in the vehicle is needed. In conventional method every second, mobile communicates with the vehicle module through server. Vehicle unit registers its IP address in the server and mobile phone gets the information from the vehicle unit through server using IP address of the vehicle unit.
PROPOSED SYSTEM
               In this proposed method, there are 2 modules. They are mobile module (i.e.) android app and hardware module. First, the user needs to install the android app in mobile phone. Android app consists of 4 tabs such as vehicle control page, Map view, Registration page, Factors settings to configure the I/O devices to the hardware module.

Fig.1 General Purpose vehicle hardware module
Control tab is used to control peripherals of the vehicle. Map view tab is used to view the vehicle’s current location in map view. Registration page is used to register IP address and port number of the vehicle module in the server. Hardware module consists of GPS, GPRS, ARM processor, and analog input output pins. In order to connect android app and hardware module user should configure the device using TCP/IP protocol. 16 digital I/O and 8 analog inputs in the hardware module are used to establish connection between android app and hardware module. These digital I/O includes door control, engine control, parking lamp control etc. 8 analog input includes fuel level monitoring, air level monitoring, oil level monitoring, etc. User should configure these analog and digital pins by using TCP/IP protocol. The processes involved in the proposed system are classified into 3 stages:
First stage: Registration

Second stage:  (Connection Request)
User (mobile phone) should receive the IP address and port number of the vehicle module through server.

Third stage:  (Connection Establishment)
After getting the IP address, Mobile phone will start to establish connection with the vehicle unit directly without the help of server.


First, vehicle unit register its IP address and port number for the very first time in the server. Mobile phone gets the IP address and port number of vehicle unit through server only once. After getting this IP address and port number from the server, mobile phone truncates the communication with the server and starts to communicate with the vehicle unit directly. Vehicle’s peripheral unit can also be controlled through communication. For example door can closed or opened and AC in car can be switched ON or OFF remotely.  Port number is used for the purpose of simultaneous communication (i.e) more than one user can communicate with the vehicle unit at the same time through different port number. IP address is the one which changes with respect to time. If the IP address of the vehicle changed due to any interruption, then vehicle unit disconnects communication with the mobile phone. Now mobile phone cannot track the location information of the vehicle. To track the location information, again the vehicle unit should register the IP address in the server and the mobile phone must get the IP address and port number again for the purpose of communication between them.
EXPERIMENTAL RESULTS
The developed android app is used to control and track the vehicle remotely. These actions are shown in the figures which have been given below.

Fig.2 Location of a car in map view


Fig.3 Locking the door using android app in mobile phone

Fig.4 Unlocking the door using android app in mobile   phone

CONCLUSION
In this paper, advancement is introduced in android based controlling and tracking the car. This can be implemented to improve the efficiency of the system compared with the conventional system. Surely this method reduces the workload of the server and the time required to do operations.






LCD Library for ARM LPC2148

LCD Library for ARM

Liquid Crystal Display also called as LCD is very helpful in providing user interface as well as for debugging purpose. A liquid crystal display (LCD) is a flat panel display that uses the light modulating properties of liquid crystals (LCs). LCD Modules can present textual information to user.
                    A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD. Click to learn more about internal structure of a LCD.


LCD Open source Header file provides a library for communication with LCDs  through the 4-bit interface. An example of LCD connections is given on the schematic at the bottom of this page.

Note: ARM development system based initialization routines are included in lcd.h.So just  add this header file to  your source code for accessing the LCD  

Note: LCD_Config needs RW for checking the LCD busy and this is tested for LPC2148
Library Routines
  • LCD_Config
  • LCD_Out
  • LCD_Out_Cp
  • LCD_Chr
  • LCD_Chr_Cp
  • LCD_Cmd
LCD_Config
Prototype
void LCD_Config(unsigned short *Dport, unsigned short *port, unsigned short RS, unsigned short EN, unsigned short WR, unsigned short D7, unsigned short D6, unsigned short D5, unsigned short D4);
Returns
Nothing.
Description
Initializes LCD at port with pin settings you specify: parameters RS, EN, WR, D7 .. D4 need to be a combination of values 0–7 (e.g. 3,6,0,7,2,1,4).
Requires
Nothing.
Example
LCD_Config(&IODIR1, &IOPIN1, 0, 1, 7, 5, 4, 3, 2);

LCD_Out
Prototype
void LCD_Out(unsigned short row, unsigned short col, char *text);
Returns
Nothing.
Description
Prints text on LCD at specified row and column (parameters row and col). Both string variables and literals can be passed as text.
Requires
Port with LCD must be initialized. See LCD_Config.
Example
Print “Hello!” on LCD at line 1, char 3:
LCD_Out(1, 3, "Hello!");

LCD_Out_Cp
Prototype
void LCD_Out_Cp(char *text);
Returns
Nothing.
Description
Prints text on LCD at current cursor position. Both string variables and literals can be passed as text.
Requires
Port with LCD must be initialized. See LCD_Config.
Example
Print “Here!” at current cursor position:
LCD_Out_Cp("Here!");

LCD_Chr
Prototype
void LCD_Chr(unsigned short row, unsigned short col, char character);
Returns
Nothing.
Description
Prints character on LCD at specified row and column (parameters row and col). Both variables and literals can be passed as character.
Requires
Port with LCD must be initialized. See LCD_Config.
Example
Print “i” on LCD at line 2, char 3:
LCD_Chr(2, 3, 'i');

LCD_Chr_Cp
Prototype
void LCD_Chr_Cp(char character);
Returns
Nothing.
Description
Prints character on LCD at current cursor position. Both variables and literals can be passed as character.
Requires
Port with LCD must be initialized. See LCD_Config.
Example
Print “e” at current cursor position:
LCD_Chr_Cp('e');

LCD_Cmd
Prototype
void LCD_Cmd(unsigned short command);
Returns
Nothing.
Description
Sends command to LCD. You can pass one of the predefined constants to the function. The complete list of available commands is below.
Requires
Port with LCD must be initialized. See LCD_Config.
Example
Clear LCD display:
LCD_Cmd(LCD_Clear);



Available LCD Commands
LCD Command
Purpose
LCD_FIRST_ROW
Move cursor to 1st row
LCD_SECOND_ROW
Move cursor to 2nd row
LCD_THIRD_ROW
Move cursor to 3rd row
LCD_FOURTH_ROW
Move cursor to 4th row
LCD_CLEAR
Clear display
LCD_RETURN_HOME
Return cursor to home position, returns a shifted display to original position. Display data RAM is unaffected.
LCD_CURSOR_OFF
Turn off cursor
LCD_UNDERLINE_ON
Underline cursor on
LCD_BLINK_CURSOR_ON
Blink cursor on
LCD_MOVE_CURSOR_LEFT
Move cursor left without changing display data RAM
LCD_MOVE_CURSOR_RIGHT
Move cursor right without changing display data RAM
LCD_TURN_ON
Turn LCD display on
LCD_TURN_OFF
Turn LCD display off
LCD_SHIFT_LEFT
Shift display left without changing display data RAM
LCD_SHIFT_RIGHT
Shift display right without changing display data RAM



Example:

#define CCLK     60           //System Frequency should mentioned for LCD
#define lcd_port IOPIN1                 //LCD Port
#define lcd_port_direction         IODIR1  //LCD Direction Port
#include <lpc214x.h>
#include <stdio.h>
#include "lcd.h"                  //LCD Header Files


char *name1 = "Hitech Solutions";
char *name2 = "JAA EmbeddedPark";


void Enable_PLL()
{
PLL0CFG &=~(0x7F);       //For clear 0t06
PLL0CFG |=0x04;                              //External OSC 12MHZ so 60/12 =5-1=4
PLL0CFG |=0x01<<5;      //Multipler and divider setup
PLL0CON=0x01;                //Enable PLL
PLL0FEED=0xAA;              //Feed sequence
PLL0FEED=0x55;
while(!(PLL0STAT & 0x0400)); //is locked?
PLL0CON=0x03;                //Connect PLL after PLL is locked
PLL0FEED=0xAA;              //Feed sequence
PLL0FEED=0x55;

}


int main()

Enable_PLL();
 LCD_Config(&lcd_port_direction,&lcd_port,16,18,17,22, 21, 20, 19);       //4bit LCD configuration

 LCD_Cmd(LCD_CLEAR);       // Clear display
 LCD_Cmd(LCD_CURSOR_OFF);  // Turn cursor off

 LCD_Out(1, 1, name1);      // Print text to LCD, 1nd row, 1st column
 LCD_Out(2, 1, name2);      // Print text to LCD, 2nd row, 1st column

               

 return(0);
}

Download LCD Header File                                                       Download Source Code for KEIL

 This all LCD functions in lcd.h

Thursday, 21 January 2016

UART Library for ARM LPC2148


UART Library

UART hardware module is available with a number of ARM. UART Library provides comfortable work with the Asynchronous (full duplex) mode.
 
The ARM7 LPC2148 Primer board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through serial port.

NXP’s ARM7 (LPC2148), ARM Primer Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 32-bit Microcontrollers.

UART

UART (Universal Asynchronous Receiver Transmitter) are one of the basic interfaces which provide a cost effective simple and reliable communication between one controller to another controller or between a controller and PC.

RS-232 Level Converter

Usually all the digital ICs work on TTL or CMOS voltage levels which cannot be used to communicate over RS-232 protocol. So a voltage or level converter is needed which can convert TTL to RS232 and RS232 to TTL voltage levels. The most commonly used RS-232 level converter is MAX232.

This IC includes charge pump which can generate RS232 voltage levels (-10V and +10V) from 5V power supply. It also includes two receiver and two transmitters and is capable of full-duplex UART/USART communication.

  • RS-232 communication enables point-to-point data transfer. It is commonly used in data acquisition applications, for the transfer of data between the microcontroller and a PC.
  • The voltage levels of a microcontroller and PC are not directly compatible with those of RS-232, a level transition buffer such as MAX232 be used.

UART hardware module is available with a number of ARM. UART Library provides comfortable work with the Asynchronous (full duplex) mode. LPC2148 has two serial ports. Here two serial port function do with UARTx . ‘x’ indicates 0 and 1.

You can easily communicate with other devices via RS232 protocol (for example with PC, see the figure at the end of the topic – RS232 HW connection). You need ARM MCU with hardware integrated UART, for example LPC2138. Then, simply use the functions listed below.
Library Routines
  • UART0_Ini t / UART1_Init
  • UART0_Ready / UART1_Ready
  • UART0_Read / UART1_Read
  • UART0_Write / UART1_Write
  • UART0_Text / UART1_Text
  • UART0_Read_Size / UART1_Read_Size 
  • UART0_Read_CMD / UART1_Read_CMD

UART_Init
Prototype
void UART_Init(const unsigned int  baud_rate);
Returns
Nothing.
Description
Initializes hardware UART module with the desired baud rate. Refer to the device data sheet for baud rates allowed for specific Fosc. If you specify the unsupported baud rate, compiler will report an error.
Requires
You need ARM MCU with hardware UART.
Usart_Init needs to be called before using other functions from UART Library.
Example
This will initialize hardware UART and establish the communication at 2400 bps:
UART0_Init(2400);
UART_Ready
Prototype
unsigned short UART_Data_Ready(void);
Returns
Function returns 1 if data is ready or 0 if there is no data.
Description
Use the function to test if data in receive buffer is ready for reading.
Requires
UART HW module must be initialized and communication established before using this function. See UART_Init.
Example
If data is ready, read it:
char receive;
...
if (UART0_Ready()) receive = UART0_Read;
UART_Read
Prototype
unsigned short UART_Read(void);
Returns
Returns the received byte. If byte is not received, returns Last Received Byte.
Description
Function receives a byte via UART. Use the function UART_Ready to test if data is ready first.
Requires
UART HW module must be initialized and communication established before using this function. See UART_Init.
Example
If data is ready, read it:
char receive;
...
if (UART0_Ready()) receive = UART0_Read();
UART_Write
Prototype
void UART_Write(unsigned short data);
Returns
Nothing.
Description
Function transmits a byte (data) via UART.
Requires
UART HW module must be initialized and communication established before using this function. See UART_Init.
Example
char chunk = 0x1E;
UART0_Write(chunk);    /* send chunk via USART */
UART_Text
Prototype
void UART_Text(unsigned char *data);
Returns
Nothing.
Description
Function transmits a string via UART. If null detected terminate the sending.
Requires
UART HW module must be initialized and communication established before using this function. See UART_Init.
Example
char *text = “Hello Universe”;
UART0_Write(text);    /* send string via USART */

UART_Read_Size
Prototype
char* UART_Read_Size (unsigned char *destination, unsigned short size );
Returns
Input destination address.
Description
Function read string by size via UART. Automatically add null to end location
Requires
UART HW module must be initialized and communication established before using this function. See UART_Init.
Example
char text[20];
UART0_Write(text,5);    /* Receives 5charcter via USART */
UART_Read_CMD
Prototype
char* UART_Read_CMD (unsigned char *destination, unsigned short CMD );
Returns
Input destination address.
Description
Function read string by byte (char) command via UART. Automatically add null to end location
Requires
UART HW module must be initialized and communication established before using this function. See UART_Init.
Example
char text[20];
UART0_Write(text,’?’);    /* Receives character until ‘?’ via USART */

Example
#define CCLK      60//System Frequency should mentioned for LCD header
#define PCLK      30//Peripheral Frequency should mentioned for UART header
#include <lpc214x.h>
#include <stdio.h>
#include "UART.h"   //UART Header Files
char *name = "Hitech Solutions";
void delay(unsigned int n) ;
void Enable_PLL()
{
PLL0CFG &=~(0x7F);      //For clear 0t06
PLL0CFG |=0x04;         //External OSC 12MHZ so 60/12 =5-1=4
PLL0CFG |=0x01<<5;      //Multipler and divider setup
PLL0CON=0x01;     //Enable PLL
PLL0FEED=0xAA;    //Feed sequence
PLL0FEED=0x55;
while(!(PLL0STAT & 0x0400)); //is locked?
PLL0CON=0x03;     //Connect PLL after PLL is locked
PLL0FEED=0xAA;    //Feed sequence
PLL0FEED=0x55;
VPBDIV=0x02;      //peripheral bus runs 2 times slower
}
int main()
{ 
char text[20];
Enable_PLL();
 UART0_Init(9600); //Init UART0 for 9600 baud
 delay(100);
 UART1_Init(9600);      //Init UART1 for 9600 baud
 delay(100);
 UART0_Write('0');      //Write character to UART0
 UART1_Write('1');         //Write character to UART1
 UART0_Text(name);         //Write string to UART0
 UART0_Write(0x0d);        //Write line feed
 UART0_Write('\n');
 UART0_Text(">>");         //Write String
 UART0_Read_Size(text,5);     //Read String by size
 UART1_Text(text);            //   Write readed string to UART1
 UART0_Text(">>");            //Write String
 UART0_Read_CMD(text,0x0d); //Read String by Command
 UART1_Text(text);            //   Write readed string to UART1
 do{
 if(UART0_Ready())
      UART1_Write(UART0_Read());
   }while(1);
 return(0);
}
void delay(unsigned int n)
{  
 unsigned int i,j;  
 for(i=0;i<n;i++)   
   for(j=0;j<12000;j++);
}



 HW Connection

Download UART Header File                                                  Download Sourcecode for KEIL

This are all UART Functions in UART.h