Showing posts with label raspberry pi. Show all posts
Showing posts with label raspberry pi. Show all posts

Thursday, May 1, 2014

1 minute RPi Setup

All of us who use raspberry pi know what a hassle it is to use it for GPIO tinkering when you are running it headless, you do not always have a router nearby to ssh into it, or if you do it eats up lots of space.

It would be awesome if we could directly connect to the Pi with our Laptop through a Ethernet Cable and nothing else (of course a power supply :) 

This is what i did, and believe me it took less than a minute to set it up, and i was good to go.

I tried this on Ubuntu and it works fine, ill try on other Linux distros and update the same.

also this method is tried on Raspbian, Ill try it on few more OSs and update the blog.

For simplicity, try Ubuntu and Raspbian combo.
 
so here are the steps. I'll put the screen shots in each steps.

Step1:
        Power Up your RPi.


Step2.

        Connect the ethernet cable between the RPi and the Laptop / Desktop.

The network icon on ubuntu will show some activity only to show that the Wired network is disconnected.


Now comes the settings

Step3.
        Go to system settings












Step4:
        Go to Network Settings











Step 5:
        You will see  a Wired network is present.
Go to "Options" of the wired network.

You will see a tab for IPv4 settings. Change the method to "Shared" .











On some systems we need to make one more change.
in the 802.1x Security tab uncheck the only checkbox there, if already not unchecked.











So its all done here, You should now see the Wired connection being established and the Pi connected on the wired network.


Step 'I dont care about the number' :
         Fire up your terminal and run the most obvious command

'ifconfig'

you should see something like this.











Look under eth0 you should see ur inet address, so your pi will have the same first 3 bytes of IP address. also note that all this time i was connected to the internet via WiFi.


so how do you find out your RPi's IP address if it is headless.

You would need an utility called nmap. if you dont already have it.

run this 
$ sudo apt-get install nmap

once it is done, we need to ping the network on eth0.

the command goes like this 

$ sudo nmap -sP <inet_address>/<range> (i think its the range)

$ sudo nmap -sP 10.42.0.1/24 in my case, Look at the screenshot, this ip address will vary machine to machine.


you will now receive a list of Hosts connected, in our case it will only be 1 which is our RPi.


so the result gives two hosts, one is our Own system and the other is our RPi, since we know the IP address of our own system the other one is the RPI.











I have highlighted the adress, so the RPi is  connected and is up.
all we now have to do is log on to it using the ssh or other network login utility.

i used

$ sudo ssh pi@10.42.0.14

you replace it with

$ sudo ssh pi@<Pi's IP address>

Enter the password for your machine, and then there will be a password prompt for the Pi, the login is then completed, some security warnings may be shown but they are pretty straightforward to handle.


after you execute the ssh login you get this 

 










HAPPY HACKING !!

Wednesday, February 12, 2014

Powering your Rasberry Pi

I bought a Rasberry Pi recently and quickly the question I was faced with was: How to power it? Then I started digging into some specifics of power supplies. Most common answer was to use a standard micro-USB phone charger which ships with most Android phones. While this worked for me, I was curious to know more about power supplies.

Let us think about what a power supply is really. The electricity that runs in our wall sockets, is AC or alternating current. This AC supply has to be converted into a low voltage DC supply before powering your electronic circuits. This is the primary function of a power supply.

Standard power consumption of the Raspberry Pi device is
  • Board A: 5V, 500 mA (2.5W) without any devices connected (e.g. USB, Ethernet, HDMI)
  • Board B: 5V, 700 mA (3.5W) without any devices connected (e.g. USB, Ethernet, HDMI)

But it doesn’t end on that. We need to ensure that the power supply we use can provide enough electric current to power the Pi plus any additional peripherals. In addition, we need to take into account inefficiencies of the supply itself and the cable between the power supply and Raspberry Pi. Most of us will use the USB ports to connect a keyboard, mouse or a Bluetooth module. The community advises that we use a power supply that can at least supply 1A of current. A poor quality power supply unit may result in corruption of your SD card. The Pi gets unstable, freezes, lags for even simple tasks if enough power is not supplied. So if you have such problems, better take a look at the power ratings of your supply.

The power required by the Pi varies depending on what peripherals are connected and what functions it is currently performing. The Pi draws extra power when:

  • Running a GUI.
  • Connecting USB devices and an Ethernet connection.
  • When running the GPU.

This means that it is difficult to say exactly how much power is needed at any time. Adding peripherals increases the loading on the power supply to your board and this, in turn, may affect the voltage presented to the Raspberry Pi. If the Raspberry Pi's supply voltage falls below a certain value (around 4.75 V), or it begins to fluctuate, your setup may become unstable.

For regular "low power" USB devices this doesn't cause a problem as they are designed to work with voltages as low as 4.4 Volt. This isn't the case however with some USB devices such as WiFi dongles which may need 4.75 Volt, and are also known to draw more than 150 mA when configured and active. Each of the two USB ports on the Pi has a polyfuse rated at 140 mA, so any connected USB devices should draw less than this amount of current. The polyfuse itself can cause significant voltage drop. So be sure you know what you connect to the Pi. It is common to use a powered USB hub to power your USB peripherals. Also know that you can power your Pi from the USB hub also. There is a thread on that too.

