Recently purchased an Hm-11 BLE module, and connected it to a Teensy 3.2.
I can see the BLE module (AnyFlite) on my phone using the MSMBle app.
The following code was used to initialize it:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}
void loop() // run over and over
{
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available())
mySerial.write(Serial.read());
}
When opening the Serial monitor, I see the "Good Morning" text, however when sending AT commands there is no response. There is nothing received on the phone app either. (when connecting all I see is received text: 00
Upon sending commands from my phone to the module, I see garbage values in the serial monitor.
My understanding is that this is caused by a baud rate mismatch.. I have cycled through all the Baud rates and still face the same issue.
I checked the voltage between ground and vcc of the module and it is at 3.3v, which is what is required.
Exhausted all troubleshooting options.
EDIT
Changed to the following code when I was told about UARTS:
#define HWSERIAL Serial3
void setup() {
Serial.begin(9600);
HWSERIAL.begin(57600);
}
void loop() {
int incomingByte;
if (Serial.available() > 0) {
incomingByte = Serial.read();
Serial.print("USB received: ");
Serial.println(incomingByte, DEC);
HWSERIAL.print("USB received:");
HWSERIAL.println(incomingByte, DEC);
HWSERIAL.write(Serial.read());
}
if (HWSERIAL.available() > 0) {
incomingByte = HWSERIAL.read();
Serial.print("UART received: ");
Serial.println(incomingByte, DEC);
HWSERIAL.print("UART received:");
HWSERIAL.println(incomingByte, DEC);
Serial.write(HWSERIAL.read());
}
}
When I send an AT
command from the Serial Monitor, I get the following:
USB received: 65
USB received: 10
When I send a command from my phone (in this case AT+ADDR?
), I get the following:
UART received: 12
ÿUART received: 8
ÿUART received: 13
î
Still, garbage is being output.
OK
is returned in the serial monitor. Changed the baud rates of mySerial, meaning the baud rate for the software serial port (also tried both). did not know about UARTs, will look it up. \$\endgroup\$