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: Two Words
- - Source Code NOT compiled for: Arduino Nano 33 BLE
- - Source Code created on: 2025-06-20 08:50:20
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Implement a system that reads digital inputs from */
- /* the PCF8575 I/O expander and analog signals from */
- /* the ADS1115 ADC, then processes and displays the */
- /* data on the Arduino Nano 33 BLE. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <PCF8575.h>
- #include <DFRobot_ADS1115.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t ioexpander_PCF8575_I2C_PIN_SDA_A4 = A4;
- const uint8_t ioexpander_PCF8575_I2C_PIN_SCL_A5 = A5;
- const uint8_t ioexpander_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;
- /****** LIBRARY CLASS INSTANCES *****/
- PCF8575 pcf8575(ioexpander_PCF8575_I2C_SLAVE_ADDRESS, &Wire);
- DFRobot_ADS1115 ads(&Wire);
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(9600);
- while (!Serial);
- // Initialize I2C communication
- Wire.begin();
- // Initialize PCF8575 I/O expander
- if (pcf8575.begin()) {
- Serial.println("PCF8575 initialized successfully");
- } else {
- Serial.println("PCF8575 initialization failed");
- }
- // Initialize ADS1115 ADC
- ads.setAddr_ADS1115(adc_ADS1115_I2C_SLAVE_ADDRESS);
- ads.init();
- if (ads.checkADS1115()) {
- Serial.println("ADS1115 initialized successfully");
- } else {
- Serial.println("ADS1115 initialization failed");
- }
- }
- void loop(void)
- {
- // Read digital inputs from PCF8575
- uint16_t digitalInputs = pcf8575.read16();
- // Read analog voltage from ADS1115 channel 0
- uint16_t adcValue = ads.readVoltage(0);
- float voltage = adcValue * 0.1875 / 1000; // Convert to millivolts
- // Display the digital inputs
- Serial.print("Digital Inputs (PCF8575): 0x");
- Serial.println(digitalInputs, HEX);
- // Display the analog voltage
- Serial.print("Analog Voltage (ADS1115 CH0): ");
- Serial.print(voltage, 3);
- Serial.println(" V");
- delay(1000); // Wait for 1 second before next reading
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement