Enxugamento V13 - 2022

 /*

  * Arduino 1.8.10
  * Wilson Bueno  - 19/01/2022
  * V 13 - Funcional
  * Alterando o cabeçalho do nome dos canais por causa da exportação para o PLZ-DAQ Excel (*)
  * Colocando o nome da versão
*/

#include "RTClib.h" //biblioteca do RTC
#include "max6675.h" // biblioteca do shield max6675
//#include <SoftwareSerial.h> // biblioteca para bluetooth - retirado para diminuir o lag
#include <SPI.h> // biblioteca comunicação serial
#include <SD.h> // biblioteca cartão SD
//#include <dht.h> // biblioteca sensor umidade e temp - retirado para diminuir o lag
#include <LiquidCrystal.h> // biblioteca LCD

//Array of bytes - grade (°) special caracter
  byte slash[8]= {
    B01100,  // B stands for binary formatter and the 5 numbers are the pixels
    B10010,
    B01100,
    B00000,
    B00000,
    B00000,
    B00000,
    B00000,
  };

const int lederroPin = 37;  


//Initialize the library by associating any needed LCD interface pin with the arduino pin number it is connected to
  const int rs = 39, en = 41, d4 = 43, d5 = 45, d6 = 47, d7 = 49;
  LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

//RTC
  RTC_DS1307 rtc;
  char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

/*
//Bluetooth
  SoftwareSerial serial1(51, 53); // RX, TX do Bluetooth - padrão 10 e 11
  // Used to identify graphing values
     String graphTag = "Graph:";
  // Used to identify the separation of values inside the stream
     char valueSeparatorCharacter = '&';
  // Used to identify the end of the stream. This will apply for both the serial monitor and graph
     char terminationSeparatorCharacter = '$';

//Humidity and tempertures sensor - vai usar?
  dht DHT;
  uint32_t timer = 0;
  const int chipSelect = 10;
*/

//LCD millis time base
  unsigned long millisdisplaytime = millis();
     
//Open file on SD card
  File logfile;

void error(char *str)  {
   Serial.print("error: ");
   Serial.println(str);
   while(1);
   }

//Thermocouples modules max6675
  //1st thermocouple
  int so1Pin = 22;// SO=Serial Out do shield termopar
  int cs1Pin = 24;// CS = chip select CS pin do shield termopar
  int sck1Pin = 26;// SCK = Serial Clock pin do shield termopar
  //2nd thermocouple
  int so2Pin = 28;// SO=Serial Out do shield termopar
  int cs2Pin = 30;// CS = chip select CS pin do shield termopar
  int sck2Pin = 32;// SCK = Serial Clock pin do shield termopar
  //3rd thermocouple
  int so3Pin = 34;// SO=Serial Out do shield termopar
  int cs3Pin = 36;// CS = chip select CS pin do shield termopar
  int sck3Pin = 38;// SCK = Serial Clock pin do shield termopar
  //4th thermocouple
  int so4Pin = 40;// SO=Serial Out do shield termopar
  int cs4Pin = 42;// CS = chip select CS pin do shield termopar
  int sck4Pin = 44;// SCK = Serial Clock pin do shield termopar

  //MAX6675 instance
    MAX6675 robojax1(sck1Pin, cs1Pin, so1Pin);
    MAX6675 robojax2(sck2Pin, cs2Pin, so2Pin);
    MAX6675 robojax3(sck3Pin, cs3Pin, so3Pin);
    MAX6675 robojax4(sck4Pin, cs4Pin, so4Pin);

//Analogic channels for Time to Dry
  int correcao=204.7; // correção para mostrar em tensão
  float entradaA8 = 8; // variável que define que a porta A8 é flutuante
  float entradaA9 = 9; // variável que define que a porta A9 é flutuante
  float entradaA10 = 10; // variável que define que a porta A10 é flutuante
  float entradaA11 = 11; // variável que define que a porta A11 é flutuante
  float entradaA12 = 12; // variável que define que a porta A12 é flutuante
  float entradaA13 = 13; // variável que define que a porta A13 é flutuante
  float entradaA14 = 14; // variável que define que a porta A13 é flutuante
  float entradaA15 = 15; // variável que define que a porta A13 é flutuante  

