Advertisement
pleasedontcode

**Data Logging** rev_01

Feb 25th, 2025
220
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: **Data Logging**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-02-25 09:06:44
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* ESP32 connects to RS485 & SD Card  Reads data */
  21.     /* every second and logs to CSV  Displays data as */
  22.     /* curves on the touchscreen Uses LVGL GUI */
  23.     /* Touchscreen buttons allow pause, scale change, and */
  24.     /* clearing  Tap "Export" button to send email with */
  25.     /* CSV */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /* START CODE */
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <SPI.h>
  32. #include <SdFat.h>  //https://github.com/greiman/SdFat
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. /***** DEFINITION OF SPI PINS *****/
  39. const uint8_t mySDCardModule_SDCardModule_SPI_PIN_MOSI_D23      = 23;
  40. const uint8_t mySDCardModule_SDCardModule_SPI_PIN_MISO_D19      = 19;
  41. const uint8_t mySDCardModule_SDCardModule_SPI_PIN_SCLK_D18      = 18;
  42. const uint8_t mySDCardModule_SDCardModule_SPI_PIN_CS_D5     = 5;
  43.  
  44. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  45. // Create an instance of the SdFat class
  46. SdFat SD;
  47.  
  48. // Variables for logging and timing
  49. unsigned long previousMillis = 0; // Store last time data was logged
  50. const long interval = 1000; // Interval for logging data (1 second)
  51.  
  52. // Function prototypes for additional functionalities
  53. void logDataToCSV();
  54. void sendEmailWithCSV();
  55.  
  56. void setup(void)
  57. {
  58.     // put your setup code here, to run once:
  59.     pinMode(mySDCardModule_SDCardModule_SPI_PIN_CS_D5, OUTPUT);
  60.     // start the SPI library:
  61.     SPI.begin();
  62.  
  63.     // Initialize SD card
  64.     if (!SD.begin(mySDCardModule_SDCardModule_SPI_PIN_CS_D5)) {
  65.         Serial.println("SD Card initialization failed!");
  66.         return;
  67.     }
  68.     Serial.println("SD Card initialized successfully.");
  69. }
  70.  
  71. void loop(void)
  72. {
  73.     // put your main code here, to run repeatedly:
  74.     unsigned long currentMillis = millis();
  75.     if (currentMillis - previousMillis >= interval) {
  76.         previousMillis = currentMillis;
  77.         logDataToCSV(); // Log data every second
  78.     }
  79. }
  80.  
  81. // Function to log data to CSV
  82. void logDataToCSV() {
  83.     // Implement the logic to read data from RS485 and log it to CSV
  84.     // This is a placeholder for the actual implementation
  85.     Serial.println("Logging data to CSV...");
  86. }
  87.  
  88. // Function to send email with CSV
  89. void sendEmailWithCSV() {
  90.     // Implement the logic to send email with the CSV file
  91.     // This is a placeholder for the actual implementation
  92.     Serial.println("Sending email with CSV...");
  93. }
  94.  
  95. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement