I am currently working on a project with a HC-06 module. I hooked it up accordingly like so:
Arduino -> HC-06
5V -> VCC
GND -> GND
TX -> RX
RX -> TX
and I ran this code:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("test");
Serial.print("\n");
}
Strangely enough that does not work at all. When I am using neither with or without PC as the power source. When I am using SoftwareSerial like this it works like a charm:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX
void setup() {
mySerial.begin(9600);
}
void loop() {
mySerial.print("test");
mySerial.print("\n");
}
Can someone please explain why and of course how to fix that?
-
assuming you have double checked that the wiring (tx/rx) is the same between the two. Also are you sure your upload completes when you use the hardware serial? Many times if another device is attached to the hardware serial port, the programing will failChad G– Chad G2018年02月19日 16:38:48 +00:00Commented Feb 19, 2018 at 16:38
1 Answer 1
You are using a Leonardo. Pins 0/1 aren't Serial
, they're Serial1
. Serial
is the built-in USB connection.
void setup() {
Serial1.begin(9600);
}
void loop() {
Serial1.print("test");
Serial1.print("\n");
}