I have a simple flight controller based on an Arduino Nano using an MPU6050 IMU and an HC-05 Bluetooth module. The RX/TX lines of the HC-05 are hooked to the TX/RX pins of the Nano (0, 1). There are numerous tutorials out there describing this basic setup. Without the HC-05 installed I can connect to it via the Nano's USB port and using MultiWiiConf I can see the data from the MPU6050 being reported back. When I install the HC-05 all I see via the USB connection is a flat line (i.e. no meaningful IMU data being returned.) If I disconnect the USB and connect via Bluetooth using EZ-GUI's Ground Station on an Android tablet I get meaningful IMU data back.
I am a little confused as to the RX/TX pins on the Nano. I am assuming they are the standard UART lines (i.e. basic Serial without requiring SoftwareSerial), so I am wondering if there is a conflict with the USB serial port.
Does this mean that with a device hooked to the Nano's RX/TX pins you can't use the USB serial port?
If you really need to use the USB port while HC-05 is connected, you'll have to add software serial.
U'll fine several good libraries in addition to the one built into the IDE
Hardware UART Port of NANO (RX0, TX1) communicates with Serial Monitor. If any external device is connected with RX0-TX1 pins of NANO, signal interference might occur, which will eventually affect data communication between NANO and Serial Monitor.
The HC-05 is a UART driven device; but, the NANO has only one UART Port. The solution comes from creating a Software UART Port in the NANO and then connect the HC-05 as per following diagram.
The Codes:
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // SRX | STX
// D2 pin of NANO is SRX-pin of NANO; it will have connection with TX-pin of HC-05
// D3 pin of NANO is STX-pin of NANO; it will have connection with RX-pin of HC-05 via voltage divider.
char c = ' '; //initializes to a space
void setup()
{
Serial.begin(9600);
Serial.println("Arduino is ready");
// HC-05 default serial speed for communication mode is 9600
BTserial.begin(9600);
Serial.println("BTserial started at 9600");
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTserial.available())
{
c = BTserial.read();
Serial.write(c);
}
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
{
c = Serial.read();
// Copy the serial data back to to the serial monitor.
// This makes it easy to follow the commands and replies
Serial.write(c);
BTserial.write(c);
}
}