Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Measurement Management
- - Source Code NOT compiled for: Arduino Nano 33 BLE
- - Source Code created on: 2025-07-05 00:16:04
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Detect and initialize the Ethernet connection */
- /* using the Ethernet2 library and the W5500 module. */
- /* Retrieve and display the assigned IP address to */
- /* confirm successful connection. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* Monitor and read all channels connected via the */
- /* PCF8575 I2C expander periodically, ensuring real- */
- /* time data acquisition from the digital inputs. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SPI.h>
- #include <Wire.h>
- #include <Ethernet2.h> //https://github.com/adafruit/Ethernet2
- #include <PCF8575.h> //https://github.com/RobTillaart/PCF8575.git
- #include <DFRobot_ADS1115.h> //https://github.com/DFRobot/DFRobot_ADS1115
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void initializeEthernet();
- void readAllChannels();
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t ethernet_W5500_RST_PIN_D2 = 2;
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t pdf_PCF8575_I2C_PIN_SDA_A4 = A4;
- const uint8_t pdf_PCF8575_I2C_PIN_SCL_A5 = A5;
- const uint8_t pdf_PCF8575_I2C_SLAVE_ADDRESS = 32;
- const uint8_t adc_ADS1115_I2C_PIN_SDA_A4 = A4;
- const uint8_t adc_ADS1115_I2C_PIN_SCL_A5 = A5;
- const uint8_t adc_ADS1115_I2C_SLAVE_ADDRESS = 72;
- /***** DEFINITION OF SPI PINS *****/
- const uint8_t ethernet_W5500_SPI_PIN_MOSI_D11 = 11;
- const uint8_t ethernet_W5500_SPI_PIN_MISO_D12 = 12;
- const uint8_t ethernet_W5500_SPI_PIN_SCLK_D13 = 13;
- const uint8_t ethernet_W5500_SPI_PIN_CS_D10 = 10;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool ethernet_W5500_RST_PIN_D2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float ethernet_W5500_RST_PIN_D2_phyData = 0.0;
- /****** LIBRARY INSTANCES *****/
- PCF8575 pcf8575Device(pdf_PCF8575_I2C_SLAVE_ADDRESS);
- DFRobot_ADS1115 ads1115(&Wire);
- /* Initialize Ethernet connection */
- void initializeEthernet() {
- pinMode(ethernet_W5500_RST_PIN_D2, OUTPUT);
- digitalWrite(ethernet_W5500_RST_PIN_D2, LOW);
- delay(10);
- digitalWrite(ethernet_W5500_RST_PIN_D2, HIGH);
- delay(100);
- // Start Ethernet with DHCP
- if (Ethernet.begin()) {
- Serial.print("Ethernet initialized. IP address: ");
- Serial.println(Ethernet.localIP());
- } else {
- Serial.println("Failed to initialize Ethernet");
- }
- }
- /* Read all channels from PCF8575 and print the values */
- void readAllChannels() {
- uint16_t inputStates = pcf8575Device.read16();
- Serial.print("PCF8575 Input States: 0x");
- Serial.println(inputStates, HEX);
- }
- /* Setup function */
- void setup(void) {
- Serial.begin(9600);
- while (!Serial) {
- ; // wait for serial port to connect
- }
- // Initialize Ethernet connection
- initializeEthernet();
- // Initialize I2C
- Wire.begin();
- // Initialize PCF8575 device
- if (pcf8575Device.begin()) {
- Serial.println("PCF8575 device initialized successfully.");
- } else {
- Serial.println("Failed to initialize PCF8575 device.");
- }
- // Initialize ADS1115 device
- ads1115.setAddr_ADS1115(adc_ADS1115_I2C_SLAVE_ADDRESS);
- ads1115.init();
- // Optional: Configure ADS1115 gain, mode, etc.
- ads1115.setGain(eGAIN_TWO);
- ads1115.setMode(eMODE_SINGLE);
- Serial.println("Setup complete.");
- }
- /* Main loop */
- void loop(void) {
- // Periodically read all channels from PCF8575
- readAllChannels();
- // Add delay for periodic reading
- delay(1000);
- }
- /* Update outputs based on raw data */
- void updateOutputs() {
- digitalWrite(ethernet_W5500_RST_PIN_D2, ethernet_W5500_RST_PIN_D2_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement