From 117e066867be5ca01ef2f04b7b1771a5e499917a Mon Sep 17 00:00:00 2001 From: "jp.av.dev" Date: Sun, 3 Apr 2022 17:12:44 -0400 Subject: [PATCH] retoques README --- BlueTooth/README.md | 110 +++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 58 deletions(-) diff --git a/BlueTooth/README.md b/BlueTooth/README.md index 19d7e1c..11e1b78 100644 --- a/BlueTooth/README.md +++ b/BlueTooth/README.md @@ -33,34 +33,30 @@ void loop() { ``` ---- -``` +### Programar el modulo bluetooth HC-06 +con un nuevo: +- **NOMBRE** (Nombre de 20 caracteres) +- **PIN** (Clave de cuatro numeros) +- **BPS** (Velocidad de conexion en baudios) + +Conexiones: +|ARDUINO | BLUETOOTH| +|-|-| +|**` 5V `** | **` VCC `** | +|**` GND `** | **` GND `** | +|**` PIN 2 `** | **` TX `** | +|**` PIN 3 `** | **` RX `** | + +```c #include -/* Programa el modulo bluetooth HC-06 con un nuevo: - NOMBRE (Nombre de 20 caracteres) - PIN (Clave de cuatro numeros) - BPS (Velocidad de conexion en baudios) - - Tienda donde se compro el modulo: http://dinastiatecnologica.com/producto/modulo-bluetooth-hc-05/ - By: http://elprofegarcia.com - - CONEXIONES: - ARDUINO BLUETOOTH - 5V VCC - GND GND - PIN 2 TX - PIN 3 RX - - */ - SoftwareSerial blue(2, 3); //Crea conexion al bluetooth - PIN 2 a TX y PIN 3 a RX char NOMBRE[21] = "FznBTSlave"; // Nombre de 20 caracteres maximo char BPS = '4'; // 1=1200 , 2=2400, 3=4800, 4=9600, 5=19200, 6=38400, 7=57600, 8=115200 char PASS[5] = "4321"; // PIN O CLAVE de 4 caracteres numericos -void setup() -{ +void setup(){ blue.begin(9600); // inicialmente la comunicacion serial a 9600 Baudios (velocidad de fabrica) pinMode(13,OUTPUT); digitalWrite(13,HIGH); // Enciende el LED 13 durante 4s antes de configurar el Bluetooth @@ -84,51 +80,49 @@ void setup() delay(1000); } -void loop() -{ - digitalWrite(13, !digitalRead(13)); // cuando termina de configurar el Bluetooth queda el LED 13 parpadeando +void loop(){ + digitalWrite(13, !digitalRead(13)); // luego de configurar el Bluetooth el LED 13 queda parpadeando delay(100); } ``` ---- -``` +```c #include -SoftwareSerial BT1(4,2); // RX, TX recorder que se cruzan +SoftwareSerial BT1(4,2); // RX, TX recordar que se cruzan -void setup() - { - Serial.begin(9600); - Serial.println("Enter AT commands:"); - BT1.begin(9600); - } - -void loop() - { - if (BT1.available()) - Serial.write(BT1.read()); - - if (Serial.available()) - { String S = GetLine(); - BT1.print(S); - Serial.println("---> " + S); - } +void setup(){ + Serial.begin(9600); + Serial.println("Enter AT commands:"); + BT1.begin(9600); } -String GetLine() - { String S = "" ; - if (Serial.available()) - { char c = Serial.read(); ; - while ( c != '\n') //Hasta que el caracter sea intro - { S = S + c ; - delay(25) ; - c = Serial.read(); - } - return( S + '\n') ; - } - } +void loop(){ + if (BT1.available()) { + Serial.write(BT1.read()); + } + if (Serial.available()) { + String S = GetLine(); + BT1.print(S); + Serial.println("---> " + S); + } +} + +String GetLine(){ + String S = "" ; + if (Serial.available()) { + char c = Serial.read(); + while ( c != '\n') { //Hasta que el caracter sea intro + S = S + c ; + delay(25) ; + c = Serial.read(); + } + return( S + '\n') ; + } +} ``` + ---- Cambio de configuración del módulo bluetooth mediante **comandos AT**. @@ -205,18 +199,18 @@ void loop(){ SoftwareSerial miBT(10,11); byte pepe; -void setup() { +void setup(){ Serial.begin(9600); Serial.print("Listo"); miBT.begin(9600); pepe = map(analogRead(A0), 0 , 1023, 0, 99); } -void loop() { - if(miBT.available()) { +void loop(){ + if(miBT.available()){ Serial.write(miBT.read()); //lee BT y envia a Arduino } - if(Serial.available()) { + if(Serial.available()){ miBT.write(map(analogRead(A0), 0 , 1023, 0, 99)); // lee Arduino y envia a BT miBT.write(pepe); }