Talking to the network with an Arduino: Unterschied zwischen den Versionen

Aus DL8RDS Wiki
Wechseln zu: Navigation, Suche
Zeile 5: Zeile 5:
 
* Ethernet Shield, purchased from Watterott: http://www.watterott.com/Arduino-Shield-Ethernet
 
* Ethernet Shield, purchased from Watterott: http://www.watterott.com/Arduino-Shield-Ethernet
 
* LM75 temperature sensoe board from Horter & Kalb: http://www.horter.de/i2c/i2c-temperatur/temperatur_1.html
 
* LM75 temperature sensoe board from Horter & Kalb: http://www.horter.de/i2c/i2c-temperatur/temperatur_1.html
 +
 +
== Related ==
 +
* http://shop.ulrichradig.de/Projekte/ETH-M32-EX/ETH-M32-EX-Leiterplatte.html
  
 
== The Sketch ==
 
== The Sketch ==

Version vom 11. November 2009, 23:43 Uhr

Well, even this is most certainly no longer related to my SWR meter project, I just find that it's sooooo cool, so I will simply present some code here.

1 Hardware

2 Related

3 The Sketch

#include <Server.h>
#include <Ethernet.h>
#include <Client.h>

#include <Wire.h>

#define address 0x48

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte ip[] = {192, 168, 178, 190};
byte gateway[] ={192,168,178,1};
byte subnet[] = {255,255,255,0};
Server server = Server(80);

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
}

void loop()
{
  Client client = server.available();
  if (client) {
    Wire.beginTransmission(address);
    Wire.send(0x00);
    Wire.requestFrom(address, 1);
    int temperature;
    if (Wire.available()) {
      temperature = Wire.receive();
    }
    Wire.endTransmission();

    server.print("HTTP/1.0 200 OK\r\nServer: arduino\r\n");
    server.print("Content Type: text/html\r\n\r\n");
    server.print("Zimmertemperatur</head>\r\n");
     server.print("<body>Zimmertemperatur:<p>\r\n");
     server.print(temperature-4);
     server.print("<p>Uptime:");
     server.print(millis());
     server.print("ms.");
    delay(10);
    client.stop();
    Serial.println("-----------");
    Serial.println(temperature);
  }
}

It will show the room temperature of my lab. I used the above mentioned LM75 sensor from Horter and the Ethernet shield with the WIZnet Ethernet module that you can purchase from Watterott. Also have a look there:

http://www.mats-vanselow.de/2009/01/30/arduino-ins-netz-bringen/

Given that my controller grabs the temperature from the source via I2C, it would be no problem to connect several sensors over this bus. It would be possible to read out a huge number of data sources...