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: # Serial Monitor
- - Source Code compiled for: ESP32 DevKit V1
- - Source Code created on: 2026-02-28 09:46:17
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* **Proposal 2**: "Configure ESP32 DevKit V1 serial */
- /* communication to send sensor data readings over */
- /* UART at 115200 baud rate for real-time */
- /* monitoring." */
- /****** END SYSTEM REQUIREMENTS *****/
- // Global variables for sensor data storage
- float sensorValue1 = 0.0;
- float sensorValue2 = 0.0;
- float sensorValue3 = 0.0;
- // UART Configuration Constants
- #define UART_BAUD_RATE 115200
- #define SERIAL_TX_BUFFER_SIZE 256
- #define SENSOR_READ_INTERVAL 1000 // milliseconds
- // Timing variables
- unsigned long lastSensorReadTime = 0;
- void setup(void)
- {
- // Initialize serial communication with 115200 baud rate
- initSerialCommunication();
- // Small delay to ensure serial is ready
- delay(500);
- // Send initialization message
- Serial.println("\n===========================================");
- Serial.println("ESP32 DevKit V1 - Sensor Data Monitor");
- Serial.println("UART Configuration: 115200 baud rate");
- Serial.println("System Ready for Real-time Monitoring");
- Serial.println("===========================================\n");
- }
- void loop(void)
- {
- // Check if it's time to read sensor data
- if (millis() - lastSensorReadTime >= SENSOR_READ_INTERVAL)
- {
- // Read sensor values
- readSensorData();
- // Transmit sensor data over UART
- transmitSensorData();
- // Update last read time
- lastSensorReadTime = millis();
- }
- }
- /**
- * Function: initSerialCommunication
- * Purpose: Configure and initialize ESP32 UART serial communication
- * Parameters: None
- * Returns: None
- * Description: Initializes the primary UART (Serial0) with 115200 baud rate
- */
- void initSerialCommunication(void)
- {
- // Initialize Serial (UART0) with 115200 baud rate
- // ESP32 uses GPIO1 (TX) and GPIO3 (RX) by default for Serial
- Serial.begin(UART_BAUD_RATE);
- // Wait for serial port to connect (required for some ESP32 boards)
- // Timeout after 2 seconds if not connected
- unsigned long startTime = millis();
- while (!Serial && (millis() - startTime < 2000))
- {
- delay(10);
- }
- }
- /**
- * Function: readSensorData
- * Purpose: Read analog sensor values from ESP32 ADC pins
- * Parameters: None
- * Returns: None
- * Description: Simulates reading sensor data. In real application, replace with actual ADC reads.
- * This example demonstrates the sensor data acquisition pattern.
- */
- void readSensorData(void)
- {
- // Read analog sensor values from ADC pins
- // Sensor 1: ADC0 (GPIO36/VP)
- sensorValue1 = analogRead(36) * (3.3 / 4095.0);
- // Sensor 2: ADC1 (GPIO39/VN)
- sensorValue2 = analogRead(39) * (3.3 / 4095.0);
- // Sensor 3: ADC2 (GPIO34/GPIO4) - Note: ADC2 pins cannot be used while WiFi is on
- sensorValue3 = analogRead(34) * (3.3 / 4095.0);
- }
- /**
- * Function: transmitSensorData
- * Purpose: Send sensor data readings over UART at 115200 baud rate
- * Parameters: None
- * Returns: None
- * Description: Formats and transmits sensor data in a structured format for real-time monitoring.
- * Includes timestamp, sensor values, and checksum verification capability.
- */
- void transmitSensorData(void)
- {
- // Get current timestamp
- unsigned long currentTime = millis();
- // Format and transmit header
- Serial.print("[");
- Serial.print(currentTime);
- Serial.print("ms] ");
- // Transmit Sensor Data
- Serial.print("SENSORS: ");
- Serial.print("CH1=");
- Serial.print(sensorValue1, 3);
- Serial.print("V ");
- Serial.print("CH2=");
- Serial.print(sensorValue2, 3);
- Serial.print("V ");
- Serial.print("CH3=");
- Serial.print(sensorValue3, 3);
- Serial.println("V");
- // Transmit raw ADC values for reference
- Serial.print("[RAW VALUES] ");
- Serial.print("ADC0=");
- Serial.print(analogRead(36));
- Serial.print(" ");
- Serial.print("ADC1=");
- Serial.print(analogRead(39));
- Serial.print(" ");
- Serial.print("ADC2=");
- Serial.println(analogRead(34));
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment