Advertisement
pleasedontcode

Network Connection rev_01

Jun 20th, 2025
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Network Connection
  13.     - Source Code NOT compiled for: Arduino Nano 33 BLE
  14.     - Source Code created on: 2025-06-20 07:02:05
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Detect and initialize the Ethernet connection */
  21.     /* using the Ethernet2 library and the W5500 module. */
  22.     /* Retrieve and display the assigned IP address to */
  23.     /* confirm successful connection. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <SPI.h>
  30. #include <Ethernet2.h> //https://github.com/adafruit/Ethernet2
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs(void);
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t ethernet_W5500_RST_PIN_D2 = 2;
  39.  
  40. /***** DEFINITION OF SPI PINS *****/
  41. const uint8_t ethernet_W5500_SPI_PIN_MOSI_D11 = 11;
  42. const uint8_t ethernet_W5500_SPI_PIN_MISO_D12 = 12;
  43. const uint8_t ethernet_W5500_SPI_PIN_SCLK_D13 = 13;
  44. const uint8_t ethernet_W5500_SPI_PIN_CS_D10 = 10;
  45.  
  46. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  47. /***** used to store raw data *****/
  48. bool ethernet_W5500_RST_PIN_D2_rawData = 0;
  49.  
  50. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  51. /***** used to store data after characteristic curve transformation *****/
  52. float ethernet_W5500_RST_PIN_D2_phyData = 0.0;
  53.  
  54. /****** LIBRARY OBJECT INSTANCES *****/
  55. // Instantiate Ethernet object
  56. EthernetClass Ethernet;
  57.  
  58. /****** NETWORK CONFIGURATION *****/
  59. // Define static IP address (modify as needed)
  60. IPAddress localIp(192, 168, 1, 177); // Example IP address
  61. IPAddress dnsServer(8, 8, 8, 8);    // Example DNS server (Google DNS)
  62.  
  63. /****** SETUP FUNCTION *****/
  64. void setup(void)
  65. {
  66.   // Initialize Ethernet connection
  67.   Ethernet.init(ethernet_W5500_SPI_PIN_CS_D10); // Set CS pin
  68.   int result = Ethernet.begin( /*mac address*/ NULL, localIp, dnsServer);
  69.   if (result == 0)
  70.   {
  71.     Serial.begin(9600);
  72.     Serial.println("Ethernet initialization failed");
  73.   }
  74.   else
  75.   {
  76.     Serial.begin(9600);
  77.     Serial.print("Ethernet IP address: ");
  78.     Serial.println(Ethernet.localIP());
  79.   }
  80.  
  81.   // put your setup code here, to run once:
  82.   pinMode(ethernet_W5500_RST_PIN_D2, OUTPUT);
  83.   pinMode(ethernet_W5500_SPI_PIN_CS_D10, OUTPUT);
  84.   // start the SPI library:
  85.   SPI.begin();
  86. }
  87.  
  88. /***** LOOP FUNCTION *****/
  89. void loop(void)
  90. {
  91.   // put your main code here, to run repeatedly:
  92.   updateOutputs(); // Refresh output data
  93. }
  94.  
  95. /***** UPDATE OUTPUTS FUNCTION *****/
  96. void updateOutputs()
  97. {
  98.   digitalWrite(ethernet_W5500_RST_PIN_D2, ethernet_W5500_RST_PIN_D2_rawData);
  99. }
  100.  
  101. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement