Search This Blog

Saturday, July 23, 2016

Starting with RPi

RaspberryPi:


Raspberry Pi is a amazing little computer that fits in the palm of your child's hand also, Also Packed with powerful enough to run your home media center, a VPN, mini server, and a lot more. Before you can do anything awesome, first you need to install an operating system and configure it.Here's how.




What You'll need to Launch Your Raspberry Pi:


  • Raspberry Pi
  • HDMI Cable : To Connect to HDMI compatible monitor or TV
  • USB Keyboard and USB Mouse : Any Standered Usb Keyboard and or Mouse will do the job.
  • 3.5 mm audio cable : if you need audio output through your home theare
  • Download the latest Raspbian OS (Here
  • A good Quality Power supply 5Volts 2A is recommended or Any Good Power Bank: Most modren smart phone  charger is suffecient if you doing light wieght projects.
  • 8 GB micro SDcard: A class 4 micro sd card is enough 
  • SD CardReader
  • 2 Softwares to write the Raspibian OS on your memory Card
  • SDFormater
  • win32DiskImager



Setting Up Your RPi with Basic Operating System (Rasppibian):

You can use the Raspberry Pi for all sorts of different things—some of which may require their own special operating systems—but to start out, it’s a good idea to get acquainted with the Pi by installing Raspbian, a Raspberry Pi-focused version of Linux. Here’s what you need to do.

Step One: Prepare Your SD Card

Before powering the Raspberry You need the Install OS on to your SD card . To do so You must put your SD card into SDcard reader and connecto to  you PC/Laptop and then format SD card using SDFormater Software (Becarefull You might Select the Wrong Drive , if you do so all the data in that drive is wiped out).
Once the formating is done then open Win32DiskImager software and Browse the Rasbian Image file which you downloaded earlier. and select Drive(which is pointer to SD Card). There is 2 otions in the drive one is read and the other is write. "read" is to read the sd card and write on the file and "write" is to write the image to the sd card.
now click on "write"(if you select "read" your Image file will be over write by the data in SD car, here sd card having no data so --> image file will be 0 Bytes) so don't do that). now the OS will starts writing on to SD card.
Wait for some time(15 min for mine)
When it finishes, safely eject your SD card and insert it into your Raspberry pi
Step Two:
In step one you successfully write the OS onto your SD card now its time to Power Up your RPi.
Connect usb mouse and keyboard to your RPi and HDMI cable to monitor and your RPi.
Check once all are connected well, then connect the power to RPi.
Now your mini computer start booting up and you can see that in the monitor.

is it asks for user name and password then type the default user name and default password as bellow
user name:pi
password: raspberry

Now you can play with your PRi it having in bult browser,image viewer,document write,...etc .

by default the file system shows only less tha 4 gb even though you use 8GB sd card. there you will face some problem with lowe memory so, first you need to expand the file system so that OS can access all the physical memory on the sd card to do that you need to configure your raspberry.....

to be continued...............

Friday, May 20, 2016

Basic Char Driver - Linux Device Driver

Here I am going to write on simple basic module which can load into kernel and  can remove from kernel . This sample module do nothing we can see the module loading and removing message in syslog.

First the useful things to write code

  • Your favorite code editor 
    • Here I used geany code editor
  • Header files
    • basic header file/libraries you must include in c file are 
      • linux/init.h
      • linux/module.h
  • Basic functions
    • basic functions/macros to add your function to kernal ar
      • module_init(fun);
      • module_exit(fun); 
  • Makefile
  • some commands to view the log
c code - filename : ex1_simple_module.c

#include <linux\init.h>
#include <linux\module.h>
int ex1_simple_module_init(void)
{
    printk(KERN_ALERT"Module ex1 Inside the Function %s",__FUNCTION__);
    return 0;
}
void ex1_simple_module_exit(void)
{
    printk(KERN_ALERT"Module ex1 Inside the Function %s",__FUNCTION__);
}

module_init(ex1_simple_module_init);
module_exit(ex1_simple_module_exit);



the above c code havin 2 user function
ex1_simple_module_init() and ex1_simple_module_exit()
and both having printk functions . the printk function send the data to system log . we can see that data in "var/log/syslog" file

module_init() function take the function as argument and sends that function to kernel as init funtion and module_exit() function send the function to kernel as exit function

to compile the kernel we need to know the current kernel version . To get that we can use the command


uname -r



Now write the make file to compile the module

Create a file with name Makefile and insert the below code in that

obj - m := ex1_simple_module.o


here the file name is ex1_simple_module.c so we use ex1_simple_module.o as output .This simple line in the makefile compile our c code and generate object file.

To run the  Makefile we need to use the below command in bas terminal

make -C /lib/modules/$(uname -r)/build M=$PWD modules




here the kernel version is got from uname -r command and the source file directory is fetch from PWD command. So we must run this command from the directory where the source file is stored

now the source is compiled and the .ko files are generated now we can insert and remove the module to kernel.To do this first we need to follow the syslog. For that we can us the below command in terminal.

sudo tail -f /var/log/syslog


here tail means print the tail part(last lines)
        -f means follow the last lines in the file syslog

after this command current terminal will the print syslog data so we need to open the other terminal to insert the module into kernel

To insert the module use insmod command and to remove use rmmod command

sudo insmod ./ex1_simple_module.ko

sudo rmmod ex1_simple_module






That it . I hope this post is useful to you .Please comment below and check out other posts and my youtube channel



Wednesday, June 4, 2014

Compiling C++ program in linux


Compiling C++ program in linux is little bit different than Compiling a C program ,

             gcc compiler is the commonly used compiler for c in linux but for compiling c++ program in linux we need to use another compiler called g++ .the syntax for this is

g++ <your_program>

It compiles the program and gives a.out as the output

But there is a problem with this , if any of the modern concepts like range for is used in the program it gives an error like,

15.cpp: In function ‘int main()’:
15.cpp:10:14: error: range-based ‘for’ loops are not allowed in C++98 mode
 for(char c : str){
 
the modern concepts are compiled with C++11 supported compiled. so there is a need to use extra option for compiling this.


i.e.,

g++ -std=c++0x <your program>

Using this flag every time is somewhat difficult so we nee to enable c++11 perminently

To set that first open the terminal

sudo gedit ~/.bashrc

then a file will be opend , now add below line as the last line

alias g++="g++ --std=c++0x" 

then save the file and restart the terminal then compile the program as

g++ <your program>


if you want to compile non c++11 program then you must use
g++ --std=c++98 <your program>




Friday, August 30, 2013

Creating header file in keil

Creating header file in keil :

        To develop a complex or a big project in keil we need to write more code so , as the number of lines increasing the complexity of editing the code is also increases so we need to optimize the code structure to access it easily. we can do so by creating header files. Header files mainly contains some functions which are called by main function and these header files may stored in the same folder or in another folder. if the header file and the project is in the same folder then  "#include<header_file_name>" is used to call a header file. if the header files stored in other location then "#include"path../header_file_name"" is used.

        Here is the simple procedure is shown about creating header file in keil is shown. you can find the clear view in video on creating header file in keil.

there are some steps for this, those are

step1:first create 3 folders with in out project folder and name them as 
      'APP','DRV','OUT'
     APP-is for our application file i.e., main files
     DRV-is for driver functions 
     OUT-is for output files

step2: create a project in keil and in the target option add 2 source groups and name them as 'APP','DRV'

step3:make delay.c and delay.h files as shown in the video 
      delay.c file having the function body and delay.h file having the function declaration
      save the both files in DRV folder

step4: now add delay.c file to DRV source group so that it will get compile along with main.c file

step5:go to 'Options for target'  the go to 'output' tab then click on 'folder for objects' and select OUT       
     folder

step6:then go to 'C51' tab and in 'include paths' add 'APP' and 'DRV' folders so that the compiler 
     searches the header file in that included paths

step7:add #include "delay.h" line in main file  and compile the code

follow the video for better understanding of creating header file in keil




Full


led blinking-8051

LED Blinking program in 8051:

8051 is a 8-bit micro-controller. i.e.,it data  bus size is 8-bit  so that each port in 8051 having 8 pins and having 4 ports Port-0,Port-1,Port-2,Port-3

this example showing the led blinking for Port 1

#include <reg52.h>//header file for 8051 or 8052
void delay(int ch)
{
int i=0,j=0;
for(i=0;i<ch;i++)
{
    for(j=0;j<1275;j++)
    {
    }
}
}
void main()
{
while(1)
{
    P1=0x00;
    delay(20);
    P1=0xff;
    delay(20);
}   
}


here while(1) is a continues loop (infinity loop)

P1=0x00; means all pins are active low that means zero Volts
P1=0xff; means all pins are active high that means 5 Volts

we are providing a delay of  200 millisec for ON and OFF state

below video shows every thing

 

Wednesday, August 28, 2013

compiling c program-linux

Compiling a c program in linux:

to run a c program in your linux machine you need 2 software packages

1.vi or vim editor
2.gcc compiler


check those software by typing the gcc and vi or vim command on the terminal
if it shows command not found then you need to install that software

to do so a simple command is useful for you

yum install software

yum command automatically searches the software package and installs the latest one

so type
yum install gcc vi vim

the it automatically install the 3 packages

vi and vim both are code editors vi is a default one but it show the code in single color
where as vim show the different colors .like variables,strings,functions...etc

its look like



see the colors in vim editor






after installing the packages first create  c file uisng vim editor

vim hw.c

its creats hw.c file and enter into editor now editor is in command mode so you need to enter into insert mode to edit the code for the type 'i'
the edit the code

the press 'esc' key to enter into command mode the ':x' to save and exit

* :x<Return> quit vi, writing out modified file to file named in original invocation
  :wq<Return> quit vi, writing out modified file to file named in original invocation
  :q<Return> quit (or exit) vi
* :q!<Return> quit vi even though latest changes have not been saved for this vi call


after exiting the editor compile the code using gcc compiler

gcc hw.c------------by default it outputs the file with a.out name

gcc hw.c -o hw.o----now the output fie name is hw.o

if there are no errors it will creates the output file
to run that file type

./a.out   or   ./hw.o

then your code will shows the output..


Tuesday, August 27, 2013

create folder-linux

Creating a folder

mkdir is a simple command to create a folder/directory

mkdir espot

then espot directory is created

cd espot

navigates to 'espot' directory

here  
ls
command  shows the files and directories with in present directory