Advertisement
pleasedontcode

Measurement Management rev_07

Jul 4th, 2025
215
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: Measurement Management
  13.     - Source Code NOT compiled for: Arduino Nano 33 BLE
  14.     - Source Code created on: 2025-07-05 00:16:04
  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. /****** SYSTEM REQUIREMENT 2 *****/
  25.     /* Monitor and read all channels connected via the */
  26.     /* PCF8575 I2C expander periodically, ensuring real- */
  27.     /* time data acquisition from the digital inputs. */
  28. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30. /* START CODE */
  31.  
  32. /****** DEFINITION OF LIBRARIES *****/
  33. #include <SPI.h>
  34. #include <Wire.h>
  35. #include <Ethernet2.h>  //https://github.com/adafruit/Ethernet2
  36. #include <PCF8575.h>    //https://github.com/RobTillaart/PCF8575.git
  37. #include <DFRobot_ADS1115.h>    //https://github.com/DFRobot/DFRobot_ADS1115
  38.  
  39. /****** FUNCTION PROTOTYPES *****/
  40. void setup(void);
  41. void loop(void);
  42. void initializeEthernet();
  43. void readAllChannels();
  44.  
  45. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  46. const uint8_t ethernet_W5500_RST_PIN_D2 = 2;
  47.  
  48. /***** DEFINITION OF I2C PINS *****/
  49. const uint8_t pdf_PCF8575_I2C_PIN_SDA_A4 = A4;
  50. const uint8_t pdf_PCF8575_I2C_PIN_SCL_A5 = A5;
  51. const uint8_t pdf_PCF8575_I2C_SLAVE_ADDRESS = 32;
  52. const uint8_t adc_ADS1115_I2C_PIN_SDA_A4 = A4;
  53. const uint8_t adc_ADS1115_I2C_PIN_SCL_A5 = A5;
  54. const uint8_t adc_ADS1115_I2C_SLAVE_ADDRESS = 72;
  55.  
  56. /***** DEFINITION OF SPI PINS *****/
  57. const uint8_t ethernet_W5500_SPI_PIN_MOSI_D11 = 11;
  58. const uint8_t ethernet_W5500_SPI_PIN_MISO_D12 = 12;
  59. const uint8_t ethernet_W5500_SPI_PIN_SCLK_D13 = 13;
  60. const uint8_t ethernet_W5500_SPI_PIN_CS_D10 = 10;
  61.  
  62. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  63. /***** used to store raw data *****/
  64. bool ethernet_W5500_RST_PIN_D2_rawData = 0;
  65.  
  66. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  67. /***** used to store data after characteristic curve transformation *****/
  68. float ethernet_W5500_RST_PIN_D2_phyData = 0.0;
  69.  
  70. /****** LIBRARY INSTANCES *****/
  71. PCF8575 pcf8575Device(pdf_PCF8575_I2C_SLAVE_ADDRESS);
  72. DFRobot_ADS1115 ads1115(&Wire);
  73.  
  74. /* Initialize Ethernet connection */
  75. void initializeEthernet() {
  76.   pinMode(ethernet_W5500_RST_PIN_D2, OUTPUT);
  77.   digitalWrite(ethernet_W5500_RST_PIN_D2, LOW);
  78.   delay(10);
  79.   digitalWrite(ethernet_W5500_RST_PIN_D2, HIGH);
  80.   delay(100);
  81.   // Start Ethernet with DHCP
  82.   if (Ethernet.begin()) {
  83.     Serial.print("Ethernet initialized. IP address: ");
  84.     Serial.println(Ethernet.localIP());
  85.   } else {
  86.     Serial.println("Failed to initialize Ethernet");
  87.   }
  88. }
  89.  
  90. /* Read all channels from PCF8575 and print the values */
  91. void readAllChannels() {
  92.   uint16_t inputStates = pcf8575Device.read16();
  93.   Serial.print("PCF8575 Input States: 0x");
  94.   Serial.println(inputStates, HEX);
  95. }
  96.  
  97. /* Setup function */
  98. void setup(void) {
  99.   Serial.begin(9600);
  100.   while (!Serial) {
  101.     ; // wait for serial port to connect
  102.   }
  103.  
  104.   // Initialize Ethernet connection
  105.   initializeEthernet();
  106.  
  107.   // Initialize I2C
  108.   Wire.begin();
  109.  
  110.   // Initialize PCF8575 device
  111.   if (pcf8575Device.begin()) {
  112.     Serial.println("PCF8575 device initialized successfully.");
  113.   } else {
  114.     Serial.println("Failed to initialize PCF8575 device.");
  115.   }
  116.  
  117.   // Initialize ADS1115 device
  118.   ads1115.setAddr_ADS1115(adc_ADS1115_I2C_SLAVE_ADDRESS);
  119.   ads1115.init();
  120.  
  121.   // Optional: Configure ADS1115 gain, mode, etc.
  122.   ads1115.setGain(eGAIN_TWO);
  123.   ads1115.setMode(eMODE_SINGLE);
  124.  
  125.   Serial.println("Setup complete.");
  126. }
  127.  
  128. /* Main loop */
  129. void loop(void) {
  130.   // Periodically read all channels from PCF8575
  131.   readAllChannels();
  132.  
  133.   // Add delay for periodic reading
  134.   delay(1000);
  135. }
  136.  
  137. /* Update outputs based on raw data */
  138. void updateOutputs() {
  139.   digitalWrite(ethernet_W5500_RST_PIN_D2, ethernet_W5500_RST_PIN_D2_rawData);
  140. }
  141.  
  142. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement