Skip to content

RobotDyn MEGA 2560 ETH R3

RobotDyn MEGA 2560 ETH R3

praveen_k

Published October 05, 2021

Project description

I/O defines on Mega ETH

For Ethernet W5500 Chipset:
  • D10 ? SS (CS1)
  • D51 ? MOSI
  • D50 ? MISO
  • D52 ? SCK
  • D8 ? INT (select D8 with W5500-INT pin jumper, pin solder jumper at bottom layer, default: not connected)
  • D7/3.3V ? RST (select D7 with W5500-RST pin solder jumper at the bottom layer, default: connected to 3.3V)
For SD card reader:
  • D4 ? CS(CS2)
  • D9 ? Card detect (pin solder jumper at bottom layer, default: not connected)
  • D51 ? MOSI/DI
  • D50 ? MISO/DO
  • D52 ? SCK/CLK
NOTE:?Both W5500 and SD card communicate with ATmega2560 via SPI bus. Pin D10 and pin D4 are chip Selection pins for W5500 and SD slot. They cannot be used as general I/O. ?

Steps for Arduino IDE:

    1. Select port:
Steps for Arduino IDE:  
    1. Select board:
Steps for Arduino IDE:
  1. Please install the libraries:
    • SD.h ??SD?Library
    • SPI.h ??SPI library
    • Ethernet.h/Ethernet2.h/ Ethernet3.h ? Ethernet / Ethernet2 / Ethernet3 libraries
Copy below code into the sketch and then upload:?
  1. #include <Ethernet3.h>
  2. #include <SPI.h>
  3. #include <EEPROM.h>
  4. #include <SD.h>
  5. #define SS 10 //W5500 CS
  6. #define RST 7 //W5500 RST
  7. #define CS 4 //SD CS pin
  8. // enter MAC-address and IP-address of your controller below;
  9. // IP-address depends on your local network:
  10. byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  11. char macstr[18];
  12. IPAddress ip(192,168,1,111);
  13. // initialize Ethernet Server library by designating a port
  14. // (default port for HTTP is ≪80≫):
  15. EthernetServer server(80);
  16. // specifying a contact and default state for LED:
  17. String LED1State = "Off";
  18. const int LED = 13;
  19. // specifying variables for the client:
  20. char linebuf[80];
  21. int charcount=0;
  22. void eeprom_read()
  23. {
  24. if (EEPROM.read(1) == '#')
  25. {
  26. for (int i = 2; i < 6; i++)
  27. {
  28. mac[i] = EEPROM.read(i);
  29. }
  30. }
  31. }
  32. void eeprom_write()
  33. {
  34. EEPROM.write(1, '#');
  35. snprintf(macstr, 18, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  36. }
  37. void setup() {
  38. // preparing LED-module:
  39. pinMode(LED_BUILTIN, OUTPUT);
  40. digitalWrite(LED_BUILTIN, HIGH);
  41. pinMode(SS, OUTPUT);
  42. pinMode(RST, OUTPUT);
  43. pinMode(CS, OUTPUT);
  44. digitalWrite(SS, LOW);
  45. digitalWrite(CS, HIGH);
  46. /* If you want to control Reset function of W5500 Ethernet controller */
  47. digitalWrite(RST,HIGH);
  48. pinMode(LED, OUTPUT);
  49. digitalWrite(LED, HIGH);
  50. // opening a sequential communication with 9600 baud speed:
  51. Serial.begin(9600);
  52. eeprom_read();
  53. eeprom_write();
  54. // initialising Ethernet-communication and server:
  55. Ethernet.begin(mac, ip);
  56. server.begin();
  57. Serial.print("server is at "); // "server at "
  58. Serial.println(Ethernet.localIP());
  59. Serial.println(Ethernet.macAddressReport());
  60. }
  61. // Displaying a webpage with a ≪ON/OFF≫ button for LED:
  62. void dashboardPage(EthernetClient &client) {
  63. client.println("<!DOCTYPE HTML><html><head>");
  64. client.println("<meta name="viewport" content="width=device-width, initial-scale=1"></head><body>");
  65. client.println("<h3>Arduino Web Server - <a href="/">Refresh</a></h3>");
  66. client.println("<h3>local IP<h3>");
  67. client.println(Ethernet.localIP());
  68. client.println("<h3>");
  69. client.println("<h3>mac Address<h3>");
  70. client.println(Ethernet.macAddressReport());
  71. client.println("<h3>");
  72. client.println("<h3>TEXT<h3>");
  73. client.println("<section id="contact"><div class="content"><div id="form"><form action=""id="contactForm"method="GET"><textarea class="message"placeholder="Enter your message"tabindex=4></textarea><input type="submit"name="submit"value="Send to Serial"class="submit"tabindex=5></form></div></section>");
  74. // generating a button to control LED:
  75. client.println("<h4>LED 13 - State: " + LED1State + "</h4>");
  76. // if LED is off, Displaying an ≪ON≫ button:
  77. if(LED1State == "Off"){
  78. client.println("<a href="/LED13on"><button>ON</button></a>");
  79. }
  80. // if LED is on, Displaying an ≪OFF≫ button:
  81. else if(LED1State == "On"){
  82. client.println("<a href="/LED13off"><button>OFF</button></a>");
  83. }
  84. client.println("</body></html>");
  85. }
  86. void loop() {
  87. // reading the incoming clients:
  88. EthernetClient client = server.available();
  89. if (client) {
  90. //Serial.print (client.read());
  91. //Serial.println("new client"); // "new client"
  92. memset(linebuf,0,sizeof(linebuf));
  93. charcount=0;
  94. // HTTP-request is ending with blank line:
  95. boolean currentLineIsBlank = true;
  96. while (client.connected()) {
  97. if (client.available()) {
  98. char c = client.read();
  99. // reading a HTTP-request, one symbol at a time:
  100. linebuf[charcount]=c;
  101. if (charcount<sizeof(linebuf)-1) charcount++;
  102. // if you reached the end of the line (i.e. if you recieved
  103. // symbol form a new line), it means that
  104. // HTTP-request is completed, and you can send the answer:
  105. if (c == 'n' && currentLineIsBlank) {
  106. dashboardPage(client);
  107. break;
  108. }
  109. if (c == 'n') {
  110. if (strstr(linebuf,"GET /id=") > 0)Serial.println(linebuf);
  111. if (strstr(linebuf,"GET /LED13off") > 0){
  112. digitalWrite(LED, HIGH);
  113. LED1State = "Off";
  114. }
  115. else if (strstr(linebuf,"GET /LED13on") > 0){
  116. digitalWrite(LED, LOW);
  117. LED1State = "On";
  118. }
  119. // if you recieved a symbol form a new line
  120. currentLineIsBlank = true;
  121. memset(linebuf,0,sizeof(linebuf));
  122. charcount=0;
  123. }
  124. else if (c != 'r') {
  125. // if you recieved any other symbol
  126. currentLineIsBlank = false;
  127. }
  128. }
  129. }
  130. // providing a time for a borwser to recieve the data:
  131. delay(1);
  132. // closing the connection:
  133. client.stop();
  134. //Serial.println("client disonnected"); // "Client is disconnected"
  135. }
  136. }

Result

RobotDyn MEGA 2560 ETH R3, Result?RobotDyn MEGA 2560 ETH R3, Result?RobotDyn MEGA 2560 ETH R3, Result

Documents

Comments

Comments