Advertisement
pleasedontcode

Signal Monitor rev_02

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