Skip to main content

Practice 11: Temperature Control Lab

✅ Práctica 11


En el siguiente blog se presenta la onceava práctica del laboratorio de control de temperatura y velocidad de un motor.

Github repository:

Objetivo general:

  • Realizar la adquisición de datos en Matlab emplenado comunicación serial

Materiales:

  • Matlab
  • TSC-Lab


Registro de datos en formato Byte:

Esta versión se recomienda si se utiliza Matlab de versiones anteriores a las 2017.
/*
****************************** TSC-Lab *******************************
***************************** PRACTICE 11 *****************************
This practice is about data acquisition with square velocity input
By: Kevin E. Chica O
Reviewed: vasanza
More information: https://tsc-lab.blogspot.com/
*/
//separador library
#include <Separador.h>
Separador s;
//initial setting for data acquisition
#include <OneWire.h>
#include <DallasTemperature.h>
//GPIO pin 0 is set as OneWire bus
OneWire ourWire1(0);
//GPIO pin 4 is set as OneWire bus
OneWire ourWire2(4);
//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);
//Status of transistors
int t1 = 0;
int t2 = 0;
//pins of transistor
int trans1 = 17;
int trans2 = 16;
//set parameters
int dutyCycle1 = 0;
int dutyCycle2 = 0;
int tempProm =0;
// Setting PWM properties
const int freq = 30000;
const int pwmChannel = 0;
const int resolution = 8;
void transistor( void *pvParameters );
void temperature( void *pvParameters );
void pwm( void *pvParameters );
void setup() {
Serial.begin(115200);
// sets the pins as outputs:
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(pwmChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(trans1, pwmChannel);
ledcAttachPin(trans2, pwmChannel);
xTaskCreatePinnedToCore(
transistor
, "trans" // Descriptive name of the function (MAX 8 characters)
, 2048 // Size required in STACK memory
, NULL // INITIAL parameter to receive (void *)
, 1 // Priority, priority = 3 (configMAX_PRIORITIES - 1) is the highest, priority = 0 is the lowest.
, NULL // Variable that points to the task (optional)
, 1); // core 1
xTaskCreatePinnedToCore(
temperature
, "temp" // Descriptive name of the function (MAX 8 characters)
, 2048 // Size required in STACK memory
, NULL // INITIAL parameter to receive (void *)
, 1 // Priority, priority = 3 (configMAX_PRIORITIES - 1) is the highest, priority = 0 is the lowest.
, NULL // Variable that points to the task (optional)
, 1); // core 0
xTaskCreatePinnedToCore(
pwm
, "PWM" // Descriptive name of the function (MAX 8 characters)
, 2048 // Size required in STACK memory
, NULL // INITIAL parameter to receive (void *)
, 1 // Priority, priority = 3 (configMAX_PRIORITIES - 1) is the highest, priority = 0 is the lowest.
, NULL // Variable that points to the task (optional)
, 1); // core 0
}
void loop() {
}
void transistor( void *pvParameters ) {
while (1) {
ledcWrite(pwmChannel, dutyCycle1);
ledcWrite(pwmChannel, dutyCycle2);
//vTaskDelay(period);
}
}
// Calcula las RPM quye tiene el motor
void temperature( void *pvParameters ) {
while (1) {
vTaskDelay(999);
//Serial.println(counter * 60);//255 -> 0x32 0x35 0x35
sensors1.requestTemperatures();
//Obtain the temperature in ºC of sensor 1
int temp1 = sensors1.getTempCByIndex(0);
//The command is sent to read the temperature
sensors2.requestTemperatures();
//Obtain the temperature in ºC of sensor 2
int temp2 = sensors2.getTempCByIndex(0);
//Serial.write((byte*)&temp1,4);//value temeprature 1
//t1_pwm
Serial.write(temp1);//value temperature 1
//t2_pwm
//Serial.write(temp2);//value temperature 2
//t1t2_pwm1_pwm2
//tempProm = (temp1 + temp2)/2;
//Serial.write(tempProm);//value temperature 2
}
}
// Read del PWM que viene desde Matlab
void pwm( void *pvParameters ) {
while (1) {
//Serial.println("hola");
//Serial.println("hola");
if (Serial.available())
{
dutyCycle1 =Serial.read();//Version 2017: t1_pwm
//dutyCycle2 =Serial.read();//Version 2017: t2_pwm
}
}
}

Repository:

https://github.com/vasanza/TSC-Lab/tree/main/Practice11/Practice11_Byte2017


Registro de datos en formato String:

Esta versión se recomienda si se utiliza Matlab de versiones actuales.
/*
****************************** TSC-Lab *******************************
***************************** PRACTICE 11 *****************************
This practice is about data acquisition with square velocity input
By: Kevin E. Chica O
Reviewed: vasanza
More information: https://tsc-lab.blogspot.com/
*/
//separador library
#include <Separador.h>
Separador s;
//initial setting for data acquisition
#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);
//Status of transistors
int t1 = 0;
int t2 = 0;
//pins of transistor
int trans1 = 17;
int trans2 = 16;
//set parameters
int dutyCycle1 = 0;
int dutyCycle2 = 0;
int band = 0;
// Setting PWM properties
const int freq = 30000;
const int pwmChannell = 0;
const int pwmChannel2 = 1;
const int resolution = 8;
void transistor( void *pvParameters );
void temperature( void *pvParameters );
void pwm( void *pvParameters );
void setup() {
Serial.begin(115200);
// sets the pins as outputs:
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);
xTaskCreatePinnedToCore(
transistor
, "trans" // Descriptive name of the function (MAX 8 characters)
, 2048 // Size required in STACK memory
, NULL // INITIAL parameter to receive (void *)
, 1 // Priority, priority = 3 (configMAX_PRIORITIES - 1) is the highest, priority = 0 is the lowest.
, NULL // Variable that points to the task (optional)
, 1); // core 1
xTaskCreatePinnedToCore(
temperature
, "temp" // Descriptive name of the function (MAX 8 characters)
, 2048 // Size required in STACK memory
, NULL // INITIAL parameter to receive (void *)
, 1 // Priority, priority = 3 (configMAX_PRIORITIES - 1) is the highest, priority = 0 is the lowest.
, NULL // Variable that points to the task (optional)
, 1); // core 0
xTaskCreatePinnedToCore(
pwm
, "PWM" // Descriptive name of the function (MAX 8 characters)
, 2048 // Size required in STACK memory
, NULL // INITIAL parameter to receive (void *)
, 1 // Priority, priority = 3 (configMAX_PRIORITIES - 1) is the highest, priority = 0 is the lowest.
, NULL // Variable that points to the task (optional)
, 1); // core 0
}
void loop() {
}
void transistor( void *pvParameters ) {
while (1) {
ledcWrite(pwmChannell, dutyCycle1);
ledcWrite(pwmChannel2, dutyCycle2);
//vTaskDelay(period);
}
}
// Calcula las RPM quye tiene el motor
void temperature( void *pvParameters ) {
while (1) {
vTaskDelay(999);
//Serial.println(counter * 60);//255 -> 0x32 0x35 0x35
sensors1.requestTemperatures();
//Obtain the temperature in ºC of sensor 1
int temp1 = sensors1.getTempCByIndex(0);
//The command is sent to read the temperature
sensors2.requestTemperatures();
//Obtain the temperature in ºC of sensor 2
int temp2 = sensors2.getTempCByIndex(0);
//Serial.write((byte*)&temp1,4);//value temeprature 1
//Serial.print("la banda es: ");//value temperature 1
//Serial.println(temp1);//value temperature 1
if (band == 0) {
//Serial.println("t1");
Serial.write(temp1);//value temperature 1
} else if (band == 1) {
//Serial.println("t2");
Serial.write(temp2);//value temperature 2
} else if (band == 2) {
int tempProm = (temp1 + temp2) / 2;
//Serial.println("t1t2");
Serial.write(tempProm);//value temperature 2
tempProm = 0;
}
}
}
// Read del PWM que viene desde Matlab
void pwm( void *pvParameters ) {
while (1) {
//Serial.println("hola");
if (Serial.available())
{
/*Cases:
t1_pwm
t2_pwm
t1t2_pwm1_pwm2
*/
String string = Serial.readStringUntil('\n');
String nameTrans = s.separa(string, '_', 0);
int dutyCycle = s.separa(string, '_', 1).toInt();
//dutyCycle = string.toInt();
if (nameTrans == "t1") {
band = 0;
dutyCycle1 = dutyCycle;
dutyCycle2 = 0;
} else if (nameTrans == "t2") {
band = 1;
dutyCycle2 = dutyCycle;
dutyCycle1 = 0;
} else if (nameTrans == "t1t2") {
band = 2;
dutyCycle1 = dutyCycle;
dutyCycle2 = s.separa(string, '_', 2).toInt();
}
}
}
}


                  

