如何将两个 BLE 模块相互连接?
How can I connect two BLE modules to eachother?
你好,我想用 BLE 模块连接两个 Arduino,但我不知道我可以使用什么模块以及如何使用它。我知道蓝牙连接是基于主从关系,但是当一个是主从时,如何搜索另一个BLE模块进行连接,然后如何连接两个模块?
我曾使用蓝牙连接到 Android,但不是 BLE 或 2 个 Arduinos 之间。但是,我确实找到了一些文章,它们应该提供一些对我有意义的指导。
Your BLE modules should connect the same way as BT2 modules. I suspect BLE will become the norm before too long.
The AT codes are the same for both the HC-05 and the HM-10 and the latter should be a drop-in replacemnt for the former. In the light of this, the article by Philipe Cantin on Arduino<>ARduino connection should apply with BLE.
You need modules that are in master mode. While master modules are in slave mode by default, they can all be set up as master. I am not aware of any BLE module that is slave-only.
http://phillipecantin.blogspot.com.au/2014/08/hc-05-bluetooth-link-with-zero-code.html
Note that, if power is a concern, both modules need to be BLE.
https://forum.arduino.cc/index.php?topic=358570.0
In the Connecting 2 Arduinos by Bluetooth using a HC-05 and a HC-06: Pair, Bind, and Link post I explained how to connect a HC-05 to a HC-06 so that when powered they automatically made a connection. Here we look at using that connection to get Arduinos talking over Bluetooth.
Most HC-05s and HC-06s have 3.3v TX and RX pins. 5V Arduinos will read 3.3v as HIGH so the BT modules TX pin can be connected directly to the Arduino RX pin. However, the Arduino TX pin needs to be converted to 3.3v before connecting to the BT modules RX pin. A simple way to do this is by using a voltage divider made from 2 resistors; I generally use 1 x 1K and 1 x 2K.
Arduino RX (pin 8) to BT module TX pin
Arduino TX (pin 9) to BT module RX pin via a voltage divider
Both Arduinos have the same connections to the BT modules.
* Sketch: Arduino2Arduino_MASTER_01
* By Martyn Currey
* 08.04.2016
* Written in Arduino IDE 1.6.3
*
* Send commands through a serial connection to turn a LED on and OFF on a remote Arduino
* There is no error checking and this sketch sends only
* Commands should be contained within the start and end markers < and >
*
* D8 - AltSoftSerial RX
* D9 - AltSoftSerial TX
*
*/
// AltSoftSerial uses D9 for TX and D8 for RX. While using AltSoftSerial D10 cannot be used for PWM.
// Remember to use a voltage divider on the Arduino TX pin / Bluetooth RX pin
// Download AltSoftSerial from https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
#include <AltSoftSerial.h>
AltSoftSerial BTserial;
// Change DEBUG to true to output debug information to the serial monitor
boolean DEBUG = true;
void setup()
{
if (DEBUG)
{
// open serial communication for debugging and show
// the sketch filename and the date compiled
Serial.begin(9600);
Serial.println(__FILE__);
Serial.println(__DATE__);
Serial.println(" ");
}
// open software serial connection to the Bluetooth module.
BTserial.begin(9600);
if (DEBUG) { Serial.println("BTserial started at 9600"); }
} // void setup()
void loop()
{
BTserial.println("<LEDON>");
if (DEBUG) {Serial.println("LEDON command sent");}
delay (1000);
BTserial.println("<LEDOFF>");
if (DEBUG) {Serial.println("LEDOFF command sent");}
delay (1000);
}
http://www.martyncurrey.com/arduino-to-arduino-by-bluetooth/
你好,我想用 BLE 模块连接两个 Arduino,但我不知道我可以使用什么模块以及如何使用它。我知道蓝牙连接是基于主从关系,但是当一个是主从时,如何搜索另一个BLE模块进行连接,然后如何连接两个模块?
我曾使用蓝牙连接到 Android,但不是 BLE 或 2 个 Arduinos 之间。但是,我确实找到了一些文章,它们应该提供一些对我有意义的指导。
Your BLE modules should connect the same way as BT2 modules. I suspect BLE will become the norm before too long.
The AT codes are the same for both the HC-05 and the HM-10 and the latter should be a drop-in replacemnt for the former. In the light of this, the article by Philipe Cantin on Arduino<>ARduino connection should apply with BLE.
You need modules that are in master mode. While master modules are in slave mode by default, they can all be set up as master. I am not aware of any BLE module that is slave-only.
http://phillipecantin.blogspot.com.au/2014/08/hc-05-bluetooth-link-with-zero-code.html
Note that, if power is a concern, both modules need to be BLE.
https://forum.arduino.cc/index.php?topic=358570.0
In the Connecting 2 Arduinos by Bluetooth using a HC-05 and a HC-06: Pair, Bind, and Link post I explained how to connect a HC-05 to a HC-06 so that when powered they automatically made a connection. Here we look at using that connection to get Arduinos talking over Bluetooth.
Most HC-05s and HC-06s have 3.3v TX and RX pins. 5V Arduinos will read 3.3v as HIGH so the BT modules TX pin can be connected directly to the Arduino RX pin. However, the Arduino TX pin needs to be converted to 3.3v before connecting to the BT modules RX pin. A simple way to do this is by using a voltage divider made from 2 resistors; I generally use 1 x 1K and 1 x 2K.
Arduino RX (pin 8) to BT module TX pin
Arduino TX (pin 9) to BT module RX pin via a voltage divider
Both Arduinos have the same connections to the BT modules.
* Sketch: Arduino2Arduino_MASTER_01
* By Martyn Currey
* 08.04.2016
* Written in Arduino IDE 1.6.3
*
* Send commands through a serial connection to turn a LED on and OFF on a remote Arduino
* There is no error checking and this sketch sends only
* Commands should be contained within the start and end markers < and >
*
* D8 - AltSoftSerial RX
* D9 - AltSoftSerial TX
*
*/
// AltSoftSerial uses D9 for TX and D8 for RX. While using AltSoftSerial D10 cannot be used for PWM.
// Remember to use a voltage divider on the Arduino TX pin / Bluetooth RX pin
// Download AltSoftSerial from https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
#include <AltSoftSerial.h>
AltSoftSerial BTserial;
// Change DEBUG to true to output debug information to the serial monitor
boolean DEBUG = true;
void setup()
{
if (DEBUG)
{
// open serial communication for debugging and show
// the sketch filename and the date compiled
Serial.begin(9600);
Serial.println(__FILE__);
Serial.println(__DATE__);
Serial.println(" ");
}
// open software serial connection to the Bluetooth module.
BTserial.begin(9600);
if (DEBUG) { Serial.println("BTserial started at 9600"); }
} // void setup()
void loop()
{
BTserial.println("<LEDON>");
if (DEBUG) {Serial.println("LEDON command sent");}
delay (1000);
BTserial.println("<LEDOFF>");
if (DEBUG) {Serial.println("LEDOFF command sent");}
delay (1000);
}
http://www.martyncurrey.com/arduino-to-arduino-by-bluetooth/