Daten zwischen 2 Arduinos austauschen - Bluetooth

Hi, folgende Problemstellung: Ich möchte gerne eine Kommunikation zwischen 2 Arduinos herstellen. D.h. am ersten Arduino wird irgendwas eingelesen und diese Werte sollen an den 2. Arudino über Bluetooth übermittelt werden. Dazu habe ich mir folgendes Modul 2x gekauft: Aukru HC-06 (https://www.amazon.de/gp/product/B00PL7SPGS/ref=oh_aui_detailpage_o02_s00?ie=UTF8&psc=1)

An jedem Arduino ist also jetzt ein Aukru HC-06 angeschlossen, aber ich weiss nicht, wie ich die Kommunikation aufbauen soll. Ich finde weder Tutorials, noch Hilfestellungen.

Habt ihr einen Rat?

Das glaub ich jetzt nicht.
Du solltest mal Google bemühen, dann findes du auch das hier:
https://arduino-hannover.de/2013/07/20/bluetooth-kochbuch-fur-arduino/

IMO brauchst Du mindestens noch einen HC-05. Der HC-06 funktioniert nur als Slave, und zwei Slaves können nicht miteinander kommunizieren.

Ja, das stimmt leider :frowning: Brauche ich nicht dann 3x den HC-05, wenn jeder Arduino mit jedem kommunzieren soll?

Habt ihr da einen Tipp, welche Kommunikationstechnologie am besten für Anfänger geeignet ist? Wenn ich den HC-06 umtauschen muss, kann ich ja auch gleich was anderes nehmen, falls zu umständlich mit dem.

Das ist alles recht ähnlich von der Handhabung her.

Willst du zwei oder drei Arduino miteinander reden lassen. Das geht nicht ganz aus deinem Posts hervor im Eingangspost steht zwei und im #3 fragst du ob du drei HC-05 brauchst.
Also bei diesen Bluetooth Modulen ist es eine Punkt zu Punkt Verbindung. Also HC-05=>HC06. Ich weiß nicht ganz ob man ein HC05 mit zwei HC06 pairen kann oder man es dann alles in der der Arduino Software abfangen kann.
Evtl sind auch die dir HopeRF RFM12B etwas für dich 433/868 Mhz für dich mit denen könnte man Multi Master machen mit ein paar Software tricks.
Zum weiteren helfen müsste noch die Entfernungen wissen um die es hier geht und die Menge der Daten. U.a. kann man sich auch einen Arduino MEGA vorstellen (der 4 Hardware Serielle Schnittstellen) mit dem kannst du dich dann mit zwei HC05 und zwei HC06 mit zwei Arduino gleichzeitig vom MEGA aus verbinden.
Gruß
DerDani

Also ein Sensor an Arduino 1 (Slave) soll Werte an Arduino 2 (Master) geben. Der MAster sagt dem Slave dann, welche Aktoren wie angesteuert werden. Gleiches gilt für die Kommunikation zwischen Arduino 3 (Slave) und Arduino 2(Master). Außerdem sollen die beiden Slaves auch miteinander kommunizieren können.

Also brauche ich doch 3 Bluetooth module, die sowohl Daten empfangen, als auch versenden können oder? Also 3x den HC-05 bin ich auf der sicheren Seite oder? Wobei wenn es eine Punkt zu Punkt Verbindung ist, kann der MAster ja nicht 2 Slaves ansteueren ?!

Gibt es denn ein Modul, das für die Gegebenheiten oben passt, was auch leicht zu handhaben ist für Anfänger?

Also wenn es nicht unbedingt Bluetooth sein muss, würde ich eventuell auch XBee in Erwägung ziehen (z.B. XBee with chip-antenna).
Ist zwar ein wenig teurer, aber es funktioniert ziemlich gut.
Jedes Modul kann senden und empfangen und (richtig konfiguriert) serielle Daten an jedes andere Modul senden oder von allen empfangen.
Die Module kümmern sich selbstständig um Kollisionsvermeidung etc.
Vereinfacht gesagt: Du sagst dem einen Modul an welches andere Modul die folgenden Daten geschickt werden sollen, dann schickst du die seriellen Daten beim einen Modul rein und die kommen beim Empfängermodul als serielle Daten wieder raus. In die andere Richtung geht es genauso.
Du kannst hintereinander mit verschiedenen Modulen "reden". Es gibt auch einen "Broadcast-Modus", da sind die Daten für alle Module (derselben Gruppe) bestimmt.

Das ist anders als bei Bluetooth, das in den Meisten Fällen nur eine Punkt-zu-Punkt-Verbindung ist.

Das "Punkt-zu-Punkt" ist hier mißverständlich, sollte IMO eher Client-Server oder Master-Slave heißen. Punkt zu Punkt wäre z.B. eine serielle RS-232 Kabelverbindung, die keine weiteren Stationen am Kabel zuläßt.

amanera:
Also ein Sensor an Arduino 1 (Slave) soll Werte an Arduino 2 (Master) geben. Der MAster sagt dem Slave dann, welche Aktoren wie angesteuert werden. Gleiches gilt für die Kommunikation zwischen Arduino 3 (Slave) und Arduino 2(Master). Außerdem sollen die beiden Slaves auch miteinander kommunizieren können.

Eine Kommunikation zwischen Master und Slave ist auch mit einfachen 433 MHz Modulen möglich.
Diese sind preiswert und für Anfänger auch rel. leicht zu händeln. Empfänger und Sender

Eine zusätzliche Kommunikation zwischen den Slaves ist damit auch möglich, sollte aber über den Master verwaltet werden.

Hier ist natürlich wichtig, wie zeitkritisch das Ganze ist und was die Slaves aushandeln sollen.

Als "Anfänger" würde ich mit den einfachen Modulen starten, die ja später gegen komfortablere Module getauscht werden können. Hier hast du auch den Vorteil einer größeren Reichweite gegenüber Bluetooth.

Hello everyone

i am a master student working on a project Bluetooth low energy for healthcare applications . in this project am using two Bluetooth low energy modules (Bluetooth 4.2) one of them should be connected to arduino and the other one should be connected to a pc to view the received signals using lab-view software .

The modules name Is AMB2621 Which is manufactured here in Germany.

the two Bluetooth chips can be connected using the software H-term where all the commands are given in hexadecimal format. i did connect both of those modules and i sent some data from one of them to the other.

My professor told i should connect one of them should be controlled using a micro controller and therefore i am using Arduino .

i buildup the circuit and i connected the RX of the module to pin 2 and the Tx of the module to pin 3 . then i used the library software serial to configure them. the other bluetooth module is controlled using H-term program. i sent the commands from the module that is connected to H-term in hexadecimal format starting by telling it to start scan ( 02 09 00 00 0B) and so on till i connected it to the other module which is connected to the arduino .

the first problem:-

1- is that when the module is connected to another one i should receive a message showing me the MAC address of the connected device in a hexadecimal form . when i Opened the serial monitor i saw only numbers. after some time i realized that its the mac address but in a form of decimal values instead of the hexadecimal. also when i receive data i see it on the serial monitor as decimal values .

2- The second problem is that i want to send data to the Bluetooth module which is connected to the Arduino using the serial monitor but when i give the commands in hexadecimal format i get no response and no data is transferred to the other connected device , i have tried to change the hexadecimal command ( this command should start a scan 0x02 0x09 0x00 0x00 0x0B) to decimal form but also no response .

Code :-

#include <SoftwareSerial.h>

SoftwareSerial Amber(3,2); // RX, TX

void setup()
{

Amber.begin(115200);
Serial.begin(115200);
}

void loop()
{
if (Serial.available())
{ // If data comes in from serial monitor, send it out to Amber chip
Amber.println(Serial.read());
}
if (Amber.available())
{ // If data comes in from Amber chip , send it out to serial monitor
Serial.println(Amber.read());
}
}

can you please help me with this issue .

thanks for your help in advance .

Hi

The person you are calling now, is ... seit mehreren Jahren nicht mehr hier
Der Thread bzw. die letzte Antwort ist über zwei Jahre alt.
Außerdem ist's hier eher Deutschsprachig, was dem Groh ein Antworten zusätzlich erschweren dürfte

MfG

Hi mahmoudadler,

I'm also using this tiny BLE modules from Amber, because they are certificated for Germany.

The HEX codes are not very complicated and you can directly start using Bluetooth Low Energy without knowledge of it's complexity. You only have to parse the Serial input.

The SoftwareSerial is limited in it's baudrate, the maximum (without errors) is about 9600. That's why I wired it through an extra Serial to USB converter (FTDI).

Arduino <-> Amb2621 Hardware Serial with 115200 baud
Arduino <-> PC (for debugging) SoftwareSerial with 9600 baud

I have written an ugly sketch for testing a automated connection and transfer.

  1. scan
  2. take scan results and connect
  3. transfer data
/* CENTRAL UART SCAN, CONNECT AND TRANSFER
   using AMB2621 BLE module
*/

#include <SoftwareSerial.h>

bool debug = true; // debug output on SoftwareSerial 10, 11
int WAKEUP_PIN = 12; // hardware wakeup setting

SoftwareSerial SoftSerial( 10, 11 ); // RX, TX

void setup()
{
 pinMode( WAKEUP_PIN, OUTPUT); // DigitalPin
 digitalWrite( WAKEUP_PIN, HIGH );
 SoftSerial.begin( 9600 ); // read and write commands to the MCU
 Serial.begin( 115200 ); // read and write commands to the AMB2621 BLE module
 // CMD_GETBTMAC(); // Show BTMAC of this device
 CMD_SCANSTART(); // scan for peripherals -> module acts as central device
 delay(1000); // no callback -> scan for 1s
 CMD_SCANSTOP(); // first stop scanning
 CMD_GETDEVICES_CONNECT(); // proceed scan results
}

void loop()
{
 uint8_t DATA[ 4 ] = { 0, 255, 0x2B, 0x2D };
 CMD_DATA( DATA, 4 );
 delay(1000);
}

// Functions

/* SLEEP
  set the module in sleep mode
  disables UART -> wake up with WAKEUP_PIN
*/
void CMD_SLEEP() {
 byte message[] = { 0x02, 0x02, 0x00, 0x00, 0x00 }; // CMD_SLEEP 0x02
 byte response[ 6 ] = {};
 SoftSerial.println("Send CMD_SLEEP...");
 Serial.write( message, sizeof(message)) ; // send command
 delay(10);
 for ( int i = 0; i < 6; i++ ) { // 02 42 01 00 00 41
   response[ i ] = Serial.read();
   delay(10);
 }
 PRS_STATUS( response[ 4 ] ); // check response STATUS
}

/* WAKEUP 
* untested
*/
void CMD_WAKEUP() {
 digitalWrite( WAKEUP_PIN, LOW );
 delay(5);
 digitalWrite( WAKEUP_PIN, HIGH );
}

void CMD_GETBTMAC() { // get BTMAC
 byte message[] = { 0x02, 0x10, 0x01, 0x00, 0x04, 0x17 };
 byte response[ 12 ] = {};
 Serial.write( message, sizeof(message) );
 delay(10);
 for ( int i = 0; i < 12; i++ ) { // 02 50 07 00 00 39 97 0A DA 18 00 33
   response[ i ] = Serial.read();
   delay(10);
 }
 PRS_STATUS( response[ 4 ] ); // check response STATUS
 SoftSerial.print( "\nBTMAC = " );
 for ( int i = 5; i < 11; i++ ) SoftSerial.print( response[ i ], HEX );
 SoftSerial.println();
}

void CMD_SCANSTART() {
 byte message[] = { 0x02, 0x09, 0x00, 0x00, 0x0B };
 byte response[ 6 ] = {};
 Serial.write(message, sizeof(message));
 delay( 10 );
 for ( int i = 0; i < 6; i++ ) { // 02 49 01 00 00 41
   response[ i ] = Serial.read();
   delay( 10 );
 }
 PRS_STATUS( response[ 4 ] );
}

void CMD_SCANSTOP() {
 byte message[] = { 0x02, 0x0A, 0x00, 0x00, 0x08 };
 byte response[ 6 ] = {};
 Serial.write(message, sizeof(message));
 delay( 10 );
 for ( int i = 0; i < 6; i++ ) { // 02 49 01 00 00 41
   response[ i ] = Serial.read();
   delay( 10 );
 }
 PRS_STATUS( response[ 4 ] );
}

/* Get devices and connect to the first one
   IN CONSTRUCTION
   TODO: - waiting for START_SIGNAL 0x02
         - check CMD_GET_CNF value 0x50
         - proceed number of devices and check whose names
*/
void CMD_GETDEVICES_CONNECT() {
 byte message[] = { 0x02, 0x0B, 0x00, 0x00, 0x09 }; // CMD_GETDEVICES
 byte response = 0xFF;
 byte BTMAC[ 6 ];
 int CS = 0;
 bool ok = false;
 Serial.write(message, sizeof(message));
 delay(10);
 int i = 0;
 do {
   response = Serial.read();
   delay(10);
   if ( ( i == 4 ) && ( PRS_STATUS( response ) ) ) { // skip 4 fields (START_SIGNAL, CMD, LENGTH) and check STATUS
     ok = true;
   }
   if ( ( i == 5 ) && ( ok ) ) {
     SoftSerial.println( "Found " + String( response, HEX ) + " device(s)" );
   }
   if ( ( ok ) && ( i > 5 ) && ( i < 13 ) ) {
     BTMAC[ i - 6 ] = response;
   }
   SoftSerial.write(response);
   i++;
 } while ( response != 0xFF );
 if ( debug ) for ( int i = 0; i < 6; i++ ) SoftSerial.write( BTMAC[ i ] );
 // connect message without BTMAC and CS
 byte conn[ 11 ] = { 0x02, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  // add BTMAC  
 for ( int i = 4; i < 10; i++ ) conn[ i ] = BTMAC[ i - 4 ];
 if ( debug ) for ( int i = 0; i < 11; i++ ) SoftSerial.write( conn[ i ] );
  // calculate a XOR checksum
 for ( int i = 0; i < 10; i++ ) CS = CS ^ conn[ i ];
 if ( debug ) SoftSerial.println( "CS = " + String( CS, HEX ) + "[hex]\tCS = " + String( CS, DEC ) + "[dec]\n" );
 // complete message with checksum
 conn[ 10 ] = CS;
 if ( debug ) for ( int i = 0; i < 11; i++ ) SoftSerial.write( conn[ i ] );
 // write connect message
 Serial.write(conn, sizeof(conn)); // call CMD_CONNECT 0x02, 0x06, 0x06, 0x00, BTMAC, CS
 delay( 10 );
 while( Serial.read() != 0x02 ){}; // waiting for response
 /*
  * TODO check response, CHANNELOPEN 
  */
}

void CMD_DATA( unsigned char* DATA, uint8_t len ) {
 int CS = 0;
 byte message[ 5 + len ] = { 0x02, 0x04, 0x04, 0x00 }; // DATA, CS };
 // add DATA
 for ( int i = 4; i < len + 4; i++ ) message[ i ] = DATA[ i - 4 ]; // reinterpret_cast<unsigned char *>(DATA[ i - 4 ]);
 // calculate XOR checksum
 for ( int i = 0; i < 5 + len; i ++ ) CS = CS ^ message[ i ];
 // complete message with checksum
 message[ 4 + len ] = CS;
 Serial.write( message, sizeof( message ) );
 // proceed response message
}

int PRS_STATUS( byte STATUS ) {
 switch ( STATUS ) {
   case 0x00 :
     if ( debug ) SoftSerial.println("OK\n");
     return 1;
     break;
   case 0x01 : // failed
     if ( debug ) SoftSerial.println("Operation failed\n");
     return 0;
     break;
   case 0xFF : // not permitted
     if ( debug ) SoftSerial.println("Operation not permitted\n");
     return 0;
     break;
   default :
     return 0;
     break;
 }
}

I'm working on a more stable version more checks and parsers. Please let me know if you like to contribute.

Best regards
Hannes