Comments

Popular posts from this blog

Practice 35: NodeRed (MQTT) + Telegram

✅ Práctica 35 Github Repositories ▷  #TSCLab #TCLab #ESP32 #Arduino #Control #MACI En el siguiente blog se presenta la vigésima sextapráctica del laboratorio de control de temperatura y velocidad de un motor. Objetivo general: Recibir los valores sensados de temperatura del TSC-Lab a Telegram.  Materiales: Node-Red TSC-Lab Introducción: En la práctica anterior se aprendió a información del TSC-Lab a Node-Red mediante Wi-Fi con protocolo HTTP. Ahora a mas de enviar dicha información se pretende recibirla y monitoreada desde Telegram, la cual es una aplicación enfocada en la mensajería instantánea, el envío de varios archivos y la comunicación en masa. Se la puede descargar desde la tienda de Google Play o App Store. También se la puede utilizar desde su sitio web o versión de escritorio. En esta práctica se crearrá un bot en Telegram el cual al recibir un comando en específico, enviará de manera instantanea el valor de temperatura solicitado. Procedimiento: Nota: se asume qu...

Práctica 7: Speed control using PWM

✅ Práctica 7 Github Repositories ▷  #TSCLab #TCLab #ESP32 #Arduino #Control #MACI En el siguiente blog se presenta la septima práctica y corresponde a la segunda del laboratorio de control de velocidad. Objetivo general: Entender el funcionamiento del motor DC con PWM para aumentar o bajar la velocidad usando código de programación en el IDE de Arduino. Objetivos específicos: Comparar los resultados de movimiento cambiando los parámetros. Materiales: PCB de Temperature Control Lab (TSC-Lab) Introducción: En la práctica anterior, al motor se le enviaba señales de High y Low para ponerlo en marcha. Sin embargo, dentro de la realidad a un motor no se lo controla así, en algunas ocasiones se lo requiere hacer girar con cierta velocidad y durante esta práctica para tener control sobre la misma se lo hace con señales PWM. Procedimiento: Se asume que la placa del ESP-32 ha sido previamente instalada en el IDE de Arduino. Copiar el código en el IDE de Arduino:      ...

