Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Raspberry Pi cookbook for Python programmers

You're reading from   Raspberry Pi cookbook for Python programmers The Raspberry Pi Cookbook has over 50 tailor-made recipes for programmers to get the most out of Raspberry Pi using Python to unleash its huge potential.

Arrow left icon
Product type Paperback
Published in Apr 2014
Publisher
ISBN-13 9781849696623
Length 402 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (18) Chapters Close

Raspberry Pi Cookbook for Python Programmers
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with a Raspberry Pi Computer FREE CHAPTER 2. Starting with Python Strings, Files, and Menus 3. Using Python for Automation and Productivity 4. Creating Games and Graphics 5. Creating 3D Graphics 6. Using Python to Drive Hardware 7. Sense and Display Real-world Data 8. Creating Projects with the Raspberry Pi Camera Module 9. Building Robots 10. Interfacing with Technology Hardware and Software List Index

Networking and connecting your Raspberry Pi to the Internet via the LAN connector


The simplest way to connect the Raspberry Pi to the Internet is using the built-in LAN connection on the Model B. If you are using a Model A Raspberry Pi, a USB-to-LAN adapter can be used (refer to the There's more… section of the Networking and connecting your Raspberry Pi to the Internet via a USB Wi-Fi dongle recipe for details on how to configure this).

Getting ready

You will need an access to a suitable wired network, which will be connected to the Internet and a standard network cable (Cat5e or a similar one with a RJ45 type connector for connecting to the Raspberry Pi).

How to do it…

Many networks connect and configure themselves automatically using Dynamic Host Configuration Protocol (DHCP), which is controlled by the router or switch. If this is the case, simply plug the network cable into a spare network port on your router or network switch (or wall network socket if applicable).

Alternatively, if a DHCP server is not available, you shall have to configure the settings manually (refer to the There's more… section for details).

You can confirm this is functioning successfully with the following steps:

  1. Ensure that the three LEDs on the Raspberry Pi marked FDX, LNK, and 100, light up (the 100 LED may not light up if connected to a 10 Mbps device rather than the more common 100 Mbps device), and in some cases, start to flash.This will indicate that there is a physical connection to the router and the equipment is powered and functioning.

  2. Test the link to your local network using the ping command. First, find out the IP address of another computer on the network (or the address of your router perhaps, often 192.168.0.1 or 192.168.1.254). Now, on the Raspberry Pi terminal, use the ping command (the parameter -c 4 is used to send just four messages; otherwise, press Ctrl + C to stop) to ping the IP address as follows:

    ping 192.168.1.254 -c 4
    
  3. Test the link to the Internet (this will fail if you usually connect to the Internet though a proxy server) as follows:

    ping www.raspberrypi.org -c 4
    
  4. Finally, you can test the link back to the Raspberry Pi by discovering the IP address using hostname -I on the Raspberry Pi. You can then use the ping command on another computer on the network to ensure it is accessible (using the Raspberry Pi's IP address in place of www.raspberrypi.org). The Windows version of the ping command will perform five pings and stop automatically and will not need the –c 4 option).

If the above tests fail, you will need to check your connections and then confirm the correct configuration for your network.

There's more…

If you find yourself using your Raspberry Pi regularly on the network and if you need to find out the IP address, you may find it helpful to fix the IP address to a known value by manually setting the IP address. However, remember to switch it back to use DHCP when connecting on another network.

Some routers will also have an option to set a Static IP DHCP address, so the same address is always given to the Raspberry Pi (how this is set will vary on the router itself).

Knowing your Raspberry Pi's IP address when it is on the network is particularly useful if you intend to use one of the remote access solutions described later on, which avoids the need for a display.

On some networks, you may be able to use the Raspberry Pi's hostname instead of its IP address (the default is raspberrypi), but not all networks will support this without additional software such as Bonjour (built in to OS X and available for Windows).

You have been reading a chapter from
Raspberry Pi cookbook for Python programmers
Published in: Apr 2014
Publisher:
ISBN-13: 9781849696623
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime