Author Topic: Frage betreffend Grove Serial Bluetooth Modul  (Read 11755 times)

House

  • freakyfriday
  • Jr. Member
  • *
  • Posts: 95
  • Karma: +1/-0
    • Hausammann-Dekor
Frage betreffend Grove Serial Bluetooth Modul
« on: August 31, 2015, 06:44:18 PM »
Hallo erstmal,  :D

Kann mir vielleicht jemand bei der Kommunikation zwischen einem Grove Serial Bluetooth Modul und einem Teensy helfen? Leider haben mich die Beispiele aus der Bibliothek von Seed nicht weiter gebracht. Mit einem Arduino gehts einigermassen mit der Kommunikation, d.h. über die im Beispiel verwendete SoftwareSerial Library. Beim Teensy brauche ich die ja nicht, da drei Serials zur Verfügung stehen, wobei ich mich für  RX2(Pin 9) und TX2(Pin 10) entschieden habe. Gerne würde ich mir die über Bluetooth empfangenen Daten im Serial Monitor anzeigen lassen. Ich hab schon einiges Probiert, jedoch steh ich irgendwie auf dem Schlauch. Ich füge mal unten das Slave-Example file von Seed an.

Code: [Select]
#include <SoftwareSerial.h>   //Software Serial Port
#define RxD 6
#define TxD 7
 
SoftwareSerial blueToothSerial(RxD,TxD);
 
void setup()
{
  Serial.begin(9600);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  setupBlueToothConnection();
}
 
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(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=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STPIN=0000\r\n");//Set SLAVE pincode"0000"
  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
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}


Danke vorab für Eure Tips!

MfG House
« Last Edit: September 04, 2015, 11:41:23 PM by House »

boxtec-support

  • Moderator
  • Hero Member
  • *****
  • Posts: 787
  • Karma: +15/-0
    • Boxtec Web
Re: Frage betreffend Grove Serial Bluetooth Modul
« Reply #1 on: August 31, 2015, 07:38:56 PM »
Hallo House,

Mit dem Teensy 3.x solltest Du SoftwareSerial nicht benötigen, der verfügt schon über 3 integrierte UARTs.
Schau mal unter folgender URL:

https://www.pjrc.com/teensy/td_uart.html

Grüsse - Christoph

House

  • freakyfriday
  • Jr. Member
  • *
  • Posts: 95
  • Karma: +1/-0
    • Hausammann-Dekor
Re: Frage betreffend Grove Serial Bluetooth Modul
« Reply #2 on: August 31, 2015, 08:04:59 PM »
Supi, danke für den Link! Ich habe nun das Beispiel abgeändert. Ich konnte es mit dem Teensy testen, kompilieren tut es schon mal ohne Fehler und uploaden auch, jedoch bekomme ich nichts zu sehen im Monitor.

Unten meine "Anpassungen":

Code: [Select]
#include "HardwareSerial.h"
#define blueToothSerial Serial2
 
void setup()
{
  Serial.begin(9600);
  delay(15); //Habe auf der Teensy Homepage gelesen man sollte nach Serial.beginn ein delay oder ein while einsetzen, also wie beim Arduino Leonardo.
  blueToothSerial.begin(38400);
  delay(15);
  setupBlueToothConnection();
}
 
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(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=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STPIN=0000\r\n");//Set SLAVE pincode"0000"
  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
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}
Gruss House
« Last Edit: September 04, 2015, 11:40:54 PM by House »

mikeZ337

  • Newbie
  • *
  • Posts: 28
  • Karma: +3/-1
Re: Frage betreffend Grove Serial Bluetooth Modul
« Reply #3 on: September 02, 2015, 07:30:26 PM »
Du hast zweimal
Code: [Select]
blueToothSerial.begin(38400); in deinem Sketch, bestimmt nicht der Fehler, ist aber unnötig.

Manchmal hilft es am Anfang des Programms ein delay von einer bis zwei Sekunden hinzuzufügen. Das Problem ist oft, dass Sensoren oder andere Module ein paar Millisekunden zum starten benötigen - der Arduino hat einen relativ langsamen Start und da stört dies nicht - andere Boards (u.a. Teensy) starten erheblich schneller, mit dem Resultat dass das Board bereits gestartet ist und mit dem Sensor kommunizieren will, dieser sich aber noch in der "Aufwärmphase" befindet. Ein delay von einer Sekunde zu Beginn des Sketches ist da immer eine gute Idee (sofern die Anwendung nicht zeitkritisch ist)

Sonst sehe ich nichts falsches am Code.

Wie hast du denn das Bluetooth Modul angeschlossen: Bluetooth TX zu Serial2 RX(Pin 9) und Bluetooth RX zu Serial2 TX(Pin 10). Woher hast du die 5V für das Bluetooth Modul?

House

  • freakyfriday
  • Jr. Member
  • *
  • Posts: 95
  • Karma: +1/-0
    • Hausammann-Dekor
Re: Frage betreffend Grove Serial Bluetooth Modul
« Reply #4 on: September 03, 2015, 12:23:12 PM »
Lieber mikeZ337,

Danke für Deine Hilfe bzw. Anmerkungen und Frage. Leider bin ich bis jetzt noch nicht viel weiter gekommen. Soll ich ein LLC dazwischen hängen? Betreffend Teensy sehe ich keine Probleme, da Pin 9 und 10 schliesslich 5V tollerant sein sollten. Das Problem sehe ich in dem Bezug nur auf der Bluetoothseite, da dies ein 5V Baustein ist, jedoch sollte der theoretisch auch mit 3.3 V funktionieren(hier meine ich nicht die Speisespannung).  Die Versorgungsspannung nehme ich von Vin bzw. USB 5V. Zur anschlussbelegung, ich habe den TX Pin vom Bluetoothmodul mit dem RX Pin 9 und den RX vom Bluetooth mit TX Pin 10 vom Teensy verbunden. Das Modul blinkt frischfröhlich vor sich hin und ich konnte das Modul auch mit einer anderen Bluetooth Device pairen. Leider bleibt jedoch der serielle Monitor weiss, die Baudrate habe ich auch  überprüft.  Der Beispielsketch mit "Hello world" funktioniert am Monitor. Ich habe beide Sketches auf zwei Teensys laufen lassen, und das Slave Bluetooth Example auf dem Arduino, um hardwareseitige Defekte auszuschliessen Ich habe nun auch das zweite, bzw. das erste "blueToothSerial.begin(38400);" entfernt und nur noch das in "void setupBlueToothConnection()" belassen. Betreffend des erwähnten Delays, wollte ich noch gerne erfahre, an welcher Stelle es am Besten platziert wird.
Unten noch mal mein Sketch mit den erwähnten Verbesserung.


Code: [Select]
#define blueToothSerial Serial2
 
void setup()
{
  Serial.begin(9600);
  setupBlueToothConnection();
}
 
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(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=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STPIN=0000\r\n");//Set SLAVE pincode"0000"
  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
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}

Gruss House
« Last Edit: September 04, 2015, 11:41:40 PM by House »

 

anything