Practice 26 : Over-The-Air programming (OTA)

✅ Práctica 26 Github Repositories ▷  #TSCLab #TCLab #ESP32 #Arduino #Control #MACI When using this resource, please cite the original publication: Víctor Asanza, Kevin Chica-Orellana, Jonathan Cagua, Douglas Plaza, César Martín, Diego Hernan Peluffo-Ordóñez. (2021). Temperature and Speed Control Lab (TSC-Lab). IEEE Dataport. https://dx.doi.org/10.21227/8cty-6069 En el siguiente blog se presenta la vigésima sexta práctica del laboratorio de control de temperatura y velocidad de un motor. Objetivo general: Actualizar el código del TSC-Lab utilizando OTA. Materiales: IOTAppStory TSC-Lab Introducción: A lo largo de todas las prácticas previamente realizadas, cada código se ha cargado al TSC-Lab con ayuda del cable USB por comunicación serial. Sin embargo, esta no es la única forma de hacerlo. Al igual que muchos otros dispositivos como celulares, carros inteligentes, decodificadores, entres otros se le pueden realizar ajustes y configuraciones de manera inalámbrica por una programaci...

Practice 29: NodeRed (Http) + Telegram

✅ Práctica 29 Github Repositories ▷  #TSCLab #TCLab #ESP32 #Arduino #Control #MACI En el siguiente blog se presenta la vigésima sextapráctica del laboratorio de control de temperatura y velocidad de un motor. Objetivo general: Recibir los valores sensados de temperatura del TSC-Lab a Telegram.  Materiales: Node-Red TSC-Lab Introducción: En la práctica anterior se aprendió a información del TSC-Lab a Node-Red mediante Wi-Fi con protocolo HTTP. Ahora a mas de enviar dicha información se pretende recibirla y monitoreada desde Telegram, la cual es una aplicación enfocada en la mensajería instantánea, el envío de varios archivos y la comunicación en masa. Se la puede descargar desde la tienda de Google Play o App Store. También se la puede utilizar desde su sitio web o versión de escritorio. En esta práctica se crearrá un bot en Telegram el cual al recibir un comando en específico, enviará de manera instantanea el valor de temperatura solicitado. Procedimiento: Nota: se asume qu...

