Bluetooth JY-MCU

Hi everyone!

I recently ordered a few components to use with my old arduino Duemilanove, and among them is a bluetooth JY MCU module. I've been trying to use it for some days but I hit a problem I don't know how to tackle.

So basically I changed the parameters of the JY-MCU for it to communicate at baud rate 115 200, and then I wired it to the Arduino. I then paired the bluetooth module with and Android phone, and via an app such as Blue Term, I try discussing with it. I used 3 different apps to see if it would change.

The smartphone receives messages from the Arduino and displays them on screen; but when I enter a letter or number, the Arduino does not receive anything. Since I can receive characters on the samrtphone, I assumed the wiring, the baud rate and the pairing were right; so I don't know how to look after.

When I open the arduino serial terminal, I can perform the actions I wish. I also tried disconnecting the arduino from the PC and alimenting it with an external power source, in order to be sure not to mess up the rx and tx lines.

So, I don't know where to look next! Do you people have any advice? Thank you!

Here is my code (which is veryvery similar to http://dukextrem.blogspot.pt/2013/02/test-du-module-bluetooth-jy-mcu.html)

/* simple test LED */
char val; // variable pour recevoir les données du port série
int ledpin = 13; // LED connected to pin 2 (on-board LED)
void setup()
{
pinMode(ledpin = 13, OUTPUT); // broche 13 en mode sortie
Serial.begin(115200); // communication série en 115200bps
}

void loop() {
Serial.println("Welcome. 1 to light on, 0 to ligth off.");
while(Serial.available() == 0)
{;}
val = Serial.read(); // lecture des données est stock dans 'val'
Serial.println("I received something!");
if( val == '0' ) // si '0' est reçue
{
digitalWrite(ledpin, LOW); // LED 13 est éteint
Serial.println("13 off"); // envoi "13 off" sur le port sortie
}
if( val == '1' ) // si '1' est reçue
{
digitalWrite(ledpin = 13, HIGH); // LED 13 est allumé on
Serial.println("13 on"); // envoi "13 on" sur le port sorti
}
Serial.flush();
}

First test I would make if I was you it's remove the chip atmega328 (carefully)from the Duemilanove board and leave it wired to the bluetooth.
Then plug the USB cable on the duemilanove and open the serial port created by the FTDI232 chip using the correct serial port.
Now using the android device search for bluethooth, connect to it and the send some commands(letters, number ..)
If all is ok you should see those characters arriving on the serial terminal.You could also send characters from the terminal to the android just typing on the terminal and press enter at the end
For this test (sending characters)I would recommend using Putty and using its native COM Port hiper-terminal support.
Putty send the characters on the fly without need to give an enter at the end of the character.If you press a key there(putty terminal) it should be sent instantaneously to the android.
All this tests will prove your wiring is ok and then you can put the chip back and move to programming
Looking too your code I notice this
Serial.flush(); //what you think this does?
flush change its behaviour some versions ago.It does not clean the serial buffer anymore if this was your intention

while(Serial.available() == 0)
{;}

This is not a pretty way of doing this

val = Serial.read(); // lecture des données est stock dans 'val'
Serial.println("I received something!");

When you send something in android app did you get this feedback?

Post the results

BobbyWomack:
ince I can receive characters on the samrtphone, I assumed the wiring, the baud rate and the pairing were right; so I don't know how to look after.

OK, so nothing wrong with pairing and wiring. Try this code

void setup()
{
    Serial.begin(115200);
    Serial.println("OK then, you first, say something.....");
    Serial.println("Go on, type something in the space above and hit Send, or just hit the Enter key"); 
}
 
void loop()
{
  while(Serial.available()==0)
  {}
  delay(500);
  Serial.println("I heard you say:      ");
  while(Serial.available()>0)
  {
    Serial.write(Serial.read());// note it is Serial.WRITE
  }
  Serial.println("");
}

Hey, thank you for both your answers.

HugoPT, I tried removing the Atmega chip, and connecting the module like this to the computer. It didn't work. I have to admit I didn't take to much time with it, because I almost broke the chip while taking it out. I wanted to get it back in and not touch it anymore. So I took my fdti cable, and plug the module directly to my pc. I then paired it with the android device, and I was able to receive and send messages from the pc, and from the android phone.
And, in my previous code, no, the feedback did not arrive. It seemed like the Arduino could not receive anything from the Android device.

I also tried the code you pasted Nick, and it did not work. I had tried to sprinkle some delays around the code, but it hadn't work either.

Now though, I am sure the problem isn't from the module thank to the experiment you adviced Hugo.

Another thing. With your code, Nick. I tried it, it did not work. Then I tried with the Arduino serial terminal, to test, and I forgot to shut off the bluetooth terminal on the android. It turned out that, with the terminal, I was able to send things to the Arduino. The android device also received what I had sent with the pc. But the pc nor the arduino seemed to have received what the android was saying.

Thank you for your advice, I'll keep looking & I'll let you know if I find anything! If anyone has advice, please let me know!

Flashnews!

So, i tried your code again Nick, but without the pc connexion and just with an external power source. It worked, the arduino did reply! It is still pretty erratic, though. For example, it recognise when it receives 2 characters or more, but not 1. But I'll figure it out from there!

Thank you for your help & bye!

OK, you found that before I could reply.

You cannot use bluetooth and serial on the same computer at the same time. You CAN use the serial on a desktop and bluetooth on a laptop at the same time!

The code I posted is crude and really only serves to prove that the two-way communication is kosher.

Good luck. The big secret about bluetooth is that there is no secret.......