Trouble Receiving Data with HC-06 & Arduino Due

Hello, I am having some trouble receiving data over blue tooth to my Arduino due from HC-06 module. The problem is that the arduino is not reading the correct value with Serial1.read() or the HC is not sending the correct value. It could also be something to do with the ARM controller?

I have the device connected correctly I believe Arduino - HC Rx1 - Tx Tx2 - Rx 3.3v - Vin Gnd - Gnd

Here is the code I am using to test:

void setup() { Serial1.begin(9600); Serial1.println("Starting Test"); }

void loop() { if(Serial1.available()) { Serial1.println("Begin Read Attempt"); Serial1.println(Serial1.read()); } }

On my bluetooth enabled laptop, I am able to pair to the device and receive the messages "Starting Test" and "Begin Read Attempt", but the Serial1.read() is giving weird values for keyboard inputs (Such as 0 for most characters or random numbers like 64 or 96)

I have tested with both terra view and arduino ied serial tool and neither work.

I have also tested the HC and program with an arduino nano and it works perfectly fine.

(Baud rate is also confirmed correct and I have tried with 38400 baud as well)

jmsigler: I have the device connected correctly I believe Arduino - HC Rx1 - Tx Tx2 - Rx 3.3v - Vin Gnd - Gnd

I believe not, not much of it looks a good idea, and I don't think you have done what you say you have done. I assume you are using the HC-06 on a four pin breakout board, usually a JY-MCU. I say this because I have never seen one sold any other way and, if this is the case, it should be connected to 5v. It may work on 3.3v but there is no good reason to tempt fate by defying clear instructions. If you really are using some unusual shield, it might still pay to ensure that it really is getting the proper power, as there are HC-05 shields that simply have the same breakout board stuck on them.

There is also no good reason to transmit on Serial2 and receive on Serial1. The command Serial1.print will never work if Tx1 is not connected.

Note that a successful pairing is no guarantee of communication. It is simply an exercise between the bluetooth modules, and Arduino is not involved.

If the HC-06 has ever worked at 9600 baud, it will never work at 38400 unless you specifically configure it to do so.

Your main problem could simply by improper configuration at the PC end. I believe these things are usually simpler using a phone.

That is a typo, I meant tx1 not 2. I was also configuring the HC using at commands to set the baud rate. I will try changing the supply voltage to 5v rather than 3.3 and see if that works.

Changing supply voltage to 5v did not work either.

Sorry to hear that, but it might just be a simple procedural problem, particularly in the light of you getting it OK with the Nano. I understand the Due is a 3.3v version of the Mega. I assume you are not using any voltage dividers on the signal lines

You might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

Update on my troubleshooting progress.

I made a slightly modified code to see what keyboard inputs were actually coming in as: int blueToothVal;

void setup() { Serial1.begin(9600); Serial1.println("Start"); }

void loop() { if(Serial1.available()) {//if there is data being recieved blueToothVal=Serial1.read(); //read it Serial1.print(" gives "); Serial1.println(blueToothVal); } delay(10); }

(Not sure how to make code box sorry)

From this code, I am getting these results with my Due http://imgur.com/x8F567a It is pretty obvious that the input is still going up as it should when you go up the ASCII table, but it is not giving the correct values at all.

I also tried using a voltage divider to step possible 5v output of bt module to 3v although from Nick's sources it should actually be 3v already. This produced no communication at all.

Could it be something to do with the data type?

I think I should have said “I hope you are not using any voltage dividers on the signal lines”

I think the powers that be changed the code box without telling anybody but the in-crowd. Try the </> at the left hand end.

The problem might be data type, so try the .ino I posted.

Your ino gives me the same results as my code (randomness like w mapping to f).