Practice 12: Speed Control Lab

✅ Práctica 12 ▷  #TSCLab #TCLab #ESP32 #Arduino #Control #MACI When using this resource, please cite the original publication: Víctor Asanza, Kevin Chica-Orellana, Jonathan Cagua, Douglas Plaza, César Martín, Diego Hernan Peluffo-Ordóñez. (2021). Temperature and Speed Control Lab (TSC-Lab). IEEE Dataport. https://dx.doi.org/10.21227/8cty-6069 En el siguiente blog se presenta la vigésima segunda práctica del laboratorio de control de temperatura y velocidad de un motor. Github repository: https://github.com/vasanza/TSC-Lab Objetivo general: Realizar la adquisición de datos en Matlab emplenado comunicación serial. Materiales: Matlab TSC-Lab Registro de datos en formato Byte: Esta versión se recomienda si se utiliza Matlab de versiones anteriores a las 2017. Repository: https://github.com/vasanza/TSC-Lab/tree/main/Practice12/Practice12_Byte Registro de datos en formato String: Esta versión se recomienda si se utiliza Matlab de versiones actuales. Repository:  https://github.c...

▷ CHARLA #PUCESE Arduino Week: Hardware de Código Abierto TSC-LAB

  ⭐⭐⭐⭐⭐ CHARLA #PUCESE Arduino Week: Hardware de Código Abierto TSC-LAB ☑️ #TSCLab #TCLab #ESP32 #Arduino #Control #MACI ☑️ #ElectronicPrototypesDesign #PrototipadoElectronico #PCB #HardwareDesign #Hardware #AdeltaTechnologies #OpenHardware #OpenSourceHardware ➡️ Repository:  https://github.com/vasanza/TSC-Lab ➡️ When using this resource, please cite the original publication: Víctor Asanza, Kevin Chica-Orellana, Jonathan Cagua, Douglas Plaza, César Martín, Diego Hernan Peluffo-Ordóñez, April 25, 2021, "Temperature and Speed Control Lab (TSC-Lab)", IEEE Dataport, doi: https://dx.doi.org/10.21227/8cty-6069. ✅ #PUCESE, organizó el webinar: "ARDUINO WEEK 2022 PUCESE" ✅  Arduino Week PUCE Esmeraldas- Charla con Expertos ⭐⭐⭐⭐⭐ CHARLA #PUCESE Arduino Week: Hardware de Código Abierto TSC-LAB  from  Victor Asanza ✅ Video de la charla: ✅ Contenido: ➡️  1- Introducción ➡️  2- Hardware de Código Abierto ➡️  3- Temperature and Speed Control Lab (TSC-LAB)...

Practice 30: NodeRed (Http) + ThingSpeak

