Buenas tardes amigos, espero su ayuda, estoy trabajando con un control de temperatura a un controlador de corriente de un carro electrico, la cuestion es que logro visualizar la temperatura pero esta no se actualiza constantemente mostrandome las variaciones, requiero reinstalar el codigo para que ahiga cambio en la lectura. Les envio el codigo en cuestion gracias por su ayuda.
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
// DS18B20 Config Section
#include <OneWire.h>
#include <DallasTemperature.h>
int Fan_Controlador = 5;
float Temp_Controlador;
bool Fan_Controlador_activado = false;
int Temp_Controlador_limite = 29;
char temp_string1[5]; //matriz de caracteres vacía para contener el flotador temporal convertido.
char temp_string2[5]; //matriz de caracteres vacía para contener el flotador temporal convertido.
#include <TouchScreen.h>
#include <Fonts/FreeSans9pt7b.h> // when you want other fonts
#include <Fonts/FreeSans12pt7b.h> // when you want other fonts
#include <FreeDefaultFonts.h> // when you want other fonts
#include <Fonts/FreeSerif12pt7b.h>
#define MINPRESSURE 10
#define MAXPRESSURE 1000
#define TS_MINX 130
#define TS_MAXX 905
#define TS_MINY 75
#define TS_MAXY 930
// We have a status line for like, is FONA working
#define STATUS_X 10
#define STATUS_Y 65
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A3 // must be an analog pin, use "An" notation!
#define YM 8 // can be a digital pin
#define XP 9 // can be a digital pin
// run TouchScreen_Calibr_native.ino in MCUFRIEND_kbv examples to calibrate screen
// copy calibration data from serial monitor for XP, XM, YP, YM, TS_LEFT, TS_RT, TS_TOP, TS_BOT
//const int XP = 7, XM = A1, YP = A2, YM = 6; //320x480 ID=0x0099
const int TS_LEFT = 903, TS_RT = 163, TS_TOP = 947, TS_BOT = 165;
// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// thermometer graphic coordinates and size
#define thermXTop 155 // thermometer tube top center x coordinate
#define thermYTop 130 // thermometer tube top center y coordinate
#define thermHeight 200 // thermometer tube height
#define thermTubeWidth 30 // thermometer tube width
#define thermBulbRadius 30 // thermometer bulb radius
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// Color definitions
#define ILI9341_BLACK 0x0000 /* 0, 0, 0 */
#define ILI9341_NAVY 0x000F /* 0, 0, 128 */
#define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */
#define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */
#define ILI9341_MAROON 0x7800 /* 128, 0, 0 */
#define ILI9341_PURPLE 0x780F /* 128, 0, 128 */
#define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */
#define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */
#define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */
#define ILI9341_BLUE 0x001F /* 0, 0, 255 */
#define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */
#define ILI9341_CYAN 0x07FF /* 0, 255, 255 */
#define ILI9341_RED 0xF800 /* 255, 0, 0 */
#define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */
#define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */
#define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */
#define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */
#define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
#define ILI9341_PINK 0xF81F
/******************* UI details */
#define BUTTON_X 52
#define BUTTON_Y 150
#define BUTTON_W 80
#define BUTTON_H 45
#define BUTTON_SPACING_X 26
#define BUTTON_SPACING_Y 30
#define BUTTON_TEXTSIZE 3
// text box where numbers go
#define TEXT_X 10
#define TEXT_Y 10
#define TEXT_W 300
#define TEXT_H 50
#define TEXT_TSIZE 2
#define TEXT_TCOLOR ILI9341_MAGENTA
// the data (phone #) we store in the textfield
#define TEXT_LEN 16
char textfield[TEXT_LEN + 1] = "";
uint8_t textfield_i = 0;
Adafruit_GFX_Button buttons[15];
/* create 15 buttons, in classic candybar phone style */
char buttonlabels[15][5] = { "Run", "Mate", "Stop", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#" };
uint16_t buttoncolors[15] = { ILI9341_DARKGREEN, ILI9341_DARKGREY, ILI9341_RED, ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE, ILI9341_ORANGE, ILI9341_BLUE, ILI9341_ORANGE };
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;
int entrada;
int aaa;
int bbb;
int Barra1En;
String MissatgeVellP2;
// DS18B20 Seccion ================================================================
// sonda de datos de un cable al pin 2
#define ONE_WIRE_BUS_PIN 53
// Configure una instancia de oneWire para comunicarse con cualquier dispositivo OneWire
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);
DeviceAddress Probe_01 = { 0x28, 0x16, 0x9E, 0x49, 0xF6, 0x8F, 0x3C, 0xE7 };
DeviceAddress Probe_02 = { 0x28, 0x9D, 0x39, 0x67, 0x62, 0x21, 0x06, 0xB6 };
// Cada DS18B20 tiene una de sus direcciones únicas; use el boceto del buscador de direcciones
void setup(void) {
Serial.begin(9600);
Serial.println(F("TFT LCD test"));
// initialize the DS18B20 temp sensor
sensors.begin(); // INICIO sensor de temperatura de dallas
sensors.setResolution(Probe_01, 10); // establezca la resolución del sensor DS18B20 en 10 bits
sensors.setResolution(Probe_02, 10); // establezca la resolución del sensor DS18B20 en 10 bits
Serial.println("Iniciando Sistema Control de Temperatura");
pinMode(Fan_Controlador, OUTPUT);
//digitalWrite (Fan_Controlador, HIGH);
Serial.print("Number of Devices found on bus = ");
Serial.println(sensors.getDeviceCount());
Serial.println("============================================");
Serial.println();
tft.reset();
uint16_t identifier = tft.readID();
if (identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"));
} else if (identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"));
} else if (identifier == 0x4535) {
Serial.println(F("Found LGDP4535 LCD driver"));
} else if (identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"));
} else if (identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if (identifier == 0x7783) {
Serial.println(F("Found ST7781 LCD driver"));
} else if (identifier == 0x8230) {
Serial.println(F("Found UC8230 LCD driver"));
} else if (identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else if (identifier == 0x0101) {
identifier = 0x9341;
Serial.println(F("Found 0x9341 LCD driver"));
} else if (identifier == 0x9481) {
Serial.println(F("Found 0x9481 LCD driver"));
} else if (identifier == 0x9486) {
Serial.println(F("Found 0x9486 LCD driver"));
} else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT"));
Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
Serial.println(F("If using the breakout board, it should NOT be #defined!"));
Serial.println(F("Also if using the breakout, double-check that all wiring"));
Serial.println(F("matches the tutorial."));
identifier = 0x9486;
}
tft.begin(identifier);
Serial.print("TFT size is ");
Serial.print(tft.width());
Serial.print("x");
Serial.println(tft.height());
}
void loop(void) {
Ppresentacion();
}
void Ppresentacion() {
// color de fondo de la pantalla
tft.fillScreen(BLACK);
// Color relleno rectangulo superior:
tft.fillRect(1, 1, 319, 48, RED);
//Color contorno rectangulo superior:
tft.drawRect(0, 0, 320, 50, YELLOW);
// Color relleno rectangulo inferior:
tft.fillRect(1, 430, 319, 48, RED);
//Color contorno rectangulo inferior:
tft.drawRect(0, 429, 320, 50, YELLOW);
// Pantalla de bienvenida
tft.setCursor(50, 15);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.println("JOURNEY 2013");
delay(500);
tft.setCursor(50, 15);
tft.setTextColor(BLUE);
tft.setTextSize(3);
tft.println("JOURNEY 2013");
delay(500);
tft.setCursor(50, 15);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.println("JOURNEY 2013");
delay(500);
tft.setCursor(50, 15);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println("JOURNEY 2013");
delay(500);
//Texto de DODGE:
//showmsgAXY(30, 260, 3, &FreeSans12pt7b, "DODGE");
tft.setCursor(35, 450);
tft.setTextColor(YELLOW);
tft.setTextSize(2);
tft.println("Por Abel Cienfuegos V.");
delay(500);
tft.setCursor(35, 450);
tft.setTextColor(BLUE);
tft.setTextSize(2);
tft.println("Por Abel Cienfuegos V.");
delay(500);
tft.setCursor(35, 450);
tft.setTextColor(RED);
tft.setTextSize(2);
tft.println("Por Abel Cienfuegos V.");
delay(500);
tft.setCursor(35, 450);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.println("Por Abel Cienfuegos V.");
delay(500);
delay(2000);
Pprincipal();
}
void Pprincipal() {
// prepara el color del fons de la pantalla
tft.fillScreen(BLACK);
// Seccion Control de Temperatura con el Fan=====================================================
sensors.requestTemperatures();
Temp_Controlador = sensors.getTempCByIndex(1);
//Serial.println("La temperatura es: "+ String(Temp_Controlador) );
if (Temp_Controlador > Temp_Controlador_limite) {
digitalWrite(Fan_Controlador, LOW);
Fan_Controlador_activado = false;
Serial.println("Ventilador Activado → " + String(Temp_Controlador));
} else {
digitalWrite(Fan_Controlador, HIGH);
Fan_Controlador_activado = true;
Serial.println("Ventilador Desactivado → " + String(Temp_Controlador));
}
// Seccion DS18B20 Sensor Temperatura Ambiente=====================================================
sensors.requestTemperatures();
Serial.print("temperature Ambiente: ");
float tempC1 = sensors.getTempC(Probe_01);
Serial.print(tempC1, 1);
Serial.println(" *C\t");
if (tempC1 == -127.00) {
Serial.print("Error getting temperature ");
} else {
// Seccion DS18B20 Sensor Temperatura del Controlador======================================================
Serial.print("temperature Controlador: ");
float tempC2 = sensors.getTempC(Probe_02);
Serial.print(tempC2, 1);
Serial.println(" *C\t");
if (tempC2 == -127.00) {
Serial.print("Error getting temperature ");
}
// convert floats into char u8g strings
tft.setCursor(30, 15);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
tft.println("TA: ");
//u8g.drawStr( 75, 51, "TA"); // Codigo para la temperatura abiente
tft.setTextColor(YELLOW, BLACK);
tft.setCursor(80, 15);
dtostrf(tempC1, 3, 1, temp_string1);
tft.println(temp_string1);
// tft.setCursor(90, 15);
// tft.setTextSize(2); // show temperature with 1 decimal place
// tft.print((char)247); // degree symbol
//u8g.drawStr(121,51, "C");
tft.setCursor(160, 15);
tft.setTextSize(3);
tft.println("C");
//u8g.drawStr(75, 61, "TC"); // Codigo para la temperatura del controlador
//dtostrf(tempC2, 3, 1, temp_string2);
//u8g.drawStr(92,61, temp_string2);
//u8g.drawStr(121,61, "C");
}
delay(900000000);
}