Backup using dd command

To backup an entire hardisk

#dd if=/dev/sda of=/dev/sdb

sda is the source hardisk and sdb is the external hardisk to which am taking backup

“if” represents input file and “of” respresents output file….

if we give parameter “conv=noerror” then it will continue to copy if there are read errors…else command may fail due to read error

#dd if=/dev/sda of=/dev/sdb conv=noerror

To make image of a hardisk

#dd if=/dev/sda of=~/Desktop/hd_img.iso

Consider am having a bootable usb with a custom OS with some settings saved in it…To make an image of that

Make image of the bootable usb

#dd if=/dev/sdb of=~/Desktop/puppy.img

The above command will make an image of the bootable usb
Now connect the blank usb and make it bootable

dd if=~/Desktop/puppy.img of=/dev/sdb oflag=direct

Always run dd command as root user…use df command to know the drives else you may loose the data…

MSP430 GPIO Programming Reading an external switch

To read an external switch using MSP430 an external switch is connected to P1.4…We uses polling method here to read the switch

/*button_press.c
ganeshredcobra@gmail.com
GPL
An external button connected to P1.4 is used in this example...
connect P1.4 to vcc through a resistor...
*/
#include 

volatile unsigned int i;//to prevent optimization
void main(void)
{
	WDTCTL=WDTPW+WDTHOLD;
 	P1DIR|=0X01;//set all bits in P1 to input except BIT0
	for(;;)
	{
	  if((P1IN & BIT4)==0)//while pushing S1
		P1OUT=0X00;//LED ON
	  else
		P1OUT=0x01;//LED OFF		 
	}
}

When we pushes the button LED will be ON and when we releases it will be OFF…
Happy Hacking 🙂

Programming MSP430 on board button

To get user input or to make a switch working in MSP430 Launchpad first we will try programming the on board button P1.3 to read user inputs

Connect P1.3 pin to Vcc through a resistor…Thecode to get user input is below

/*button_press.c
ganeshredcobra@gmail.com
GPL
on board button S2 is used in this example...
connect P1.3 to vcc through a resistor...
*/
#include <msp430g2553.h>

volatile unsigned int i;//to prevent optimization
void main(void)
{
WDTCTL=WDTPW+WDTHOLD;
P1DIR|=0X01;//set all bits in P1 to input except BIT0
for(;;)
{
P1OUT=0x01;//BIT 0 LED ON
while((P1IN & BIT3)==0)//while pusing S1
P1OUT=0X00;//LED OFF
}
}

The above code sets the red led on whenever we pushes the button the led is turned off….The code is self explanatory with comments…

This is an example of polling…

Happy Hacking 🙂

How to connect Micromax 3G mobile internet modem in Ubuntu 12.04

Last day i configured a Micromax 3G mobile internet modem…This is how i fixed it…The output of lsusb was like this

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 
Bus 001 Device 003: ID 03f0:5307 Hewlett-Packard 
Bus 001 Device 008: ID 1c9e:9605 OMEGA TECHNOLOGY 
Bus 001 Device 006: ID 5986:0364 Acer, Inc

Create a config file

gksudo gedit /etc/usb_modeswitch.d/1c9e:9605

Paste this code in that config file

DefaultVendor = 0x1c9e 
DefaultProduct = 0x9605 
TargetVendor = 0x1c9e 
TargetProduct = 0x9605 MessageContent="55534243123456788000000080000606f50402527000000000000000000000"

Save and exit then

sudo modprobe usbserial vendor=0x1c9e product=0x9605 
sudo usb_modeswitch -c /etc/usb_modeswitch.d/1c9e\:9605

This will fix the issue….
You need to run this code always so you can add this to /etc/rc.local…Insert the below code just before exit 0 so that it will be part of your startup programs

sleep 10
 modprobe usbserial vendor=0x1c9e product=0x9605
 usb_modeswitch -c /etc/usb_modeswitch.d/1c9e\:9605
 sleep 20
 nmcli nm wwan on
 sleep 10
 nmcli con up id "your connection name here"

After restarting connect the device and wait for 10 seconds to get the device detected…