✅ Práctica 30 Github Repositories ▷  #TSCLab #TCLab #ESP32 #Arduino #Control #MACI When using this resource, please cite the original publication: Víctor Asanza, Kevin Chica-Orellana, Jonathan Cagua, Douglas Plaza, César Martín, Diego Hernan Peluffo-Ordóñez. (2021). Temperature and Speed Control Lab (TSC-Lab). IEEE Dataport. https://dx.doi.org/10.21227/8cty-6069 En el siguiente blog se presenta la vigésima séptima práctica del laboratorio de control de temperatura y velocidad de un motor. Objetivo general: Enviar los valores sensados de temperatura del TSC-Lab por WiFi a Node-Red y ThingSpeak.  Materiales: Node-Red Thingspeak TSC-Lab Introducción: En la práctica anterior se aprendió a utilizar y familiarizarse con Node-Red, el envío de información se lo hizo por medio de comunicación serial. Sin embargo, no tiene mucho sentido que se esté enviando información a Node-Red por el puerto serial cuando se puede aprovechar el ESP-32 para conectarse a internet por medio de Wi-Fi. S...

Practice 24: Firebase

✅ Práctica 24 Github Repositories ▷  #TSCLab #TCLab #ESP32 #Arduino #Control #MACI When using this resource, please cite the original publication: Víctor Asanza, Kevin Chica-Orellana, Jonathan Cagua, Douglas Plaza, César Martín, Diego Hernan Peluffo-Ordóñez. (2021). Temperature and Speed Control Lab (TSC-Lab). IEEE Dataport. https://dx.doi.org/10.21227/8cty-6069 En el siguiente blog se presenta la cuadragésima primera práctica del laboratorio de control de temperatura y velocidad de un motor. Objetivo general: Sensar datos y subirlos a la Realtime Database de Firebase Materiales: Firebase TSC-Lab Introducción: Firebase es una plataforma para el desarrollo de aplicaciones web y aplicaciones móviles lanzada en 2011 y adquirida por Google en 2014.​ Es una plataforma ubicada en la nube, integrada con Google Cloud Platform, que usa un conjunto de herramientas para la creación y sincronización de proyectos que serán dotados de alta calidad, haciendo posible el crecimiento del número de...

Practice 34: NodeRed (WiFi y MQTT)

✅ Práctica 34 Github Repositories ▷  #TSCLab #TCLab #ESP32 #Arduino #Control #MACI En el siguiente blog se presenta la vigésima quinta práctica del laboratorio de control de temperatura y velocidad de un motor. Objetivo general: Enviar los valores sensados de temperatura del TSC-Lab por WiFi a Node-Red por medio del protocoo MQTT y visualizarlos.  Materiales: Node-Red TSC-Lab Introducción: En la práctica anterior se aprendió a utilizar y familiarizarse con Node-Red, el envío de información se lo hizo por medio de comunicación serial. Sin embargo, no tiene mucho sentido que se esté enviando información a Node-Red por el puerto serial cuando se puede aprovechar el ESP-32 para conectarse a internet por medio de Wi-Fi. Se usará el protocolo MQTT para conectarse al servidor donde se aloja el servidor que se está ejecutando Node-Red, lo cual permitirá que cualquier dispositivo tenga acceso a su información. Procedimiento: Nota: se asume que está instalado Node-Red, que está famil...

Practice 33: MQTT

✅ Práctica 33 Github Repositories ▷  #TSCLab #TCLab #ESP32 #Arduino #Control #MACI En el siguiente blog se presenta la vigésima octava práctica del laboratorio de control de temperatura y velocidad de un motor. Objetivo general: Realizar una conexión MQTT utilizando el TSC-Lab.  Objetivos específicos: Enviar un mensaje al servidor y verificarlo en MQTTLens. Materiales: MQTTLens TSC-Lab Introducción: En las prácticas anteriores se realizararon conexiones a .diferentes plataformas donde se envió la información e inclusive se pudo visualizar los datos. Sin embargo, poseen muchas limitaciones como por ejemplo ThingSpeak que únicamente permite crear cuatro canales y el envío de información lo hace con un delay mínimo de 14 segundos, inclusive utilizar el protocolo HTTP ha generado conflictos. Ante ello, la mejor alternativa es trabajar con un servidor y enviar la data por medio de protocolo MQTT.  Procedimiento: Nota: revisar la práctica 1 donde se le recuerda a como insta...