0% found this document useful (0 votes)
4 views6 pages

Informe Practica Bluetooth

Uploaded by

mangane.dious23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Informe Practica Bluetooth

Uploaded by

mangane.dious23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

MÓDULO: INTEGRACIÓN DE SISTEMAS DE AUTOMATIZACIÓN INDUSTRIAL CURSO: 2024/2025

ACTIVIDAD: ISAI_AI4 COMUNICACIÓN BLUETOOTH (20%)


AUTOR/AUTORES: Ousmane Mangane
Nombre del profesor/es: Rubén Acerete Halli

TRABAJO A REALIZAR:

DESCRIPCIÓN DE LA FUNCIONALIDAD IMPLEMENTADA NO ESPECIFICADA EN EL


ENUNCIADO
No se estima oportuna hacer una descripción de la funcionalidad de la práctica, ya que se explica con creces
en el enunciado

Página 1 de 6
CÓDIGO IMPLEMENTADO

#include <BluetoothSerial.h>

BluetoothSerial bluetooth_osm;

#define RGB_LED_RED_DO 13
#define RGB_LED_GREEN_DO 5
#define RGB_LED_BLUE_DO 23

#define POTENCIOMETER_AI 34

#define PERIOD_SEND_BLUETOOTH_REQUEST 20
#define PERIOD_RGB_LED_RED_DO 2700
#define PERIOD_RGB_LED_BLUE_DO 200
#define PERIOD_POTENCIOMETER_PRINF_VALUE 1000
#define ANALOG_RESOLUTION 11

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)


#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

void send_bluetooth_request(uint32_t period_send_bluetooth_request);0¡0¡9


void blink_rgb_red_led(uint32_t period_rgb_red_led);
void blink_rgb_blue_led(uint32_t period_rgb_blue_led);
void potenciometre_printf_value(uint32_t period_potenciometre_printf_value);

void setup() {
Serial.begin(115200);
bluetooth_osm.begin("ESP32_osm"); //Bluetooth device name

analogReadResolution(ANALOG_RESOLUTION);

pinMode(RGB_LED_RED_DO, OUTPUT);
pinMode(RGB_LED_GREEN_DO, OUTPUT);
pinMode(RGB_LED_BLUE_DO, OUTPUT);

void loop() {

send_bluetooth_request(PERIOD_SEND_BLUETOOTH_REQUEST);

void send_bluetooth_request(uint32_t period_send_bluetooth_request){

Página 2 de 6
static uint32_t last_execution = 0;
uint32_t current_time = 0;
uint32_t time_diference = 0;

bool static blink_red_rgb_led_satus = false;


bool static blink_blue_rgb_led_satus = false;

current_time = millis();
time_diference = current_time - last_execution;

if(time_diference >= period_send_bluetooth_request){


last_execution = current_time;
char send_caracter_bt = 0;

if (bluetooth_osm.available()) {

send_caracter_bt = bluetooth_osm.read();

switch (send_caracter_bt){
case 'a':
digitalWrite(RGB_LED_GREEN_DO, HIGH);
break;

case 'b':
digitalWrite(RGB_LED_GREEN_DO, LOW);
break;

case 'c':
blink_red_rgb_led_satus = true;
break;

case 'd':
blink_red_rgb_led_satus = false;
digitalWrite(RGB_LED_RED_DO, LOW);
break;

case 'e':
blink_blue_rgb_led_satus = true;
break;

case 'f':
blink_blue_rgb_led_satus = false;
digitalWrite(RGB_LED_BLUE_DO, LOW);
break;
}

potenciometre_printf_value(PERIOD_POTENCIOMETER_PRINF_VALUE);

}
Página 3 de 6
if(true == blink_red_rgb_led_satus){

blink_rgb_red_led(PERIOD_RGB_LED_RED_DO);

if(true == blink_blue_rgb_led_satus){

blink_rgb_blue_led(RGB_LED_BLUE_DO);

void blink_rgb_red_led(uint32_t period_rgb_red_led){

static uint32_t last_execution = 0;


uint32_t current_time = 0;
uint32_t time_diference = 0;
static uint8_t led_status = 0;

current_time = millis();
time_diference = current_time - last_execution;
if(time_diference >= period_rgb_red_led){
last_execution = current_time;

led_status = !led_status;
digitalWrite(RGB_LED_RED_DO, led_status);
Serial.println("Led_rojo_encendido");

}
}

void blink_rgb_blue_led(uint32_t period_rgb_blue_led){

static uint32_t last_execution = 0;


uint32_t current_time = 0;
uint32_t time_diference = 0;
static uint8_t led_status = 0;

current_time = millis();
time_diference = current_time - last_execution;
if(time_diference >= period_rgb_blue_led){
last_execution = current_time;

led_status = !led_status;
digitalWrite(RGB_LED_BLUE_DO, led_status);

Página 4 de 6
Serial.println("Led_azul_encendido");

}
}

void potenciometre_printf_value(uint32_t period_potenciometre_printf_value){


const float MAXIMUM_VOLTAGE = 3.3f;
const float MAXIMUM_ADC_BITS = 1023.0f;
const float VOLTAGE_CONVERSION_FACTOR = (MAXIMUM_VOLTAGE / MAXIMUM_ADC_BITS);
float voltage_potentiometer = 0.0f;

uint32_t current_time = 0;
static uint32_t last_execution = 0;
uint32_t time_difference = 0;

int16_t potentiometer_adc = 0;

current_time = millis();
time_difference = uint32_t(current_time - last_execution);

if(time_difference >= period_potenciometre_printf_value){


last_execution = current_time;

potentiometer_adc = analogRead(POTENCIOMETER_AI);

voltage_potentiometer = float(potentiometer_adc) * VOLTAGE_CONVERSION_FACTOR;

bluetooth_osm.print(voltage_potentiometer);
bluetooth_osm.println("V");
}
}

Página 5 de 6
CONCLUSIÓN
En esta práctica se ha hecho uso de la librería BluetoothSerial.h para poder usar las funciones por de
bluetooth. Se ha hecho uso de la función bluetooth_osm.available() para popder comunicar vía bluetooth. Se
ha hecho de la función bluetooth_osm.begin("ESP32_osm") para darle nombre a la placa esp32. Se ha hecho
uso de la función bluetooth_osm.read() para leer el puerto bluetooth.

En esta práctica he aprendido a hacer la comunicación vía bluetooth. He aprendido ha usar las funciones para
la lectura y escritura de la comunicación vía bluetooth. He aprendido a comunicar una placa de Arduino con
un móvil vía bluetooth.

Página 6 de 6

You might also like