//Variáveis para serial e cartão (*)
  float val1 = 0; //variável que guarda o valor lido na analógica
  float val2 = 0; //variável que guarda o valor lido na analógica
  float val3 = 0; //variável que guarda o valor lido na analógica
  float val4 = 0; //variável que guarda o valor lido na analógica
  float val5 = 0; //variável que guarda o valor lido na analógica
  float val6 = 0; //variável que guarda o valor lido na analógica
  float val7 = 0; //variável que guarda o valor lido na analógica
  float val8 = 0; //variável que guarda o valor lido na analógica

//Variáveis para LCD
  int val10 = 0; //variável que guarda o valor lido na analógica
  int val11 = 0; //variável que guarda o valor lido na analógica
  int val12 = 0; //variável que guarda o valor lido na analógica
  int val13 = 0; //variável que guarda o valor lido na analógica
  int val14 = 0; //variável que guarda o valor lido na analógica
  int val15 = 0; //variável que guarda o valor lido na analógica
  int val16 = 0; //variável que guarda o valor lido na analógica
  int val17 = 0; //variável que guarda o valor lido na analógica

 
//Serial date for PLX-DAQ Excel files
  int ROW = 0;
  int LABEL = 1;

//loop do STARTING no LCD
int x = 1;

//============================================================================
void setup() {

  //Set up the LCD's number of columns and rows:
    lcd.begin(16, 2); //4 linhas por causa dos menus
    lcd.createChar(7, slash); // Create a custom character for use on the LCD. Up to eight characters of 5x8 pixels are supported
     
  //Alimentação Led de erro
    pinMode (lederroPin, OUTPUT); // VCC
 

  //inicialização serial
    //serial1.begin(9600); // Para o bluetooth
    Serial.begin(9600); //inicialização serial
    Serial.println("CLEARDATA"); // reset da comunicação serial
    Serial.println("LABEL,Time,val1,val2,val3,val4,val5,val6,val7,val8,Temp1,Temp2,Temp3,Temp4,ROW"); // nomeia as colunas
   
  //SD card  
    Serial.print("Initializing SD card...");
    pinMode(10, OUTPUT); //shield SD
 
    //See if the card is present and can be initialized:
      if (!SD.begin(10, 11, 12, 13)) {  
      Serial.println("Card failed, or not present");
      digitalWrite(lederroPin, HIGH);   // turn the LED on (HIGH is the voltage level)
      lcd.clear();
      lcd.setCursor(3, 0);
      lcd.print("* FAIL ON *");
      lcd.setCursor(3, 1);
      lcd.print("* SD CARD *");
      while (1) ;
      }
      Serial.println("card initialized.");
 
  char caracter;
  DateTime now = rtc.now();
     
    //Create a new file sequencial on SD card
      char filename[] = "LOGGER00.TXT";
      for (uint8_t i = 0; i < 1000; i++)
      {
      filename[6] = i/10 + '0';
      filename[7] = i%10 + '0';
        if (! SD.exists(filename)) {
        // only open a new file if it doesn't exist
        logfile = SD.open(filename, FILE_WRITE);
        digitalWrite(lederroPin, LOW);    // turn the LED off by making the voltage LOW
           
        //loop para correr o STARTING
          while (x<=17) {
            lcd.clear();
            lcd.setCursor(3, 0);
            lcd.print("R&D MARELLI");
            lcd.print(" ");
            lcd.setCursor(x, 1);
            lcd.print("START V13-Jan22");
            //lcd.print("STARTING =|:)");
            delay(500);
            x++;
            }
            x = 0;
       
        break;  // leave the loop!
        }
       }
   
        if (! logfile) {
          error("couldnt create file");
          Serial.println("Fail to create file");
          lcd.clear();
          lcd.setCursor(3, 0);
          lcd.print("* FAIL ON *");
          lcd.setCursor(3, 1);
          lcd.print("* SD CARD *");
          digitalWrite(lederroPin, HIGH);   // turn the LED on (HIGH is the voltage level)
          }
          Serial.print("Logging to: ");
          Serial.println(filename);

  //Relógio RTC
      if (! rtc.begin()) {
        Serial.println("Couldn't find RTC");
        lcd.clear();
        lcd.setCursor(3, 0);
        lcd.print("* FAIL ON *");
        lcd.setCursor(7, 1);
        lcd.print("* RTC *");
        digitalWrite(lederroPin, HIGH);   // turn the LED on (HIGH is the voltage level)
     
      while (1);
        }
      if (! rtc.isrunning()) {
        Serial.println("RTC is NOT running!");
        lcd.clear();
        lcd.setCursor(3, 0);
        lcd.print("* FAIL ON *");
        lcd.setCursor(7, 1);
        lcd.print("* RTC *");
        digitalWrite(lederroPin, HIGH);   // turn the LED on (HIGH is the voltage level)
       
        }
     
     // Ajuste data e hora - following line sets the RTC to the date & time this sketch was compiled
         //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
     // This line sets the RTC with an explicit date & time, for example to set
     // January 21, 2014 at 3am you would call:
        //rtc.adjust(DateTime(2020, 12, 30, 11, 41, 0));
}
       
//===================================================================    
void loop(void){
 
  //char caracter;
  DateTime now = rtc.now();

/*
  //DHT - humidity and temperature sensor
    DHT.read11(A1); // chama método de leitura da classe dht,pino A1
    //Retirando os decimais dos valores de DT11
      int umi = (DHT.humidity);  
      int tempe = (DHT.temperature);
 
  //Bluetooth
    serial1.print(graphTag);
    serial1.print(val1 / correcao); //Umidade 1
    serial1.print(valueSeparatorCharacter);
    serial1.print(val2 / correcao); //Umidade 2
    serial1.print(valueSeparatorCharacter);
    serial1.print(val3 / correcao); //Umidade 3
    serial1.print(valueSeparatorCharacter);
    serial1.print(val4 / correcao); //Umidade 4
    serial1.print(valueSeparatorCharacter);
    serial1.print(val5 / correcao); //Umidade 5
    serial1.print(valueSeparatorCharacter);
    serial1.print(val6 / correcao); //Umidade 6
    serial1.print(terminationSeparatorCharacter);
  */  
    val1 = analogRead(entradaA8); // faz a leitura da entrada A8
    val2 = analogRead(entradaA9); // faz a leitura da entrada A9
    val3 = analogRead(entradaA10); // faz a leitura da entrada A10
    val4 = analogRead(entradaA11); // faz a leitura da entrada A11
    val5 = analogRead(entradaA12); // faz a leitura da entrada A12
    val6 = analogRead(entradaA13); // faz a leitura da entrada A13
    val7 = analogRead(entradaA14); // faz a leitura da entrada A14
    val8 = analogRead(entradaA15); // faz a leitura da entrada A15

    val10 = analogRead(entradaA8); // faz a leitura da entrada A8
    val11 = analogRead(entradaA9); // faz a leitura da entrada A9
    val12 = analogRead(entradaA10); // faz a leitura da entrada A10
    val13 = analogRead(entradaA11); // faz a leitura da entrada A11
    val14 = analogRead(entradaA12); // faz a leitura da entrada A12
    val15 = analogRead(entradaA13); // faz a leitura da entrada A13
    val16 = analogRead(entradaA14); // faz a leitura da entrada A14
    val17 = analogRead(entradaA15); // faz a leitura da entrada A15
   
  //Condicionais
    //if (entradaA8 < 370) {
    //val1 = 800; }

     
  //Dados via serial
    ROW++; //Excel lines increment
    Serial.print("DATA,TIME,"); // inicia a impressão de dados, sempre iniciando
    Serial.print(val1 / correcao);
    Serial.print(",");
    Serial.print(val2 / correcao);
    Serial.print(",");
    Serial.print(val3 / correcao);
    Serial.print(",");
    Serial.print(val4 / correcao);
    Serial.print(",");
    Serial.print(val5 / correcao);
    Serial.print(",");
    Serial.print(val6 / correcao);
    Serial.print(",");
    Serial.print(val7 / correcao);
    Serial.print(",");
    Serial.print(val8 / correcao);
    Serial.print(",");
    Serial.print(robojax1.readCelsius()); // termopar 1
    Serial.print(",");
    Serial.print(robojax2.readCelsius()); // termopar 2
    Serial.print(",");
    Serial.print(robojax3.readCelsius()); // termopar 3
    Serial.print(",");
    Serial.print(robojax4.readCelsius()); // termopar 4
    Serial.print(",");
    Serial.println(ROW);
   
  //SD Card
   
    logfile.print(now.day(), DEC);
    logfile.print('/');
    logfile.print(now.month(), DEC);
    logfile.print('/');
    logfile.print(now.year(), DEC);
    //logfile.print(" (");
    //logfile.print(daysOfTheWeek[now.dayOfTheWeek()]);
    //logfile.print(") ");
    logfile.print(" , ");
    logfile.print(now.hour(), DEC);
    logfile.print(':');
    logfile.print(now.minute(), DEC);
    logfile.print(':');
    logfile.print(now.second(), DEC);
    logfile.print(" , ");
    //logfile.print(m/1000);           // milliseconds since start
    logfile.print(" , ");
    logfile.print(val1 / correcao);
    logfile.print(" , ");
    logfile.print(val2 / correcao);
    logfile.print(" , ");
    logfile.print(val3 / correcao);
    logfile.print(" , ");
    logfile.print(val4 / correcao);
    logfile.print(" , ");
    logfile.print(val5 / correcao);
    logfile.print(" , ");
    logfile.print(val6 / correcao);
    logfile.print(" , ");
    logfile.print(val7 / correcao);
    logfile.print(" , ");
    logfile.print(val8 / correcao);
    logfile.print(" , ");
    logfile.print(robojax1.readCelsius());
    logfile.print(" , ");
    logfile.print(robojax2.readCelsius());
    logfile.print(" , ");
    logfile.print(robojax3.readCelsius());
    logfile.print(" , ");
    logfile.print(robojax4.readCelsius());
    logfile.println(" , ");

    //Vai usar??    
  //Serial.print(umi);
  //Serial.print(tempe);
  //Serial.print(DHT.humidity);
  //Serial.print(" %");
  //Serial.print(DHT.temperature);
  //Serial.println(" °C");
 
  //Draft : Início dados RTC
    // Serial.print(m/1000);           // milliseconds since start
    // Serial.print(" , ");    
    // Serial.print(now.day(), DEC);
    // Serial.print('/');
    // Serial.print(now.month(), DEC);
    // Serial.print('/');
    // Serial.print(now.year(), DEC);
    // Serial.print(" (");
    // Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    // Serial.print(") ");
    // Serial.print(" , ");
    // Serial.print(now.hour(), DEC);
    // Serial.print(':');
    // Serial.print(now.minute(), DEC);
    // Serial.print(':');
    // Serial.print(now.second(), DEC);
    // Serial.print(" , ");
   
    // logfile.print(DHT.humidity);
    // logfile.print(" % ");
    // logfile.print(DHT.temperature);
    // logfile.print(" °C ");
   
       
   // if ((millis() - syncTime) < SYNC_INTERVAL) return; {
       // syncTime = millis();
       // }
    // blink LED to show we are syncing data to the card & updating FAT!
        delay(400);
         
         
         //LCD
    displaytime();
       
 logfile.flush();
   
}

