▷ Practice 2 #TSCLAB: Ambient temperature reading using sensor 1 and 2

⭐⭐⭐⭐⭐ Practice 2 #TSCLAB: Ambient temperature reading using 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 a temperatura ambiente.

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 en esta práctica se tiene un único caso:
  • Caso 1: ningun heater está activado

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 2 *****************************
This practice is about USB DATA ACQUISITION and have 4 different cases:
• Case 1: Ambient temperature reading using 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: ");
}
}
}
//method to read data for 15 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.print(dutyCycle2);
Serial.println("\n");
delay(freq_sampling);
}
}
    
  1. Cargar el código a la placa.
  2. Abrir Cool Term, iniciar la conexión y guardar los datos.

Nota: el comando 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 en esta ocasión como se tiene un solo caso y es el sigueinte:
  • Para iniciar el caso 1 se debe enviar el comando: case_1


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í. 

Comentarios

Popular Posts

▷ Especificaciones del módulo ESP32

▷ #ESP32 - REAL-TIME CLOCK #RTC INTERNO

▷ #ESP32 - SINCRONIZAR RTC INTERNO CON SERVIDOR NTP

▷ Instalación de ALTIUM CircuitMaker y especificaciones del módulo ESP32

▷ Display of last 24 hours of Temperature, Humidity and Temp. CPU

▷ IoT-Based Shrimp Pool Optimization with LoRa Technology

▷ Wireless Sensor Network (WSN)

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

▷ Device Free Indoor Localization in the 28 GHz band based on machine learning

▷ SOLUCIÓN EVALUACIÓN SISTEMAS DIGITALES 1, 1er Parcial (2021 PAE)