2010年6月21日月曜日

Arduino Ethernet shield

I finally figure out to use Ethernet Shield.

Even though Arduino provides a good example of web server, the beginner really does not understand it well.

Also the book "Making Things Talk" did not help me at all. Forget about it, it will not help you so much.


This is a tutorial of how to use Arduino's official Ethernet Shield as a web server. In oder to make a thing simple I do not add any sensor to analog pin of Arduino but you can play around it.  


Requirement

Your computer which has a Ethernet connection and USB. (I will explain about a case of Windows. If you are user of Linux or ... Mac find a same way by yourself. I am not familiar with  Linux and do not have Mac)

Internet connection

Arduino

Arduino program

Official Arduino Ethernet Shield which has a chip WIZnet W5100

two Ethernet cable. Do not use wireless except some situation. Especially if you want to do a same thing at school never use wireless otherwise you will wast 2 hours to realize your problem.

USB cable

Web Browser. (I checked with IE in this time, but I think I really does not matter)

A little knowledge of network(I will explain later).


Step one

First thing you need to do is to build Arduino Ethernet shield ready to use.

see the following picture.



you can add sensor to the analog pin if you want you will those value through the Internet.

+ Do not connect any thing to the digital pins number 10, 11, 12, and  13 . Even though they are looked vacant pins since they are already used by Ethernet Shield.

Second Step

Load a ready made program that is in samples.

File>Examples>Ethernet>WebServer.



The ready made program will be load in a new window.

However it is not ready to upload them.

If you see the program you will see a cords



byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte ip[] = { 127, 0, 0, 1 };

Server server(80);

These are very fundamental information of network.

Since I am not a specialist of network, I can not tell exactly but mac and ip are addresses that indicate your computer. 

the number 80 is called a port number. Usually "http"(which you often seen in a address bar of the browser) uses port number 80.

Before upload we have to figure out and tell the address of the Arduino. (I think probably that is because Arduino Ethernet shield do not have a function of DHCP server.)

Step 3

Detect addresses.

Fortunately, we do not need to spend so much effort to figure out addresses.

In the book "Making Things Talk" mention about the software PuTTy(PuTTy is Only for Windows, Linux and Mac need other software) in order to find a address called MAC address.

MAC address is a physical address that is recorded in your microchip and it will not change.(We also need IP address that will change normally unless you have a fixed IP address or do a special setup.

Look at a back side of Arduino Ethernet Shield 

You will see unfamiliar numbers that is looked like XX-XX-XX-XX-XX-XX

Since it is a hexadecimal number system the numbers contain alphabet. 






These numbers(Actually number) are called MAC address.  

Next you need to find your IP address.

Connect your computer to the Internet with Ethernet Cable.

You need to do a "Hacker" like thing to find. 

======Windows only ========================

go to Start> accessory>command prompt.

You will see DOS  window(I do not know how many people know DOS but)

You have to use it CUI

Type following and hit Enter:

ipconfig /all

This is a very useful commend that worth to remember.

You will see following thing



(sorry my computer runs Japanese operating system)

You will probably see "IPv4 address" which is your IP address.

IP address is looked like thins:

127.0.0.1

Now you have all the information you need.

=============For Linux and Mac and Windows user, who do not like CUI,===========

Go a web page that will tell your IP address. There are so many web page that tells your IP address.

Do not use proxy server and also your Internet security application potentially cause problem.

Linux must have a command that tells your IP address, since it is a operating system mainly for server but I am not sure.

I think Mac also has similar thing but I do not know.

==================================================================


go back to the program and replace the number to your number.

byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte ip[] = { 127, 0, 0, 1 };

Server server(80);

 You do not need to do any thing for port number unless your router has some special setup.

Step 4

You are ready to upload a program to the Arduino.

Upload the program.

Unplug the Ethernet cable that is connected to your computer(only the side of computer) and plug it to Arduino.



Bring another new cable and connect  your computer and the router.

Step 5

Run a browser.

I use IE since I used a school computer that was already connected to the network.

In the browser's address bar, type the IP address that you program.


http://127.0.0.1(use your own number.)


The number something like 127.0.0.1 is same as http://www.google.com they are looked different but they actually almost same. Since for humans  IP address is not easy to remember, a DNS server change it to words that human can easily remember.

(127.0.0.1 does not indicate Google webpage. 127.0.0.1 is a special IP address that is indicate your computer(localhost) so that if you run server system in your computer with Apache you will use it.)  


If you see a information of analog pin of Arduino.

If you choose other than 80 for port number you need to specify the port.


http://127.0.0.1:8080

I you have any trouble it must be caused by firewall of the router, programed wrong number or other many reasons. 

 






 

0 件のコメント:

コメントを投稿