Advertisement
Guest User

Arduino MEGA + Ethernetshield

a guest
Mar 4th, 2014
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4. byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  5. IPAddress ip(10,0,0,177);
  6.  
  7. EthernetServer server(80);
  8.  
  9. void setup() {
  10.   // Open serial communications and wait for port to open:
  11.   Serial.begin(9600);
  12.  
  13.   // SS must be output and disable any device using SS
  14.   pinMode(53,OUTPUT);
  15.   digitalWrite(53,HIGH); //any device on the SS pin will be disabled
  16.  
  17.   // disable w5100
  18.   pinMode(10,OUTPUT);
  19.   digitalWrite(10,HIGH);   // disable W5100
  20.  
  21.   // disable SD
  22.   pinMode(4,OUTPUT);
  23.   digitalWrite(4,HIGH);  // disable SD
  24.  
  25.   //Add code in function setup(), i'm success.
  26. pinMode(11,INPUT);
  27. pinMode(12,INPUT);
  28. pinMode(13,INPUT);
  29.  
  30.   // start the Ethernet connection and the server:
  31.   // Try DHCP first, if that fails, try fixed ip.
  32.   if (Ethernet.begin(mac) == 0)
  33.   {
  34.     Serial.println(F("DHCP failed"));
  35.     Ethernet.begin(mac,ip);
  36.   }
  37.  
  38.   server.begin();
  39.   Serial.print("server is at ");
  40.   Serial.println(Ethernet.localIP());
  41. }
  42.  
  43. void loop() {
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement