November 23, 2016

Internet of Things with Thingspeak #8

Hai everybody....long time no see...

Let's begin the topic of connecting our Raspberrypi to Internet


Let's cook some IoT 

Here is a easy way to connect your raspberry pi with Internet; also say it as IoT

Now let's get started with thingspeak.....(opensource- free tool )


Step 1: Install these packages to start your first IoT


~ thingspeak
~ psutil package : it is a cross-platform library for retrieving information onrunning processes and system utilization (CPU, memory, disks, network)  - install this only if needed

just type these in to your terminal


sudo pip install thingspeak

<when it is done installing, go on with the below>

sudo pip install psutil

Step 2: After Installing this you need to setup thinkspeak


so visit the thingspeak website  https://thingspeak.com   and sign up

then get started by creating a New channel 

Name your channel such as "MyfirstIoT" or something


select the number of fields you needed ; for example i need to create a program to note distance measured from ultrasonic sensor.


          In-order to store the distance only one field is enough as shown below, which you can rename it as you wish

also you can find the Make Public option, which you have to enable it, (to make it seen by everyone)
finally save the channel

the below image is the confirmation window that your channel is set

   


















Here you should make a note of Channel ID (Highlighted)

And open the API Keys 

 Note down the Write API as shown

Step 3: After Making note of it, we can move on to programming again i.e same old ultrasonic we are taking about before but with some little modification

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


channel_id = "190090"
write_key  = "W0BY8W15LGUEEC0F"    # Here i used mine, instead use your own channel id and API
channel = thingspeak.Channel(id=channel_id,write_key=write_key)

# Here the channel information and Write API is taken to proceed the process

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

    time.sleep(1)      # to avoid rapid changes...you can increase it if needed.
    try:
        response = channel.update({distance})
        print response
    except:
        print "connection failed"

# Sometimes the channel may not be connected due to network traffic, or failed internet connections, Since the try-exception methodology is always recommended to be used with thingspeak interface programming as shown above. warning: be conscious about the  intent space

GPIO.cleanup()


Now, run this program and see the magic; open up your thingspeak anywhere in the world ..you can see your sensor data stored in there......

you can find more examples here.

try everything

for any doubts comment me...


bye
--------
Arun

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

September 27, 2016

Installing GPIO library in Raspberry pi #3

 General Purpose Input/Output (GPIO) is an integrated pins located at the Raspberry pi.

In olden days todays' IoT technology is called as Machine to Machine technology.
Many can say their own definition for IoT, but as per my understanding IoT is know to be an "Infrastructure of the Information Society".

But in-order to do that we need to make our pi to communicate with the sensors to collect the physical parameters, at the same time it need to store the data in the cloud or the local storage using internet.

Configuring and controlling these pins will lead to achieve the above mentioned task.

Step1: Open the terminal window directly or using the  putty to initiate configuration.

Step2: Update the Raspbian OS

            in the terminal window execute the following commands using super user permission

sudo apt-get update

sudo apt-get dist-upgrade

Step3: Before getting into GPIO library installation first we need to install python packages or upgrade it using the following command
       

sudo apt-get install python-dev python3-dev

Step4: Once you done with that get onto downloading latest GPIO library from the following link


Step5: If your using putty till now, better to install WinSCP  in your laptop too, shown in the below link

        using this software we can upload the files from our laptop to raspberry pi

So we can download the GPIO library files to our laptop and then transfer the same file to our pi (It uses the same user name and password as our pi)

Step6: Anyway, i hope you have  downloaded the GPIO library in to our pi. Now use this command to extract it


tar zxvf RPi.GPIO-0.5.6.tar.gz  

(remember the package version changes depends on what you download)

Step7: Then enter into the extracted folder.

cd RPi.GPIO-0.5.6

(check the version use ls command to check what you have downloaded) 
Step8: Now Execute the silver touch command

sudo python setup.py install 

or

sudo python3 setup.py install

yahoooo!!!! our pi is ready to make GPIO action.....

bye
---
Arun      

September 26, 2016

Using Raspberry pi without a separate Monitor #2

I hope we have done the initial setup in our pi (Ref. #1)

Remember our pi is a computer, which can be operated by connecting it to the Monitor, Keyboard and a Mouse.

Usually the monitors will have HDMI port or VGA port
but our pi is equipped with HDMI port. If you monitor is VGA ported then use the HDMI to VGA converted as shown below

The true purpose of making the computer in miniature size is to encourage portability, so learning different methods will give us a use it in different possibilities.

So here is our topic "Using Raspberry pi without a separate Monitor"

Step1: Using your memory card reader; open your pi's Harddisk/SD card

Step2: Inside the "boot" drive you can find file named "cmdline". you can just open it

Step3: There you can find some config. statements in a single line. Press "end" , give a space and type this "ip=192.168.0.200"  (without double quotation)

Remember the ip address what i have mention is for example (you can mention the ip address of your own)

Step4: Reinsert the configured SD Card in your pi

Step5: There are many softwares to interlink Raspberry pi and our laptop/pc. But i find the software name "putty" is the better one among them
you can download the "putty" software in this link

Step6: Install putty in your PC/Laptop. Configure  your laptop's ip address for example if your ip address as shown above(Ref. Step3) then your laptops ip may be like this 192.168.0.100 or some other, but the first 3 sections of address should be the same "192.168.0.XXX"

Step7: Power up your pi, use Ethernet cable to connect raspberry pi and your laptop

Step8: Open putty software that you have installed; there you can find session tap in that type you pi's ip to call it as shown below


then, go to SSH tap and find X11.. in that you have to enable X11 forwarding



once you done these you can click open button below -
Raspberry pi's terminal window appears and asks for user name and password

 username >> pi
 password >> raspberry
(default user name and password for all pi)

--
Arun