How can I connect two BLE modules to eachother? - arduino

Hi i would to connect two Arduino with a BLE module, but i don't know what module can i use and how to use it. I know that bluetooth connection is based on master slave relation, but when one is master how can i search the other BLE module to connect and then how can i connect the two modules?

I've worked with Bluetooth some to connect to an Android, but not BLE or between 2 Arduinos. However, I did find some articles that should provide some guidance that makes sense to me.
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.
http://www.martyncurrey.com/connecting-2-arduinos-by-bluetooth-using-a-hc-05-and-a-hc-06-pair-bind-and-link/
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/

Related

AT-Commands from ESP32 to Fanstel BC805M (nRF52805M) not working

I want to send a simple AT-Command like: AT\r\n from the ESP32 to the Fanstel BC805M (nRF52805M) breakout board. My goal is to get an answer.
Problem: The Esp32 does not get an answer from the BC805M.
Setup
Hardware
The ESP32 is connected by usb cable to my Mac.
The ESP32 connects to the BC805M by five cables -> 3V3->VDD, GND->GND, Rx->Tx, Tx->Rx, GPIO32(high)->GPIO04(P004). Rx and Tx from ESP32 are Serial2 (not the Serial0 of the programmer). The P004 pin from BC805M is set to high to enable "command-mode".
Software
The BC805M came already preloaded with The AT commands code.
The ESP32 is flashed by a simple Serial2 write/read arduino code:
#include <HardwareSerial.h>
#define RXD2 16
#define TXD2 17
#define CMD_MODE 32
void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
pinMode(CMD_MODE, OUTPUT);
digitalWrite(CMD_MODE, HIGH);
delay(1000);
Serial.println("start");
}
void loop() {
Serial2.write("AT\r\n");
delay(500);
if(Serial2.available()){
Serial.write(Serial2.read());
}
}
On Monitor, I received nothing: Terminal Output
What I tested
I connected the two ESP32 Rx and Tx Serial2 Pins with each other and the monitor prints AT AT AT ... (so this works)
I connected the ESP32 with the BC805M not by crossing Tx and Rx but like: Rx->Rx, Tx->Tx; I received the message
BlueNor 200622 started
on my monitor. This means I read the values of the Rx pin of the BC805M and wrote them to my monitor. Shouldn't this message be sent on on the Tx pin of the BC805M?
I connected to the BC805M per Android App, which connects to it via Bluetooth Low Energy. I sent commands from the app to the BC805M. But I got no response. I could read the commands I sent on the Rx Pin of the BC805M.
I connected solely the BC805M per usb to my mac and ran Arduino-IDE's monitor, the monitor prints absolutely nothing and writing AT-Commands also results into nothing.
The Fanstel support just wrote me that the BC805M Evaluation Board is NOT preloaded with the AT-Command firmware.
Only the BC805M module has it preloaded.
That explains why the AT-Commands did not work.

HC-05 bluetooth module not working properly from a distance

I have started learning about arduino and just bought a bluetooth module, HC-05. From where i bought, it says it has range of approx.10 meters. I made hc-05 connection with arduino in below described ways
I am using it as a slave with default configurations, 9600 baud rate and HC-05 name with pin 1234
GND of HC05 -> GND of `arduino`
VCC of HC05 -> 5V of `arduino`
TX of HC05 -> RX of `arduino`
RX of HC05 -> TX of `arduino` via voltage divider network 2k---|---1k
Below is my arduino code
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
// Connect the HC-05 TX to Arduino pin 2 RX.
// Connect the HC-05 RX to Arduino pin 3 TX through a voltage divider.
int pin = 13;
char c = ' ';
void setup()
{
Serial.begin(9600);
Serial.println("Arduino is ready");
pinMode(pin,OUTPUT);
// HC-05 default serial speed for communication mode is 9600
BTserial.begin(9600);
Serial.println("BTserial started at 9600");
}
void loop()
{
if (BTserial.available()>0){
c = BTserial.read();
Serial.println(c);
switch (c){
case '1' :
digitalWrite(pin,HIGH);
break;
case '2' :
digitalWrite(pin,LOW);
break;
default: break;
}
}
}
Following things happening to me:
When I power the module I am able to discover it with my phone but only when I hold my phone very near to the module. If I move away from the HC05 module, for example 3-4 feet, I am not able to discover it.
2.After connecting with it (while holding phone near to the module), I am able to send data to it but again, if I move away , only a few steps, I am unable to send data and I disconnect from it automatically. Also if I change direction of the antenna even then no communication happens.
My purpose is to control my home's lights and TV with the help of this module and Relays. But HC05 is useless so far. I was hoping that I would code it and wire it and hang it on a wall and interact it with and andoird app.
Is it suppose to happen like this? or there's something wrong with my module's antenna
thank you.

HC-05 Module AT command mode won't respond

I've been trying to connect two HC-05 bluetooth modules together as master and slave devices. I know that to do this i need to establish one as a slave device and one as a master using the AT command mode. I am using an arduino nano with each of the modules and the circuit i have used is shown:
Vcc -----> 5V
GND ----> GND
Rx ------> Rx
Tx ------> Tx
I followed various online tutorials and have used this code:
include SoftwareSerial.h
SoftwareSerial BTSerial(0, 1); // RX | TX
void setup()
{
Serial.begin(9600);
BTSerial.begin(9600); // HC-05 default speed in AT command more
Serial.println("Enter AT commands:");
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available()){
Serial.write(BTSerial.read());
}
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available()){
BTSerial.write(Serial.read());
}
}
Using the button on the module or by setting the EN pin high, i am able to put the module into AT mode as displayed by the LED blinking every 2 seconds. However, i receive no response after sending commands to the module using the serial monitor when i should receive a confirmation of my command.
Any ideas where i'm going wrong?
Here's the solution that eventually worked for me: I used this circuit with a voltage divider:
Vcc -----> 5V
GND ----> GND
D2 ------> Tx
D3 ------> Rx
I ended up having to buy an Uno for this to work, I'm assuming then that my Nano's were faulty in some way. I then used the following code:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3); // RX | TX
void setup()
{
Serial.begin(9600);
BTSerial.begin(38400); // HC-05 default speed in AT command more
Serial.println("Enter AT commands:");
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available()){
Serial.write(BTSerial.read());
}
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available()){
BTSerial.write(Serial.read());
}
}
This allowed me to enter the AT mode and also receive responses.
One of the issues was that I was using the Tx and Rx pins which are also used to communicate with the computer so cannot be used with the HC-05 at the same time.
Another issue was the baudrate: I alternated between 9600 and 38400 for each communication until I found a combination that worked, and adjusted the speed in the Serial monitor so that it made sense.
Then I was able to use the command mode normally.

Arduino Nano no serial communication SIM800C

I am trying to get my SIM800C to talk with my Arduino. There is no communication happening, though.
#include <SoftwareSerial.h>
SoftwareSerial at(2, 3);
void setup() {
Serial.begin(9600);
at.begin(9600);
}
void loop() {
// try every 2 seconds
delay(2000);
Serial.println("sending AT ... ");
at.println("AT");
while (at.available() > 0) {
Serial.write(at.read());
}
}
I am not able to get an OK back. SIM800C is supposed to detect the baud rate by itself.
I am sure there has to be a simple stupid mistake. I just don't know what to do at this point. I obviously already checked for cable break. Out of desperation I already tried to switch RX and TX. I also tried different baud rates (whatever is within the usual limitations of SoftwareSerial) but it should automatically detect it once a couple of AT commands got in anyway.
Weird enough, the pin PWX on the SIM800C needs to be hooked up to a GND to work. It started blinking every second now and is responding to AT commands.
Also it turned out that this specific module does not ship with autobauding enabled, as stated by the SIM800C documentation. The correct baud rate is 115200.
There are some problems you need to consider:
Use below sample code which transfers data between PC and SIM. Sometimes SIM module would go into power down state and won't respond on any AT command but would print some results in the serial monitor.
As already mentioned in comments it seems that your wiring is wrong and as you declared Software Serial as SoftwareSerial at(2, 3); which means pin 2 is Rx on Arduino and should connect to Tx pin of SIM and pin 3 is Tx on Arduino and should connect to Rx pin of SIM. Please don't mess with the pins and connect the pins like below correctly.
Arduino SIM
Rx 2 ----> Tx
Tx 3 ----> Rx
I'm not sure if you can power on SIM800 with a 500mA USB connector, make sure that use an external 1/2 A power supply for VCC of SIM module.
Look at the blink speed of SIM module if it connected and powered on it would blinky with 3 seconds delay and if it blinks fast, it means that it is being restarted. Also if SIM powered on correctly it would print some info like SIM READY, CALL READY, etc.
Try other baud rates like 115200 and see if you get anything on power on.
I put some macro definition to make pin mappings more clear.
#include <SoftwareSerial.h>
//SIM800 TX is connected to Arduino D2
#define SIM800_TX_PIN 2
//SIM800 RX is connected to Arduino D3
#define SIM800_RX_PIN 3
//Create software serial object to communicate with SIM800
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);
void setup() {
//Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
while(!Serial);
//Being serial communication witj Arduino and SIM800
serialSIM800.begin(9600);
delay(1000);
Serial.println("Setup Complete!");
}
void loop() {
//Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
if(serialSIM800.available()){
Serial.write(serialSIM800.read());
}
//Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
if(Serial.available()){
serialSIM800.write(Serial.read());
}
}
Yes this module will not work in this configuration. There is a pin of V_TTL With 5V pin.. This pin enables the TTL logic converter of your GSM.. You have to connect this pin to 5V in case of arduino and to 3V in case of ESP8266.See the pin configuration here

