Advertisement
pleasedontcode

Two Words rev_01

Jun 20th, 2025
295
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: Two Words
  13.     - Source Code NOT compiled for: Arduino Nano 33 BLE
  14.     - Source Code created on: 2025-06-20 08:50:20
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a system that reads digital inputs from */
  21.     /* the PCF8575 I/O expander and analog signals from */
  22.     /* the ADS1115 ADC, then processes and displays the */
  23.     /* data on the Arduino Nano 33 BLE. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <Wire.h>
  30. #include <PCF8575.h>
  31. #include <DFRobot_ADS1115.h>
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. /***** DEFINITION OF I2C PINS *****/
  38. const uint8_t ioexpander_PCF8575_I2C_PIN_SDA_A4 = A4;
  39. const uint8_t ioexpander_PCF8575_I2C_PIN_SCL_A5 = A5;
  40. const uint8_t ioexpander_PCF8575_I2C_SLAVE_ADDRESS = 32;
  41. const uint8_t adc_ADS1115_I2C_PIN_SDA_A4 = A4;
  42. const uint8_t adc_ADS1115_I2C_PIN_SCL_A5 = A5;
  43. const uint8_t adc_ADS1115_I2C_SLAVE_ADDRESS = 72;
  44.  
  45. /****** LIBRARY CLASS INSTANCES *****/
  46. PCF8575 pcf8575(ioexpander_PCF8575_I2C_SLAVE_ADDRESS, &Wire);
  47. DFRobot_ADS1115 ads(&Wire);
  48.  
  49. void setup(void)
  50. {
  51.   // Initialize serial communication for debugging
  52.   Serial.begin(9600);
  53.   while (!Serial);
  54.  
  55.   // Initialize I2C communication
  56.   Wire.begin();
  57.  
  58.   // Initialize PCF8575 I/O expander
  59.   if (pcf8575.begin()) {
  60.     Serial.println("PCF8575 initialized successfully");
  61.   } else {
  62.     Serial.println("PCF8575 initialization failed");
  63.   }
  64.  
  65.   // Initialize ADS1115 ADC
  66.   ads.setAddr_ADS1115(adc_ADS1115_I2C_SLAVE_ADDRESS);
  67.   ads.init();
  68.  
  69.   if (ads.checkADS1115()) {
  70.     Serial.println("ADS1115 initialized successfully");
  71.   } else {
  72.     Serial.println("ADS1115 initialization failed");
  73.   }
  74. }
  75.  
  76. void loop(void)
  77. {
  78.   // Read digital inputs from PCF8575
  79.   uint16_t digitalInputs = pcf8575.read16();
  80.  
  81.   // Read analog voltage from ADS1115 channel 0
  82.   uint16_t adcValue = ads.readVoltage(0);
  83.   float voltage = adcValue * 0.1875 / 1000; // Convert to millivolts
  84.  
  85.   // Display the digital inputs
  86.   Serial.print("Digital Inputs (PCF8575): 0x");
  87.   Serial.println(digitalInputs, HEX);
  88.  
  89.   // Display the analog voltage
  90.   Serial.print("Analog Voltage (ADS1115 CH0): ");
  91.   Serial.print(voltage, 3);
  92.   Serial.println(" V");
  93.  
  94.   delay(1000); // Wait for 1 second before next reading
  95. }
  96.  
  97. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement