Monday 24 November 2014

Installing HP laserjet 1020 plus in Raspberry Pi and printing via putty

Download printer driver
Open terminal or log in to your Raspberry Pi via putty.
Create a new directory and download the driver in it .
mkdir hppritner 
cd hpprinter
wget http://softlayer-sng.dl.sourceforge.net/project/hplip/hplip/3.14.10/hplip-3.14.10.run 



Change password of your root user 

we need the password of root user to install the driver so if you don't know what the password of root is (like it was in my case ) you can reset it by typing :
sudo passwd root



Installing HP LaserJet 1020 plus driver 
Type the following command and press enter . It will take around 15 minutes to install .
sh hplip-3.14.10.run
It will ask for your root password, enter it .




Printing a file

To print a file use the lpr command .
lpr filename




Sunday 23 November 2014

Controlling Raspberry Pi GPIO pins remotely over a TCP connection

Open terminal or connect to Raspberry Pi via Putty and create a new file test.py
Command : nano test.py
copy the code given below and paste it in that file . The code is also available on github .
Press CTRL+X to exit and then y to save changes .
Now to run the file type sudo python test.py


from socket import *  
 ## Import GPIO library  
import RPi.GPIO as GPIO   
 # Use physical pin numbers  
GPIO.setmode(GPIO.BOARD)  
 # Set up header pin 7 (GPIO7) as an output  
GPIO.setup(7,GPIO.OUT)  
host = "0.0.0.0"  
print host  
port = 7777  
s = socket(AF_INET, SOCK_STREAM)  
print "Socket Made"  
s.bind((host,port))  
print "Socket Bound"  
s.listen(5)  
print "Listening for connections..."  
while True:  
    c, addr = s.accept()   # Establish connection with client.  
    print 'Got connection from', addr  
    c.send('Thank you for connecting')  
    data = c.recv(1024)  
    if(data == "on" ):  
        print 'pin 7 on'  
        GPIO.output(7,True) ## Turn on GPIO pin 7  
    elif(data == 'off' ):  
        print 'pin 7 off'      
        GPIO.output(7,False) ## Turn off GPIO pin 7  
    elif(data == 'close' ):  
        print 'closing connection'  
        s.close()  
        break  
   c.close()   
 GPIO.cleanup() 



Now use a TCP client to connect to this TCP server and send data .
Modify the pin number to control other GPIO pins .

Saturday 22 November 2014

Raspberry pi ssh login without monitor and giving it static IP

Connecting Raspberry Pi to Ethernet and finding its IP address 

Connect Raspberry pi to Ethernet and power it on . The Raspbian "wheezy" distro comes with SSH telnet access enabled .
When you switch Raspberry pi on the router will allocate an IP to it .  Now log in to your router to see the IP assigned to Raspberry Pi . You can also use any IP scanner software also for finding out the IP assigned to Raspberry Pi like Advanced IP Scanner.



Connect to the Raspberry Pi via SSH / Putty

Download & Install Putty. It is not really an Install as you can run the putty.exe directly

Enter the IP address of Raspberry Pi in host name and click open.


Enter username pi and password raspberry (this is the default password )






Now you are connected to Raspberry Pi .

Giving static IP to Raspberry Pi

Type  cat /etc/network/interfaces to list the network interface currently available.


iface etho inet dhcp : This line tells us that we are using DHCP to get IP address . The IP address we get is dynamic and gets assigned to us every time we connect to router .

To set a static IP address we need some information about our connecion .

Type ifconfig to get inet address , Bcast and Mask  .


inet address : 192.168.0.100
Bcast : 192.168.0.255
Mask : 255.255.255.0

Type netstat -nr to get Gateway and Destination .


Gateway : 192.168.0.1
Destination : 192.168.0.0
 
Now we need to edit etc/network/interfaces to get static IP . 

type sudo nano /etc/network/interfaces and delete "iface etho inet dhcp" and replace with iface etho inet static and in the next line paste / write all the info we got in the above step .
It will look like : 

iface lo inet loopback
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1


 Type CTRL+X to exit then yes to save changes .


Type sudo reboot to reboot Pi . When the Pi boots it will have a static IP .