October 7, 2016

Sharing Internet from the Laptop to Raspberry Pi #7



Welcome back Guys!!!!

In this post we are going to see about , sharing WiFi Internet connection with Raspberry Pi through LAN/Ethernet from our laptop.

This post is for windows users only

I have a windows 7 system, will explain it through that

Step 1:  Open your "Network & Sharing Centre". In that open  "Change adapter Setting"
     There you can find many network connections  as shown below


In this "Local Area Connection" is the network medium, which we use to connect our raspberry pi through Ethernet cable. Open it and change the "IP Address" to  automatic IP.

Step 2 :  Check your Laptop/PC is has working internet connection. if so, open the properties of your wifi adapter ... in Sharing option change "Enable" sharing.  Also  Change the "Home networking connection"  to  "Local Area Network"



Once you done that , confirm it by clicking "OK"
A window appears asking you to confirm the "IP ADDRESS"; by default your system ip will change to "192.168.137.1"

Step 3: Now change your pi's something like this  "192.168.137.43" or "192.168.137.216" or anything else but the first 3 fields of ip should be same "192.168.137.XXX"
(changing ip address of pi requires a SD card reader . Please see the Post  #2 or click here for reference)

Step 4: Now check whether our Laptop/PC  is connected with PI, Use Windows command Prompt



If there is no loss then ....holaaaaa .... our work is done......
use putty software and open the terminal window and check for internet connection using this command

Here your can use the IP address or you can type "raspberrypi.mshome.net" in the putty's ip address space.   

then use the below code to check...whether it is working or not

>> sudo apt-get update

This is one method, there are many other ways, but i found this is easy

There is another method which makes our system as a proxy server, we will see that in our future posts


thanks for reading
bye
----

Arun

Interfacing Ultrasonic sensor with Raspberry pi #6

Welcome back friends!!!

Now let's move on to the ultrasonic interfacing with raspberry pi

import RPi.GPIO as GPIO        #Imporing  GPIO module
import subprocess                     #Importing Sub-process Modules, which will be discussed later
import time                                #Importing time modules

GPIO.setmode(GPIO.BCM)    #  Setting up a mode of operation

TRIG = 23                                #  Assigning a pin no. for Trigger
ECHO = 24                              #  Assigning a pin no. for Echo

GPIO.setup(TRIG,GPIO.OUT)   #  Setting up a trigger pin
GPIO.setup(ECHO,GPIO.IN)     #  Setting up a echo pin
GPIO.output(TRIG, False)

print "Waiting For Sensor To Settle"   
time.sleep(2)                              #  Wait for 2 seconds

while(True):                                #  Start a loop to process this continuously
    GPIO.output(TRIG, True)      #  Start a trigger 
    time.sleep(0.00001)                 #  To make the trigger i frequency
    GPIO.output(TRIG, False)     #  Stop a trigger
    while GPIO.input(ECHO)==0:  # loop to check the status of  echo pin
        pulse_start = time.time()         # Note the initial pulse release time
    while GPIO.input(ECHO)==1:    # loop to check the status of  echo pin again
        pulse_end = time.time()           # Note the final  pulse reach time
    pulse_duration = pulse_end - pulse_start  # finding the travel time of a pulse by taking difference

    distance = pulse_duration*17150   # calculating distance
    distance = round(distance, 2)          # rounding off 
    print "Distance:",distance,"cm"       # printing Output

GPIO.cleanup()



Execute this program as like the previous one
for any doubts and more explanation

comment me!!!!


Thank you
bye

----
Arun

October 4, 2016

Executing my First GPIO in Raspberry Pi #5

Welcome Amigos' !!!!


As a quick replay use the first  3 steps in the last post and start a first program


>> mkdir myprograms
>> cd myprograms
>> sudo nano myfirst.py

while doing this, a window appears to let you type the program, but before that take a good look @ GPIO pin configuration



now, copy and paste these lines in the opened terminal window
#1.  this is the program to turn LED on and off  in 5 seconds interval

import RPi.GPIO as GPIO  # Import GPIO module
import time   # Import Time Module

GPIO.setmode(GPIO.BOARD)   # Use board pin numbering
GPIO.setup(7, GPIO.OUT)   # Setup GPIO Pin 7 to OUT

GPIO.output(7,True)  # Switch on pin 7
time.sleep(5)   # Wait
GPIO.output(7,False)   # Switch off pin 7
time.sleep(5)   # Wait


GPIO.cleanup()  


Once you have complete pasting or typing  Press "Cntrl + x" for exit and "Cntrl + y" for saving the file and give an "Enter" to finalize the process.

Before executing the program, connect a LED in the Pin 7  and there are several ground pins available such as Pin 6,9,14,20,25,30,34 & 30

#1.  How about turning LED on and off  in 5 seconds interval continuously


import RPi.GPIO as GPIO  # Import GPIO module
import time   # Import Time Module

GPIO.setmode(GPIO.BOARD)   # Use board pin numbering
GPIO.setup(7, GPIO.OUT)   # Setup GPIO Pin 7 to OUT

while(True):
    GPIO.output(7,True)  # Switch on pin 7
    time.sleep(5)   # Wait
    GPIO.output(7,False)   # Switch off pin 7
    time.sleep(5)   # Wait


GPIO.cleanup()  


tada.... just while loop is included....

Remember in other programming language such as C lang. after a looping statement a braces '{'  will be started and ended @ some place to execute more than one line in a loop. 
But in python you have to give a "TAB space" or "4 space bars" before each and every line to execute those lines in loop. (remember this may some time show you an error)

After saving this program file, try to run it using the below code

sudo python myfirst.py

# sudo - is used to run this program as super user

this will make the LED's to glow  or whatever connected to the respective pins

We will see the detailed view of programming in the upcoming python tutorial

see you
----

Arun

Procedure for GPIO programing in Raspberry pi #4

Welcome Amigos' !!!!

Hope you have completed the configuration stage.

Now lets code our first ***

Step1:Create a separate directory to mange all the program we do using the terminal command
>> mkdir myprograms

Step2: Now get into the created folder
>> cd myprograms

Step3: To create a first program type
>> sudo nano myfirst.py

+ In this sudo indicates "SUPER USER" so the command mention will be used with administrator            permission.
nano is the command to create new files.
+ myfirst.py is the name of my first program with extension .py, since it is a python program.

 Step4:   Lets begin!!!  please see the syntax below before going for actual program

import RPi.GPIO as GPIO     # importing GPIO module- remember that this is case sensitive
import time                             # Importing Time module

GPIO.setmode(GPIO.BOARD) #  you can use this if you want to use pi's direct pin numbers
    or
GPIO.setmode(GPIO.BCM)  # you can use this, if you want to use the CPU pin numbering

(sometimes there will be a need for switching modes, there we can make use of this)
GPIO.setup(channel, GPIO.IN)  # to set the input channel

GPIO.setup(channel, GPIO.OUT) # to set the output channel

GPIO.cleanup()  # this line will refresh and reset the system by removing imported modules,                                              consider this as a good programming style

see you
---
Arun