I have spent a number of hours trying to connect an HC-05 bluetooth module to my Mega 2560. What I am trying to do is put the HC-05 in AT command mode. I have read probably a dozen examples and tried probably 6 different scripts with no success. I am never able to get the HC-05 to return any data.
I am pretty sure my wiring is correct:
2560 to HC-05
5v VCC
GND GND
RX1 TX (Mega Pin 19)
TX1 RX (Mega Pin 18 - but run through a voltage divider using 2 resistors)
My first question is "what is Serial1 ?" I understand there are 4 UARTS on the board, but which pins does Serial1 correspond to ? I had thought TX1/RX1, but the examples are all over the place. I have even seen Serial1 used to read from the Serial Console and then write to the HC-05. So how does it work ?
And I have tried SoftwareSerial BTserial examples as well, still with no success. I mean this should be about 10 lines of code, so I am obviously missing something. Any help would be appreciated.
My problem is that there are a ton of examples out there for HC-05 code and wiring, and none of them work for me (I have have tried at least 6 or 7 different ones). So what I was looking for was what Wawa sent, a good basic description of Serial vs Serial1. So now that I get it, I can put together my own code and wiring and THEN post it because I'll bet I still won't be able to get it to work. I am actually concerned I have somehow "blown up" both the the HC-05 I have. Thanks ....
You CAN use software serial but doing so in the light of four (4) hardware serial ports usually marks you as somebody who doesn't know what they are doing. And note also that not all of the plethora of available pins are kosher for software serial anyway. Software serial is always best avoided, very few people will ever find good reason for using it on a Mega, and the OP is surely not one of them.
Because there are 3 extra hardware serial ports. Hardware serial ports are more robust and capable of much higher speeds.
If you do use software serial, for what reason I don't know, you must be careful to use pins that support pin change interrupts. Not all pins do. See the software serial reference.
I would like to thank everyone who responded and with your help I have managed to figure it all out. I have two HC-05s working with my Mega 2560 and talking to one another in a Master Slave relationship. The only thing I still haven't figured out was the voltage divider circuit, so I used a 10K potentiometer to get 3.3v, which worked fine. Thanks again.
And if you need a good "working" example of the sketch and wiring let me know.
I guess that is because everybody talks about it and assumes you know what they mean. A 1k/2k resistance pair will suffice. You will see a bazillion examples in Google images. You will also see a lot of examples with no divider...
Tried 1k/2k, but it is unclear if was the divider that didn't work, or more likely, I just didn't know what I was doing. The potentiometer worked, but I also bought a couple of Buck converter voltage regulators as that is easier. Thanks