▷ Practice 4 #TSCLAB: Activation of transistor 2 and reading of temperature sensor 1 and 2

 ⭐⭐⭐⭐⭐ Practice 4 #TSCLAB:  Activation of transistor 2 and reading of temperature sensor 1 and 2

Objetivo general:

  • Guardar las mediciones obtenidas con ayuda de Cool Term y exportarlas en un archivo comma-separtaed-values (csv).

Objetivos específicos:

  • Guardar los datos de las lecturas realizadas con el heater 2 activado.

Materiales:

  • Programa Cool Term
  • PCB de Temperature Control Lab (TSC-Lab)


Introducción:

Para esta práctica, el sistema sigue sin tener retroalimentación, es decir, es en lazo abierto ya que simplemente se está midiendo el cambio de temperatura conforme los heaters estén activados o desactivados y esto dependerá con cual de los casos el estudiante desea trabajar.
  • Caso 1: ningun heater está activado
  • Caso 2: únicamente el heater 1 se activa y desactiva.
  • Caso 3: únicamente el heater 2 se activa y desactiva.
Para esta práctica se trabajará con el caso 3. Los mediciones son almacenadas en el ordenador gracias a Cool Term. 

Procedimiento:

Se asume que las librerías del sensor de temperatura y ESP están instaldas en el IDE de Arduino.
  1. Copiar el código en el IDE de Arduino:    

/*
****************************** TSC-Lab *******************************
***************************** PRACTICE 4 *****************************
This practice is about USB DATA ACQUISITION and have 4 different cases:
• Case 1: Ambient temperature reading using sensor 1 and 2
• Case 2: Activation of Transistor 1 and Reading of temperature sensor 1 and 2
• Case 3: Activation of Transistor 2 and Reading of temperature sensor 1 and 2
By: Kevin E. Chica O
More information: https://tsc-lab.blogspot.com/
*/
#include <OneWire.h>
#include <DallasTemperature.h>
//GPIO pin 4 is set as OneWire bus
OneWire ourWire1(4);
//GPIO pin 0 is set as OneWire bus
OneWire ourWire2(0);
//A variable or object is declared for our sensor 1
DallasTemperature sensors1(&ourWire1);
//A variable or object is declared for our sensor 2
DallasTemperature sensors2(&ourWire2);
//pins of transistor
int trans1 = 17;
int trans2 = 16;
//set parameters
int period = 15; //medium period in minutes
int freq_sampling = 100; // sampling time
int ciclos = 20; // sampling time
int dutyCycle1 = 0;
int dutyCycle2 = 0;
// Setting PWM properties
const int freq = 30000;
const int pwmChannell = 0;
const int pwmChannel2 = 1;
const int resolution = 8;
void setup() {
delay(1000);
Serial.begin(115200);
sensors1.begin(); //Sensor 1 starts
sensors2.begin(); //Sensor 2 starts
//transistor 1
pinMode(trans1, OUTPUT);
//transitor 2
pinMode(trans2, OUTPUT);
// configure LED PWM functionalitites
ledcSetup(pwmChannell, freq, resolution);
ledcSetup(pwmChannel2, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(trans1, pwmChannell);
ledcAttachPin(trans2, pwmChannel2);
Serial.println("Choose any case: ");
}
void loop() {
if (Serial.available())
{
String string = Serial.readStringUntil('\n');
if (string == "case_1") {
Serial.println("Case 1 started");
for (int i = 1; i <= ciclos; i++) {
//transistor 1 deactivate
dutyCycle1 = 0;
ledcWrite(pwmChannell, dutyCycle1);
//transistor 2 deactivate
dutyCycle2 = 0;
ledcWrite(pwmChannel2, dutyCycle2);
readData();
readData();
}
Serial.println("Case 1 finished");
Serial.println("Choose any case: ");
}
else if (string == "case_2") {
Serial.println("Case 2 started");
for (int i = 1; i <= ciclos; i++) {
//transistor 1 activate
dutyCycle1 = 255;
ledcWrite(pwmChannell, dutyCycle1);
readData();
//transistor 1 deactivate
dutyCycle1 = 0;
ledcWrite(pwmChannel2, dutyCycle2);
readData();
}
Serial.println("Case 2 finished");
Serial.println("Choose any case: ");
}
else if (string == "case_3") {
Serial.println("Case 3 started");
for (int i = 1; i <= ciclos; i++) {
//transistor 2 activate
dutyCycle2 = 255;
ledcWrite(pwmChannel2, dutyCycle2);
readData();
//transistor 2 deactivate
dutyCycle2 = 0;
ledcWrite(pwmChannel2, 0);
readData();
}
Serial.println("Case 3 finished");
Serial.println("Choose any case: ");
}
}
}
//method to read data for 12 minute
void readData() {
uint32_t timer = period * 60000L;
for ( uint32_t tStart = millis(); (millis() - tStart) < timer; ) {
//The command is sent to read the temperature
sensors1.requestTemperatures();
//Obtain the temperature in ºC of sensor 1
float temp1 = sensors1.getTempCByIndex(0);
//The command is sent to read the temperature
sensors2.requestTemperatures();
//Obtain the temperature in ºC of sensor 2
float temp2 = sensors2.getTempCByIndex(0);
//print to display the temperature change
Serial.print(temp1);
Serial.print(",");
Serial.print(temp2);
Serial.print(",");
Serial.print(dutyCycle1);
Serial.print(",");
Serial.println(dutyCycle2);
delay(freq_sampling);
}
}
    
  1. Cargar el código a la placa.
  2. Abrir Cool Term, iniciar la conexión y guardar los datos.

Nota: los comandos de activación y desactivación de los heaters dependerá de cada caso pero deben ser enviados por el "Monitor Serie" de Cool Term y son los siquientes:
  • Para iniciar el caso 1 se debe enviar el comando: case_1
  • Para iniciar el caso 2 se debe enviar el comando: case_2
  • Para iniciar el caso 3 se debe enviar el comando: case_3
En esta práctica se ingresará el comando case_3. 
Si al momento que se exportaron los resultados a .txt contiene cadenas de texto como por ejemplo "Choose any case" o cualquier otro, se recomienda borrarlos antes de exportarlos a .csv.

Resultados:

Los archivos .csv generados de esta práctica se los puede apreciar aquí. 

Read related topics

Comentarios

Popular Posts

▷ Especificaciones del módulo ESP32

▷ #ESP32 - REAL-TIME CLOCK #RTC INTERNO

▷ #ESP32 - SINCRONIZAR RTC INTERNO CON SERVIDOR NTP

▷ #ESP32 - Display OLED 128x64

▷ #ESP32 - Over-The-Air programming #OTA

▷ #ESP32 - #MQTT (Introducción)

▷ PROTEUS PCB DESIGN

▷ DISEÑO DE SISTEMAS DIGITALES, PROYECTOS PROPUESTOS (2019 2do Término)

▷ SISTEMAS EMBEBIDOS, PROYECTOS PROPUESTOS (2021 PAO1)

▷ #ESP32 - INSTALAR LIBRERIAS DESDE GESTOR LIBRERIAS ARDUINO