4.CONNECTIONS WITH PI

MAKING PI INTO WIFI AP:

Requirements:

  1. Raspberry pi
  2. Ethernet cable
  3. USB console cable
  4. wifi adapter
  5. putty

Steps to make pi into wifi router

  1. Consider a Raspberry Pi in which raspbian OS is installed. Now we can connect to the Pi using console cable. This allows us to connect to access the command line of Raspberry Pi, by plugging the USB end into our computer and the other end into specific serial GPIOs on the Raspberry Pi. The console cable looks as below:console-cable-breakoutconnect the console cable to the following GPIO pins as shown:connect the ground (GND) to the pin 6 of raspberry pi.connect RXD to the TX of raspberry pi.connect TXD to the RX of raspberry pi.Now connect the raspberry pi to the computer using USB console cable and give power supply(3.3v) to the pi.
  2. To bring up the shell on windows, we need to find out what COM port the console cable is using.                                                                                                                                            search for device manager and note com port number in ports section                     dev manager Now open putty and connect our system to raspberry pi as shown in TTL.
  3. pi terminalNow we need to install a software onto the pi that will act as the ‘hostap'(host access point). To install the software, enter the below commands on the command-line interface.sudo apt-get update
    sudo apt-get install hostapd isc-dhcp-server
  4. To setup the DHCP server, we need to edit the dhcpd.conf file. This file allows wifi connections to automatically get IP addresses,DNS etc. To edit the conf file, enter the below command on command line interface.

    sudo nano /etc/dhcp/dhcpd.conf

    In the conf file search for the below lines and comment them by entering # before them

                                       option domain-name “example.org”;
                                      option domain-name-servers ns1.example.org, ns2.example.org;

    Change them as below:

                          #option domain-name “example.org”;
                          #option domain-name-servers ns1.example.org, ns2.example.org;

    Also find the below lines and uncomment the authoritative by removing the # symbol before it.

                          # If this DHCP server is the official DHCP server for the local
                          # network, the authoritative directive should be uncommented.
                          #authoritative;

    Change it as shown below:

    # If this DHCP server is the official DHCP server for the local
                   # network, the authoritative directive should be uncommented.
                    authoritative;

    Add the below lines at the bottom of conf file and save the file by clicking ctrl+x and Y:

    subnet 192.168.42.0 netmask 255.255.255.0 {
                  range 192.168.42.10 192.168.42.50;
                 option broadcast-address 192.168.42.255;
                 option routers 192.168.42.1;
                default-lease-time 600;
                max-lease-time 7200;
                option domain-name “local”;
                option domain-name-servers 8.8.8.8, 8.8.4.4;
            }

     

  5. Next open the file isc-dhcp-server
    Find the following line in file INTERFACES=””  and update this to INTERFACES=”wlan0″
    Save the file and return
    Make sure that wlan0 is not active. Make it inactive using command
    sudo ifdown wlan0
  6. set up the wlan0 connection to be static and incoming.
    run sudo nano /etc/network/interfaces to edit the file

    Find the line “auto wlan0” and comment it, if it is in the file. Comment each line after the current line also.

    add the below lines into the file

    iface wlan0 inet static
    address 192.168.50.1
    netmask 255.255.255.0

  7. setting password for the network. For this we need to create a file and write into it. I am setting my password as Bhargavcreate file using command
    sudo nano /etc/hostapd/hostapd.conf

    Write the following code into file :

    interface=wlan0
    driver=rtl871xdrv
    ssid=navi
    hw_mode=g
    channel=6
    macaddr_acl=0
    auth_algs=1
    ignore_broadcast_ssid=0
    wpa=2
    wpa_passphrase=raspberry(I did not change password)
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=TKIP
    rsn_pairwise=CCMP

  8. we need to setup configuration file for Raspberry Pi.
    Run sudo nano /etc/default/hostapdFind the line #DAEMON_CONF=”” and edit it so it says DAEMON_CONF=”/etc/hostapd/hostapd.conf”
    Configure Network Address Translation

    This will allow multiple clients to connect to the WIFI network. Open the file “sysctl.conf” using the following command sudo nano /etc/sysctl.conf
    At bottom of the file add line. This will start IP forwarding on boot up
    net.ipv4.ip_forward=1
    Save the file and return

    sudo sh -c “echo 1 > /proc/sys/net/ipv4/ip_forward”

    Run the following commands to create the network translation between the ethernet port eth0 and the wifi port wlan0

    sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    sudo iptables -A FORWARD -i eth0 -o wlan0 -m state –state RELATED,ESTABLISHED -j ACCEPT
    sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

    Now changing the configuration so that WIFI connection is ready on startup. Run the following command
    sudo sh -c “iptables-save > /etc/iptables.ipv4.nat”

    Open the file iptables.ipv4.nat using command
    sudo nano /etc/network/interfaces

    add the below line at end of file
    up iptables-restore < /etc/iptables.ipv4.na

  9. Updating the software so that the WIFI hardware is supported. Follow the below steps to setup software
    To download
    wget   http://adafruit-download.s3.amazonaws.com/adafruit_hostapd_14128.zip
    To install
    unzip adafruit_hostapd_14128.zip
    sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG
    sudo mv hostapd /usr/sbin
    Give permission for execution
    sudo chmod 755 /usr/sbin/hostapd
    WIFI zone on every restart
    Now we are all set to set our own WIFI using Raspberry Pi. This can be hosted using following command
    sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf
    This displays the name of your WIFI on other devises. You can select the newly created WIFI and connect to it using the password.
  10. Now we can see our raspberry pi wifi and access it.wifi.pngnavi is our wifi.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 TTL CONNECTIONS:

Everybody wants to connect their PI to a system instead of connecting to monitor and do their work. There are many ways to connect PI to laptop. Now I will show one of the method how to connect a pi with laptop(with windows OS).

REQUIREMENTS: 

  1. USB (with TTL(transistor-transistor logic) adapter).
  2. Pi with installed software(this installation is shown Rapberry pi and hardware installation page)  and others like breadboard etc.
  3. Laptop(with windows OS).

STEPS IN CONNECTION:

  1. Connect T-type GPIO extension board as shown in below image. This helps in connecting bread board to pi.
  2. By using TTL adapter and jumper pins connect laptop to breadboard. By this pi is connected to power source.
  3. Type  devmgmt.msc in search and it will open device manager20170209_160408
  4. Then insert TTL connected pi to laptop and open devmgmt.msc it will show port that which pi is connected.2if the warning shows like above figure download prolific usb driver and update it and restart laptop. Then it will show as belowScreenshot_20170209-163918.png
  5. Open putty and check serial as shown below20170209_164252.jpgserial line is port number and speed is 115200. Then it opens a command prompt then enter login and password20170209_164645.jpg
  6. Type commands
  •     cd boot
  • sudo na config.txt
  • enable_urt=1

then we can program in putty.