//To speed up the recording of file on SD card

void displaytime(){
 
  DateTime now = rtc.now();  
  if((millis() - millisdisplaytime) < 800){
   
    //LCD page 1  
      lcd.clear();
      lcd.setCursor(1, 0);
      lcd.print(val10 / correcao);
      lcd.print(".0 ");
      lcd.print(val11 / correcao);
      lcd.print(".0 ");
      lcd.print(val12 / correcao);
      lcd.print(".0 ");
      lcd.print(val13 / correcao);
      lcd.print(".0 ");
     
      lcd.setCursor(1, 1);
      lcd.print(val14 / correcao);
      lcd.print(".0 ");
      lcd.print(val15 / correcao);
      lcd.print(".0 ");      
      lcd.print(val16 / correcao);
      lcd.print(".0 ");
      lcd.print(val17 / correcao);
      lcd.print(".0 ");
//adicionar saídas

      /*lcd.print(now.day(), DEC);
      lcd.print(now.hour(), DEC);
      lcd.print(':');
      lcd.print(now.minute(), DEC);
      lcd.print(':');
      lcd.print(now.second(), DEC);*/
     
     }
     else {
       
     //LCD page 2  
      lcd.clear();
      lcd.setCursor(0, 0);
            lcd.print(robojax1.readCelsius()); // termopar 1
      lcd.write(7); // Writes a character to the LCD
      lcd.print("C  ");
      lcd.print(robojax2.readCelsius()); // termopar 1
      lcd.write(7); // Writes a character to the LCD
      lcd.print("C ");
      lcd.setCursor(0, 1);
      lcd.print(robojax3.readCelsius()); // termopar 1
      lcd.write(7); // Writes a character to the LCD
      lcd.print("C  ");
      lcd.print(robojax4.readCelsius()); // termopar 1
      lcd.write(7); // Writes a character to the LCD
      lcd.print("C ");

  }
    if((millis() - millisdisplaytime) > 800){
    millisdisplaytime = millis();
    }
}
 

 

Comentários

Postagens mais visitadas