Blogger Themes

Search This Blog

www.embeddedstudy.com | Copyright © 2017 | All Rights Reserved | Nithin Pradeep . Theme images by Storman. Powered by Blogger.

Popular KOZHI

Sponsor

Download

Blogger Tricks

FEATURED

What is an Embedded System?

An embedded system is a combination of hardware and software that is designed to carry out a certain task or tasks, meaning it has a s...

JOIN THE TEAM

Popular Posts

Wikipedia

Search results

Search This Blog

Social

More Links

Social

ad

ads

Tuesday, 29 August 2017

How to Install Raspbian Os Jessie On Raspberry Pi 3 and Connecting Pi to Linux

- No comments

Hello all..
Today i will show you how to install Os On Raspberry Pi and connect it to Linux OS..
First of all you need following items.. You can get these from studyembedded.com/Hot Stuffs!/Electronic Shop

  • Raspberry Pi 2/3
  • 16 GB Micro SD Card and Card Reader
  • RJ 45 Ethernet Cable
  • 5v 1A charger (Mobile Phone charger will do..)
Next you need to Download Raspbian OS by clicking this link
https://downloads.raspberrypi.org/raspbian_latest

After downloadig copy that zip file in to another folder and Extract it by using following command

unzip 2017-06-21-raspbian-jessie.zip
Wait for the inflaing to be finished,
you will get an img image file.

Now connect SD card to your computer using an SD Card reader.
Format the memory card if something is present in the card,
To copy to it we need to unmount the card first ,
Follow the steps below.
umount /media/boot
unmount the listed memory card

install the OS by Copying the img file to SD card by running the following command in the same directory where the image file is present

sudo dd bs=8M if=2017-06-21-raspbian-jessie.img of=/dev/sdb

wait for the process to complete this may take 15-30 minutes to complete.
you can check the status ie, how much data is copied by running the following command.

du-h 2017-06-21-raspbian-jessie.img

After it is finished insert the SD Card to Raspberry Pi and connect RJ 45 cable to it and connect the other end to laptop
connect the power cable also to Raspberry Pi and power it
You can see the green Led in Raspberry Pi is glowing which indicates that Operating system is loading and Red LED indicates Pi is On.


it's all done now,

Now we need to connect the Pi to our Linux ,For this use ssh connection 
set up the connection by  clicking Edit connections.. from the network tab in Linux.
 click add select ethernet







Give Connection name as Raspberry Pi and click IPv4 Settings

 in Methods select Shared to other computers
Click Save 
 The Ethernet symbol (first one)Indicates that the connection is successful 

Now for  Logging in to Raspberry Pi,
  1. Open a terminal
  2. type     cat /var/lib/misc/dnsmasq.leases 
     3.Here 10.42.0.55 is my ip address for Raspberry pi(Yours might be different)
     4.Type ssh 10.42.0.55 -l pi    (use your ip)
      5 .provide yes in the next step
     6. Provide password as   raspberry  when it is asked .

that's it you have successfully logged on to Raspberry Pi....

  
          
          
 

Saturday, 26 August 2017

Digital Lock Using Arduino

- No comments
Digital code locks are most common on security systems. An electronic lock or digital lock is a device which has an electronic control assembly attached to it. They are provided with an access control system. This system allows the user to unlock the device with a password. The password is entered by making use of a keypad. The user can also set his password to ensure better protection.

In this project major components include a keypad, LCD and the controller Arduino. This article describes the making of an electronic code lock using arduino.

Components Required

The following components are required for making the digital code lock
  1. Arduino Uno
  2. 16x2 LCD Display
  3. 4x4 keypad
  4. Relay
  5. 1K Resistors Qty. 3
  6. BC548
  7. LEDs

Digital Code Lock Circuit

Code lock circuit is constructed around Arduino Uno, using LCD and keypad. 

LCD and keypad forms the user interface for entering the password and displaying related messages such as “Invalid password”, “Door open”, etc. 

Two LEDs are provided to indicate the status of door whether it is locked or open. To operate latch/lock we are using Relay which can be connected to the electronic actuator or solenoid.


Program Code for Arduino Digital Code Lock

Program is constructed using two libraries “LiquidCrystal” and “Keypad”. 

Program have different modules, Setup, Loop, Lock. 

In setup we initialize all the IO connections and LCD, Keypad. 

In main loop we are taking pressed keys in array “code[]”, Once the four digits are entered we stop accepting keys. 

We are using numeric keys and ‘C’ , “=” key. ‘C’ key is used to lock or clear the display incase wrong password is entered. 

We can hide the entered password by putting Star character ‘*’.

After entering password ‘=’ key acts as ok. If password is correct door is kept unlocked for few seconds. If it is incorrect message will be displayed.

/* Digital Code Lock Demo */
#include <Keypad.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd (9, 8, 7, 6, 5, 4);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys [ ROWS ][ COLS ] = {
{'7','8','9','/'},
{'4','5','6','*'},
{'1','2','3','-'},
{'C','0','=','+'}
};
byte rowPins [ ROWS ] = {3, 2, 19, 18}; //connect to the row pinouts of the keypad
byte colPins [ COLS ] = {17, 16, 15, 14}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad ( makeKeymap ( hexaKeys ), rowPins , colPins , ROWS ,
COLS );
const int LED_RED =10; //Red LED
const int LED_GREEN =11; //Green LED
const int RELAY =12; //Lock Relay or motor
char keycount =0;
char code [4]; //Hold pressed keys
//=================================================================
// SETUP
//=================================================================
void setup (){
pinMode ( LED_RED , OUTPUT );
pinMode ( LED_GREEN , OUTPUT );
pinMode ( RELAY , OUTPUT );
// set up the LCD's number of columns and rows:
lcd . begin (16, 2);
// Print a message to the LCD.
lcd . print ("Password Access:");
lcd . setCursor (0,1); //Move coursor to second Line
// Turn on the cursor
lcd . cursor ();
digitalWrite ( LED_GREEN , HIGH ); //Green LED Off
digitalWrite ( LED_RED , LOW ); //Red LED On
digitalWrite ( RELAY , LOW ); //Turn off Relay (Locked)
}//
=================================================================
// LOOP
//=================================================================
void loop (){
char customKey = customKeypad . getKey ();
if ( customKey && ( keycount <4) && ( customKey !='=') && ( customKey !='C')){
//lcd.print(customKey); //To display entered keys
lcd . print ('*'); //Do not display entered keys
code [ keycount ]= customKey ;
keycount ++;
}
if(customKey == 'C') //Cancel/Lock Key is pressed clear display and lock
{
Lock (); //Lock and clear display
}
if(customKey == '=') //Check Password and Unlock
{
if(( code [0]=='1') && ( code [1]=='2') && ( code [2]=='3') && ( code [3]=='4')) //Match the
password. Default password is “1234”
{
digitalWrite ( LED_GREEN , LOW ); //Green LED Off
digitalWrite ( LED_RED , HIGH ); //Red LED On
digitalWrite ( RELAY , HIGH ); //Turn on Relay (Unlocked)
lcd . setCursor (0,1);
lcd . print ("Door Open ");
delay (4000); //Keep Door open for 4 Seconds
Lock ();
}
else
{
lcd . setCursor (0,1);
lcd . print ("Invalid Password"); //Display Error Message
delay (1500); //Message delay
Lock ();
}
}
}
//=================================================================
// LOCK and Update Display
//=================================================================
void Lock ()
{
lcd . setCursor (0,1);
lcd . print ("Door Locked ");
delay (1500);
lcd . setCursor (0,1);
lcd . print (" "); //Clear Password
lcd . setCursor (0,1);
keycount =0;
digitalWrite ( LED_GREEN , HIGH ); //Green LED Off
digitalWrite ( LED_RED , LOW ); //Red LED On
digitalWrite ( RELAY , LOW ); //Turn off Relay (Locked)
}

Friday, 25 August 2017

Files In Python

- No comments
In todays section we will see how we can create and do some operations on a file.
to see the list of supported functions type dir(file) in prompt.
see the following code below and understand.,I have created a dummy file called data (vi data) and it has following contents in it.

create a file called p1.py and type the following code:
#! /usr/bin/python
fh=open('data','r')
print fh.close                              #will print false because file is openprint fh.mode                               #will print mode of file that is open                   print fh.name                              #will print name of file that is open
print fh.fileno()                              #will give default file descriptor that is openfh.close()                              #will close file
The program will give output as
False
r
data
3
 

Reading contents of a file

fh.read()

fh.readlines() will give each lines in list format.

>>> print fh.readlines()
['Hello all\n', 'Good morning\n', 'welcome to embeddedstudy.com\n', 'How is the weather today\n', '123456789\n', '\n']

ASSIGNMENTS

  • Write a program to print contents of file word by word
  • Write a program to implement wc command along with file name
  • Write a program to implement head  and tail command (head command will print first 10 lines in a file by default and tail will print last 10 lines)
 

Writing contents to a file

fh.write()

 The first  code will create a file and write data inputed to the file after creating data1.
Second will write line by line to the file from list after creating data1.

Taking Arguments from command line


we need to give command line argument as:
 output will be like:
0      -first fh.tell() will give starting of file pointer
10   - after reading 10 lines pointer points to 10th place.
88   -fh.seek() is same like fseek in c ,second argument 2 means position is at end
83  -seeking 5 position backwards from the end.

In the next section we will discuss about Regular expressions in Python...
 
 <<Previous                                                                                                                                     Next>>

Creating Modules in Python

- No comments

In this section we will discuss how to create module in Python...

what is a module?

module is a Python object with arbitrarily named attributes that you can bind and reference. Simply, a module is a file consisting of Python code. A module can define functions, classes and variables. A module can also include runnable code.

See the following program

We are creating 2 modules one for (cal_c.py)arithmetic operations like add,subtract,... and other for finding power(math_c.py).


math_c.py

cal_c.py

project.py
The program will prints output as
 30
25
27
10

in shell....




A pyc file is created after impporting..
We have to create .pyc file for security purposes since in python application it self is cource code.It is automatically created for modules and packages but not for normal files,
else we can create like this.
python -m py_compile p2.py
this p2.pyc is called as byte code or frozen binary.





LIST 

 l.reverse(l.sort) - will print list in reverse order
 l.append(subl)
>>> l
[1, 2, 3, 60, 4, 5, 6, 500, [100, 200, 300]]

this will append whole list

>>> l.extend(subl)
>>> l
[1, 2, 3, 60, 4, 5, 6, 500, [100, 200, 300], 100, 200, 300]

 
this will append only list elements as individual,ie it needs itrative items

l.append(123) works but l.extend(123) will give error.
 l.pop() will pop data from list and will give return value also.

 l.remove(3)- removes first occurance of 3.
lets see..
ASSIGNMENT
Write a program to delete all occurance of given number from list.


l1=l implies that l1 is reference to l.
del command will delete a perticular member .

  • how to print a perticular character from a list.to print 't' and [20,30] from [10,'Nithin',20,[10,20,30]]  


in the next section we will discuss about list comprehension...

<<previous                                                                                                                                Next>>

Thursday, 24 August 2017

LIN PROTOCOL Introduction & overview

- No comments

LOCAL INTERCONNECT NETWORK
LIN


INTRODUCTION

 Many mechanical components in the automotive sector have been replaced or are now being replaced by intelligent mechatronical systems. A lot of wires are needed to connect these components. To reduce the amount of wires and to handle communications between these systems, many car manufacturers have created different bus systems that are incompatible with each other. In order to have a standard sub-bus, car manufacturers in Europe have formed a consortium to define a new communications standard for the automotive sector. The new bus, called LIN bus, was invented to be used in simple switching applications like car seats, door locks, sun roofs, rain sensors, mirrors and so on. The LIN bus is a sub-bus system based on a serial communications protocol. The bus is a single master / multiple slave bus that uses a single wire to transmit data. To reduce costs, components can be driven without crystal or ceramic resonators. Time synchronization permits the correct transmission and reception of data. The system is based on a UART / SCI hardware interface that is common to most microcontrollers. The bus detects defective nodes in the network. Data checksum and parity check guarantee safety and error detection. As a long-standing partner to the automotive industry, STMicroelectronics offers a complete range of LIN silicon products: slave and master LIN microcontrollers covering the protocol handler part and LIN transceivers for the physical line interface. For a quick start with LIN, STMicroelectronics supports you with LIN software enabling you to rapidly set up your first LIN communication and focus on your specific application requirements.




Network topology

LIN is a broadcast serial network comprising 16 nodes (one master and typically up to 15 slaves).
All messages are initiated by the master with at most one slave replying to a given message identifier. The master node can also act as a slave by replying to its own messages. Because all communications are initiated by the master it is not necessary to implement a collision detection.
The master and slaves are typically microcontrollers, but may be implemented in specialized hardware or ASICs in order to save cost, space, or power.
Current uses combine the low-cost efficiency of LIN and simple sensors to create small networks. These sub-systems can be connected by back-bone-network (i.e. CAN in cars).

Overview

The LIN bus is an inexpensive serial communications protocol, which effectively supports remote application within a car's network. It is particularly intended for mechatronic nodes in distributed automotive applications, but is equally suited to industrial applications. It is intended to complement the existing CAN network leading to hierarchical networks within cars.
In the late 1990s the Local Interconnect Network (LIN) Consortium was founded by five European automakers, Mentor Graphics (Formerly Volcano Automotive Group) and Free scale(Formerly Motorola, now NXP). The first fully implemented version of the new LIN specification was published in November 2002 as LIN version 1.3. In September 2003 version 2.0 was introduced to expand configuration capabilities and make provisions for significant additional diagnostics features and tool interfaces.
The protocol’s main features are listed below:
  • Single master, up to 16 slaves (i.e. no bus arbitration). This is the value recommended by the LIN Consortium to achieve deterministic time response.
    • Slave Node Position Detection (SNPD) allows node address assignment after power-up
  • Single wire communications up to 19.2 kbit/s @ 40 meter bus length.In the LIN specification 2.2, the speed up to 20 kbit/s.
  • Guaranteed latency times.
  • Variable length of data frame (2, 4 and 8 byte).
  • Configuration flexibility.
  • Multi-cast reception with time synchronization, without crystals or ceramic resonators.
  • Data checksum and error detection.
  • Detection of defective nodes.
  • Low cost silicon implementation based on standard UART/SCI hardware.
  • Enabler for hierarchical networks.
  • Operating voltage of 12 V.
Data is transferred across the bus in fixed form messages of selectable lengths. The master task transmits a header that consists of a break signal followed by synchronization and identifier fields. The slaves respond with a data frame that consists of between 2, 4 and 8 data bytes plus 3 bytes of control information.
In the Next section we will see LIN Protocol in detail....

                                                                                                                                                          NEXT>>

Monday, 21 August 2017

Modules in Python

- No comments


In this section we will discuss about ,lambda function and modules in Python.

Lambda Function

Lambda is an anonymous function,this function needs expressions and returns an object ,this function is not going to be created in standard way.

The above program will print 30 and 25.

Modules in Python

A Python module is simply a Python source file, which can expose classes, functions and global variables. When imported from another Python source file, the file name is treated as a namespace. A Python package is simply a directory of Python module(s).
keyword is a module it shows how many keywords and related informations.
dir(keyword) wont work unless we import keyword.
so to import type ..



['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
these are the available keywords in the Python,they are 31 of them.
Now let us see calendar and time modules.
import calendar as cal   - we can use cal instead of calendar module.


print cal.monthrange(2017,10)
will give (6, 31)
here 6 indicates it is sunday(0-mon,1-tue,2-wed......6-sun) and 31 ,the no of days in the month.
Now let us see time function..
time.time() -will give epoch time ie from 1970 jan 1.
time.localtime(time.time()) - will give time in structure format.
time.asctime(time.localtime(time.time())) -access time will give time in string format.



String based functions in Python

Let us see some examples of string functions..

s.strip() removes blank spaces from both ends while s.split() will split spaces and make in to list.
s.index('i') gives the first position of 'i'.
 s.index('deep') gives the starting position of d

if substring not found then it will print not found.

















IMPORTING PLATFORM

The platform module in Python is used to access the underlying platform's data, such as, hardware, operating system, and interpreter version information. The platform module includes tools to see the platform's hardware, operating system, and interpreter version information where the program is running.
 import platform
>>> platform.python_version()   - will give current python version

>>> platform.version() - will give platform.

>>> from platform import * -can import a particular platform

>>> from platform import python_version -import only python_version and nothing else
In the next section we will discuss about creation of our own modules and list functions...
<<Previous                                                                                                                                                              Next>>