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