No Response from ESP8266 WIFI Module

I bought a new ESP8266 WIFI module (8pins) and flashed firmware (from https://raw.githubusercontent.com/nodemcu/nodemcu-flasher/master/Win32/Release/ESP8266Flasher.exe) it using arduino Duemilanove correctly.
I have gone through many troubleshooting steps, but on reset module does give some gibberish response, but no Ready/OK response from "AT" command.
Red LED
of module is always on but Blue light is off.
Steps taken :-
To supply enough current i used Beaglebone 3V3 supply as module Vcc.
But i'm not able to receive any response from AT commands.
Arduino Tx (5V) has brought down to 3v3 using voltage divider and
connected to Rx
In Flash settings ensured baud rate was 115200 and all settings correct
Module is working fine presumably as tried with 2 more modules same thing
Here's my connections:
//////////////////////////////////////////////////////////////////////////////
/////// CONNECTIONS ////////
/////////////////////////////////////////////////////////////////////////////
/*
ESP8266 VCC -> BeagleBone 3.3
ESP8266 GND -> Common GND (Arduino & BeagleBone)
ESP8266 CH_PD -> 3K resistor -> VCC
ESP8266 RST -> VCC or pin 13(arduino)
GPIO CAB BE LEFT OPEN OR TIED HIGH
ESP8266 Tx -> pin2 (Arduino software serial Rx)
ESP8266 Rx <- Voltage Divider <- pin3 (Arduino software serial Tx)
*/
Here's my code
#define esp8266 Serial2
#define CH_PD Vcc // but needs a narrow low pulse
#define speed8266 9600 // This is the speed that worked with my ESP8266
void setup()
{
esp8266.begin (speed8266);
Serial.begin(9600);
reset8266(); // Pin CH_PD need a reset before start communication
}
void loop()
{
while(esp8266.available())
{ Serial.write(esp8266.read()); }
while(Serial.available())
{ esp8266.write(Serial.read()); }
}
/*************************************************/
// Reset funtion to accept communication
void reset8266 ()
{
pinMode(CH_PD, OUTPUT);
digitalWrite(CH_PD, LOW);
delay(300);
digitalWrite(CH_PD, HIGH);
}
Here's the output on Serial Monitor
Arduino Serial Monitor Output
Kindly help me what am i doing wrong ?
I don't want to use another FTDI chip while arduino already have it.
At the moment I can only give you a part answer (seems I can't comment yet :) ).
The gibberish is normal when starting/resetting the ESP, it's just the boot code which outputs a boot message at 74880 baud (Which is basically the default baud rate 115200, but because the ESP starts at a lower cpu frequency, the baud rate is also lower, boot frequency is 26 mhz, normal frequency is 40 mhz, 26/40 * 115200 = 74880. If you can set your serial client to 74880 baud you should see the message, but it's an odd baudrate, so it might be hard or impossible to set.
So gibberish on reset is good! It means the ESP is working and happy, the problem is with your software (as you determined yourself too).
I assume your code is on the Arduino side?
The big question is what is flashed on the ESP, and what it's expected bahaviour is. From your question I'm not 100% sure what you did flash on it..
I think you might've flashed nodemcu on it though, which would not respond to AT commands, try to flash the 'original' AT rom from Espressif Systems on it?

Resources