Projeto Enxugamento RAM RHO - Ago/25
/* Projeto Segundo Front End para Enxugamento
Enxugamento_v27_1_FrontEnd2_RAM_RHO
* Wilson Bueno - 04/08/2025
* Arduino IDE 2.3.5
* Baseado na V 24.4 - Draft - without bluetooth and umidity sensor / Colocando temporizador no display
* V24.5 - verificando funcional para IDE 2.3.5 - problema no RTC - por causa da pilha?? / * V25.0 - habilitando as saídas de enxugamento
* V25.1 - progressivo ok parcial / * V25.2 - Maya / * V25.3 - sugestões Maya - Ok
* V26.0 - Incluindo sensor de umidade e temperatura - Ok * V26.1 - progressivo - OK
* V27.0 - Inclusão canais para medição das baterias da RAM 1500 RHO - Ok
* V27.1 - progressivo
*/
#include "RTClib.h" // RTC library
#include "max6675.h" // shield max6675 library
#include <SPI.h> // library serial comunication
#include <SD.h> // library SD card
#include <LiquidCrystal.h> // library LCD
#include <Adafruit_AHT10.h> // biblioteca sensor umidade e temperatura
Adafruit_AHT10 aht; //AHT10 card umidity and temperature
const int lederroPin = 37;
const int pinselecao = 8; //seleção tela automática / temperaturas
int pinstatus = 0; //status pino de seleção
//Portas analógicas do voltimetro
int CH1 = A0;
int CH2 = A1;
//Variaveis que armazenam o valor de tensão de cada canal.
float VCH1;
float VCH2;
//Com auxilio de um multimetro, verifique a tensão fornecida na linha de 5V pela sua placa ARDUINO e digite no lugar do valor atual.
#define VREF1 20.50
#define VREF2 20.30
//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"};
//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; // voltage adjust values
int eA8 = A8;
int eA9 = A9;
int eA10 = A10;
int eA11 = A11;
//Saídas Analógicas para o Spider
int sA12 = A12;
int sA13 = A13;
int sA14 = A14;
int sA15 = A15;
//Serial date for PLX-DAQ Excel files
int ROW = 0;
int LABEL = 1;
//loop do STARTING no LCD
int x = 1;
int w = 1;
//============================================================================
void setup() {
pinMode(pinselecao, INPUT);
//Initialize AHT10 card umidity and temperature
if (!aht.begin()) {
Serial.println(F("Could not find AHT10? Check wiring"));
while (1) delay(10);
}
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp); // Populate temp and humidity objects with fresh data
Serial.println(F("Sensor ATH: Ok"));
lcd.begin(16, 2); //Set up the LCD's number of columns and rows:
pinMode(lederroPin, OUTPUT); //Alimentação Led de erro
Serial.begin(9600); //serial startup
Serial.println(F("============================="));
Serial.println(F("Marelli - Testing Engineering"));
Serial.println(F("============================="));
Serial.println(F("V27.1 IDE2.3.5 - 04/08/25"));
Serial.println(F("============================="));
Serial.print(temp.temperature);
Serial.print(F(" °C"));
Serial.print(F(" <> "));
Serial.print(humidity.relative_humidity);
Serial.println(F(" %HR"));
//SD card
Serial.print(F("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(F("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(F("* FAIL ON *"));
lcd.setCursor(3, 1);
lcd.print(F("* SD CARD *"));
while (1)
;
}
Serial.println(F("Card Initialized"));
delay(500);
//char caracter;
//DateTime now = rtc.now();
//Create a new file sequencial on SD card
char filename[] = "LOGGE000.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
lcd.clear();
lcd.setCursor(3, 0);
lcd.print(F("R&D MARELLI"));
lcd.setCursor(0, 1);
lcd.print(F("V27.1 IDE2.3.5-08/25"));
delay(2000);
lcd.setCursor(0, 1);
lcd.print(humidity.relative_humidity, 0);
lcd.print(F("%HR <> "));
lcd.print(temp.temperature, 1);
lcd.print(F("\xDF"));
lcd.print(F("C "));
//lcd.print(F("oC"));
delay(4000);
while (x <= 17) {
lcd.clear();
lcd.setCursor(3, 0);
lcd.print(F("R&D MARELLI"));
lcd.setCursor(x, 1);
lcd.print(filename);
delay(500);
x++;
}
x = 0;
break; // leave the loop!
}
}
if (!logfile) {
error("couldnt create file");
Serial.println(F("Fail to create file"));
lcd.clear();
lcd.setCursor(3, 0);
lcd.print(F("* FAIL ON *"));
lcd.setCursor(3, 1);
lcd.print(F("* SD CARD *"));
digitalWrite(lederroPin, HIGH); // turn the LED on (HIGH is the voltage level)
}
Serial.print(F("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)
}
// Date and time adjusts - 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. Example: January 21, 2014 at 3am you would call:
//rtc.adjust(DateTime(2020, 12, 30, 11, 41, 0));
Serial.println(F("CLEARDATA")); // reset da comunicação serial
Serial.println(F("LABEL,Time,PT1,PT2,PT3,PT4,T1,T2,T3,T4,ROW")); // nomeia as colunas
delay(50);
}
//===================================================================
void loop(void) {
pinstatus = digitalRead(pinselecao);
DateTime now = rtc.now();
// read the analog in value:
eA8 = analogRead(A8);
eA9 = analogRead(A9);
eA10 = analogRead(A10);
eA11 = analogRead(A11);
// map it to the range of the analog out:
//sA12 = map(eA8, 0, 100, 0, 100);
sA12 = eA8 * 11.77;
sA13 = eA9 * 11.77;
sA14 = eA10 * 11.77;
sA15 = eA11 * 11.77;
// change the analog out value:
analogWrite(A12, sA12);
analogWrite(A13, sA13);
analogWrite(A14, sA14);
analogWrite(A15, sA15);
//Dados entradas via serial
ROW++; //Excel lines increment
Serial.print(F("DATA,TIME,")); // inicia a impressão de dados, sempre iniciando
Serial.print(eA8 / correcao);
Serial.print(F(","));
Serial.print(eA9 / correcao);
Serial.print(F(","));
Serial.print(eA10 / correcao);
Serial.print(F(","));
Serial.print(eA11 / correcao);
Serial.print(F(","));
Serial.print(robojax1.readCelsius()); // thermocouple 1
Serial.print(F(","));
Serial.print(robojax2.readCelsius()); // thermocouple 2
Serial.print(F(","));
Serial.print(robojax3.readCelsius()); // thermocouple 3
Serial.print(F(","));
Serial.print(robojax4.readCelsius()); // thermocouple 4
Serial.print(F(","));
Serial.println(ROW);
/*
//Dados saídas via serial
Serial.print(sA12);
Serial.print(F(","));
Serial.print(sA13);
Serial.print(F(","));
Serial.print(sA14);
Serial.print(F(","));
Serial.print(sA15);
Serial.print(F(","));
*/
//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(eA8 / correcao);
logfile.print(" , ");
logfile.print(eA9 / correcao);
logfile.print(" , ");
logfile.print(eA10 / correcao);
logfile.print(" , ");
logfile.print(eA11 / 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(F(" , "));
logfile.print("Tensão Bateria 1: ");
logfile.print(VCH1);
logfile.print("Tensão Bateria 2: ");
logfile.println(VCH2);
// blink LED to show we are syncing data to the card & updating FAT!
delay(400);
//LCD
displaytime();
logfile.flush(); //garantir a gravação no cartão
}
//To speed up the recording of file on SD card
void displaytime() {
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (pinstatus == HIGH) {
lcd.clear();
lcd.setCursor(0, 0);
/*
lcd.print(robojax1.readCelsius()); // termopar 1
lcd.print("\xDF"); //opção à montagem do caracter °
//lcd.write(7); // Writes a character to the LCD
lcd.print("C ");
lcd.print(robojax2.readCelsius()); // termopar 1
lcd.print("\xDF"); //opção à montagem do caracter °
//lcd.write(7); // Writes a character to the LCD
lcd.print("C ");
lcd.setCursor(0, 1);
lcd.print(robojax3.readCelsius()); // termopar 1
lcd.print("\xDF"); //opção à montagem do caracter °
//lcd.write(7); // Writes a character to the LCD
lcd.print("C ");
lcd.print(robojax4.readCelsius()); // termopar 1
lcd.print("\xDF"); //opção à montagem do caracter °
//lcd.write(7); // Writes a character to the LCD
lcd.print("C ");
*/
//Função que chama a leitura analogica do ADC. Uma chamada por canal.
VCH1 = analogRead(CH1);
VCH2 = analogRead(CH2);
//Converte o valor ligo pela função analog Read(0 até 1023) em um valor de tensão.
VCH1 = (VCH1 * (VREF1 / 1023));
VCH2 = (VCH2 * (VREF2 / 1023));
//Escreve no display as tensões medidas por cada canal do voltimetro.
lcd.setCursor(0, 0);
lcd.print("Tensao Bat1:");
lcd.setCursor(12, 0);
lcd.print(VCH1, 1);
lcd.setCursor(0, 1);
lcd.print("Tensao Bat2:");
lcd.setCursor(12, 1);
lcd.print(VCH2, 1);
Serial.print("Tensão Bateria 1: ");
Serial.print(VCH1);
Serial.print("Tensão Bateria 2: ");
Serial.println(VCH2);
//digitalWrite(37, HIGH);
} else {
//digitalWrite(37, LOW);
//DateTime now = rtc.now();
if ((millis() - millisdisplaytime) < 800) {
//LCD page 1
lcd.clear();
lcd.setCursor(1, 0);
lcd.print(F("PT1 PT2 PT3 PT4"));
lcd.setCursor(1, 1);
lcd.print(eA8 / correcao);
lcd.print(F(".0 "));
lcd.print(eA9 / correcao);
lcd.print(F(".0 "));
lcd.print(eA10 / correcao);
lcd.print(F(".0 "));
lcd.print(eA11 / correcao);
lcd.print(F(".0 "));
} else {
//LCD page 2
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(robojax1.readCelsius()); // termopar 1
lcd.print("\xDF"); //opção à montagem do caracter °
//lcd.write(7); // Writes a character to the LCD
lcd.print("C ");
lcd.print(robojax2.readCelsius()); // termopar 1
lcd.print("\xDF"); //opção à montagem do caracter °
//lcd.write(7); // Writes a character to the LCD
lcd.print("C ");
lcd.setCursor(0, 1);
lcd.print(robojax3.readCelsius()); // termopar 1
lcd.print("\xDF"); //opção à montagem do caracter °
//lcd.write(7); // Writes a character to the LCD
lcd.print("C ");
lcd.print(robojax4.readCelsius()); // termopar 1
lcd.print("\xDF"); //opção à montagem do caracter °
//lcd.write(7); // Writes a character to the LCD
lcd.print("C ");
}
if ((millis() - millisdisplaytime) > 800) {
millisdisplaytime = millis();
}
}
}
Comentários
Postar um comentário