0

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?

asked Feb 19, 2018 at 16:32
1
  • 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 fail Commented Feb 19, 2018 at 16:38

1 Answer 1

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");
}
answered Feb 19, 2018 at 16:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.