Alternate ways to power your Pi: 
Although I never tried, but there are some interesting alternate ways to power your Pi. They are listed here.

There is still a _lot_ to know about power supplies and how they affect parts of an electronic and electrical devices. For example, how does overclocking affect power requirements? It is an interesting topic and I will keep this post updated on any new things that I learn and may be useful to others.

All the info written above has been compiled by reading blogs, wiki, manuals, etc. If you feel there is anything incorrect/overlooked, I would be more than glad to correct them.

Thursday, October 10, 2013

Using Raspberry Pi as a torrent client.

Using Raspberry Pi as a torrent client

Advantage of using raspberry pi as a torrent client is that it uses very less power. For a comparison,

Power consumption of Raspberry Pi device is very less. (5V, 500 mA (2.5W) without any devices connected).

So obviously, its a better solution for downloads that take a long time. and better to keep raspberry pi always on over a desktop / laptop.

Steps

  1. sudo apt-get update
    sudo apt-get upgrade
  2. sudo apt-get install deluged
    sudo apt-get install deluge-console
  3. Start the deluge daemon by running deluged
    It creates the necessary files that we can now edit.
    Stop this after some time (5-10 seconds) by running sudo pkill deluged
  4. Now edit the auth file. But first create a backup.
    cp ~/.config/deluge/auth ~/.config/deluge/auth.copy`
    Editing the auth file. nano ~/.config/deluge/auth
    Add a line at the bottom of the configuration file with the following convention: user:password:level
    Example : pi:pi:10 (10 is full-access/administrative level for the daemon)
  5. Now let's update the settings for allowing remote connections.
    deluged
    
    deluge-console
    
    config -s allow_remote True
    
    config allow_remote
    
    exit
    
  6. Restart deluged for this configuration to take effect.
    sudo pkill deluged
    
    deluged
    
  7. Intall deluge-web to be able to access it from remote.
    sudo apt-get install python-mako
    
    sudo apt-get install deluge-web
    
    deluge-web
    
  8. Access deluge-web from a remote machine on the same network.
    Navigate to http://<rasberrypi-ip>:8112/ .
    You have a torrent server at your service!
    Enter the password as deluge and immediately change it.
  9. In addition to accessing the web-gui from you can also access it from an Android application like Torrent Manager.
    While using this app just provide the password which was changed in step 8.

    You can take a look at the RaspberryPi code repository of IOT-Pune

Wednesday, October 2, 2013

Home Automation with RaspberryPi Python - Django


Home Automation with RaspberryPi Python - Django

So after attending the 2 meet-ups for IOT-Pune. I got a Raspberry Pi and decided to play around with it a little bit. The following post will walk you through the steps needed to turn on/off a light bulb.

Things needed
1. Raspberry Pi
2. Relay switch
3. light bulb with wire to plug into main power supply

Lets us start!!!

  • sudo apt-get install python-dev python-setuptools
  • sudo pip install django
  • django-admin.py startproject mysite
  • cd mysite/
  • django-admin.py startapp ledblink
  • cd mysite
  • open file named setting.py and add the ledblink app in the INSTALLED_APPS so that it looks like this
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'ledblink',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)
  • add this to the templates dir make sure you  add import os at the top of the page
TEMPLATE_DIRS = (
     os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'),
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)
  • cd ledblink
  • open the views.py file and change it to this
from django.shortcuts import render
from django.http import HttpResponse
import RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BOARD)
GPIO.setup(18,GPIO.OUT)


def blinker(request):
    if 'on' in request.POST:
        GPIO.output(18,1)
    elif 'off' in request.POST:
        GPIO.output(18,0)
    return render(request,'control_page.html')
    
  • Let us add the template control pages so go ahead and create a templates directory in your ledblink app and add the following html code and name it control_page.html
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<form action="" method="post">{% csrf_token %}
<input type="submit" name="on" value="on" />
<input type="submit" name="off" value="off" />
</form>
</body>
</html>

  • now let us create a url that links to this view. Goto the urls.py file in mysite directory cd ../mysite
from django.conf.urls import patterns, include, url
from ledblink.views import blinker
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
    url(r'^ledblink/$',blinker),
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^mysite/', include('mysite.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
)
  • Goto main folder of the project where the manage.py file is located and run the following command
sudo python manage.py runserver 192.168.0.106:8000

open up a web browser and type http://192.168.0.106:8000/ledblink/ in the address bar and you should have the following result




now lets get to the part where we connect every thing to the raspberry pi.



  • Sorry I couldn't get a better picture even though Nishant suggested to take the book out. :P But yoy connect the 5V out of the Pi that is pin 2 to the positive on the relay . The ground pin 6 to the regative of the relay and finaly GPIO18 to the corresponding pin on the relay board.

  • Plug the bulb in the main power supply. Go ahead and try turning on the bulb from the web Browser