lunes, 16 de septiembre de 2013

PROGRAMA ANDROID Y PROGRAMACIÓN BLUETOOTH

Buenos Días Jóvenes,


Cordial saludo a continuación adjunto archivos que contienen:


  • Programa en arduino para el manejo de tarjeta bluetooth
  • App de android para el manejo de datos en bluetooth
  • Código fuente de la app de android
  • Código de manejo de la tarjeta bluetooth en arduino.



Código Arduino para control de Tarjeta Bluetooth


/* Upload this sketch into Seeeduino and press reset*/
 
#include <SoftwareSerial.h>
#include <Servo.h>

#define RxD 6
#define TxD 7
 
#define DEBUG_ENABLED  1

Servo myservo0;
Servo myservo1;
 
SoftwareSerial blueToothSerial(RxD,TxD);
 
void setup() 
{
  Serial.begin(9600);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  myservo0.attach(2);
  myservo1.attach(3);
  Serial.println("Configuracion Bluetooth Comienza!");
  setupBlueToothConnection();
  myservo0.write(90);
  myservo1.write(90);
  delay(15);
}

void loop() 
  char recvChar;
  while(1){
    if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
      recvChar = blueToothSerial.read();
      Serial.print(recvChar);
      if ((recvChar & 0x0F)==0x04){
        myservo0.write(0);
        delay(15);
      }else if ((recvChar & 0x0F)==0x08){
        myservo0.write(180);
        delay(15);
      }else{
        myservo0.write(90);
        delay(15);
      }
      if ((recvChar & 0xF0)==0x10){
        myservo1.write(180);
        delay(15);
      }else if ((recvChar & 0xF0)==0x20){
        myservo1.write(10);
        delay(15);
      } 
    }
    if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
      recvChar  = Serial.read();
      blueToothSerial.print(recvChar);
    }
  }
 
void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=OkmadeArduino\r\n"); //set the bluetooth name Cambiar
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  blueToothSerial.print("\r\n +STPIN=0000\r\n");
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  Serial.println("Configuracion Bluetooth Terminada!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}


No hay comentarios.:

Publicar un comentario