Hi, ich versuche als Teil einer Maturaarbeit eine Verbindung zwischen zwei Arduinos mit Hilfe von 2 Bluetooth-Modulen (https://www.sparkfun.com/products/10393) herzustellen. Hierzu habe ich jeweils die Bluetooth-Module mit den Arduinos (Leonardo, Uno) verbunden und ein kleines Testprogramm geschrieben. Leider funktioniert dies nicht und auch mit Hilfe eines Testprogrammes aus dem Internet, konnte keine Verbindung hergestellt werden (https://github.com/yexiaobo-seeedstudio/Bluetooth_Shield/tree/master/BluetoothShieldDemoCode/examples). Könnt ihr mir eventuell helfen und ein paar Tips sagen, wie ich eine Verbindung zwischen den Arduinos herstellen kann? Slave:
1 | #include <SoftwareSerial.h> |
2 | |
3 | #define BTX 2 // TX-O pin of bluetooth mate, Arduino D2
|
4 | #define BRX 3 // RX-I pin of bluetooth mate, Arduino D3
|
5 | |
6 | SoftwareSerial Bluetooth (BTX, BRX); |
7 | |
8 | void setup() { |
9 | Serial.begin(9600); |
10 | Bluetooth.begin(115200); |
11 | delay(320); // IMPORTANT DELAY! (Minimum ~276ms) |
12 | Bluetooth.print("$$$"); // Enter command mode |
13 | delay(15); // IMPORTANT DELAY! (Minimum ~10ms) |
14 | Bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity |
15 | Bluetooth.println("SM,1"); // Slave-configuration |
16 | Bluetooth.println("C, 000666605063"); //MAC-address |
17 | Bluetooth.println("F,1"); |
18 | Bluetooth.println("---"); |
19 | Bluetooth.begin(9600); // Start bluetooth serial at 9600 |
20 | |
21 | |
22 | }
|
23 | |
24 | void loop() { |
25 | if(Bluetooth.available()){ // If the bluetooth sent any characters |
26 | Serial.println(Bluetooth.read()); |
27 | }
|
28 | }
|
Master:
1 | #include <SoftwareSerial.h> |
2 | |
3 | int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2 |
4 | int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3 |
5 | |
6 | SoftwareSerial bluetooth(bluetoothTx, bluetoothRx); |
7 | |
8 | void setup() |
9 | {
|
10 | Serial.begin(9600); // Begin the serial monitor at 9600bps |
11 | bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps |
12 | delay(320); // IMPORTANT DELAY! (Minimum ~276ms) |
13 | bluetooth.print("$$$"); // Enter command mode |
14 | delay(15); // IMPORTANT DELAY! (Minimum ~10ms) |
15 | bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity |
16 | bluetooth.begin(9600); // Start bluetooth serial at 9600 |
17 | }
|
18 | |
19 | void loop() |
20 | {
|
21 | if(bluetooth.available()) // If the bluetooth sent any characters |
22 | {
|
23 | // Send any characters the bluetooth prints to the serial monitor
|
24 | Serial.print((char)bluetooth.read()); |
25 | }
|
26 | if(Serial.available()) // If stuff was typed in the serial monitor |
27 | {
|
28 | // Send any characters the Serial monitor prints to the bluetooth
|
29 | bluetooth.print((char)Serial.read()); |
30 | }
|
31 | // and loop forever and ever!
|
32 | }
|