Arduino Uno + Bluetooth Connectivity Issue

About master/slave, as you think your module is master there is simple way check it. can you look tracks or measure where status led on your btmodule is connected. if it's connected to pin 24 of module it then have hc04 firmware and its slave only. if led goes pin 31 or 32 then hc05 firmware and it can be master or slave.
to find right pins, tx and rx are 1 adn 2 and opposite side last pin is 34
pin 1 is also marked with white point

If its hc04 its ok for you as its slave and default baudrate is 9600, but if its hc05 you can change it to slave sending AT+ROLE=0\r\n command from arduino or terminal via tx/rx pins. before that you must put it in at mode by setting pin 34 of module to high state, dont use 5v but 3.3v for this, and powerup it. its now in at mode and baudrate must be now 38400.
when paired defaul baudrate for both is 9600.
you can also test ttl serial communication by sending AT (for hc04) or AT\r\n(hc05), module should reply OK, you can use led off/on to show ok reply.

Other thing, that module have onboard regulator so it can be connected to 5v, but rx and tx are still 3.3v tolerant. im not sure about atmel chips(i use schottky & pullup) but some other cases ttl serial communication is not working if it is connected to 5v logic. i suggest to add atleast resistor(maybe 1k)from arduino tx to module rx line.

hope that help you or someone else if your module is wrong mode.

Hi, I am using several cheap bt modules with my dev systems. I am using IVT BlueSoleil (the application/driver comes with the Sweex usb bt dongle) and I am in doubt whether it will work without this application (under XP). There are always two ports listed (ie com15, 16) - no idea why, when connected to the first bt module the third com appears (com17) and this is the com I connect myself to via ie teraterm. When you connect to the second bt module the com18 appears and so on. I do not care what XP device manager says, never checked that, everything is managed via BlueSoleil application/driver (a small BT icon in the taskbar). The bt modules need to be set to a specific baudrate, default was 9600 with mines. P.

I'm still not getting anywhere on this, but I very much appreciate all the details you have provided. Since my original post, I moved on to a BT shield which is master/slave so I don't believe that is the issue currently (but then again, it still could be). I will check the traces on the original module I was using to answer that question as suggested.

Currently, I'm trying to connect the itead module found here: http://iteadstudio.com/product/arduino-bluetooth-shield-upgrade-to-v2-2/
Here's the datasheet: http://iteadstudio.com/store/images/produce/Shield/BTshieldv2.2/BTShieldV2.2_DS.pdf

The data sheet it a bit hard to follow. I've tried using tera-term to connect to the module but am not having success there either. The problem connecting to the module via tera-term is the terminal is not echoing any of the keys pressed. Not sure what the deal is but I assume it is some configuration issue I haven't worked out yet. At any rate, any tips there would be appreciated.

As for the general bluetooth connectivity issue, it seems, based on what I understand from UK350, that my bluetooth module is connected but not "paired". I do have an entry in device manager for the module: Ports (COM & LPT) > Standard Serial Over Bluetooth Link (COM14). This coincides with port associated with the bluetooth module in control panel > devices & printers > bluetooth devices > itead.

The status of itead in control panel show it was last connected April 1, 2012 (today) but is not currently connected. And, the connection type is "authenticated." This seems to agree with UK350's assessment.

I have confirmed that no other services are using COM14 when attempting to run my Processing code, however, COM14 does not show in the Serial.write() output. I suspect this is normal for a device that is not paired.

So, I think at this point, I need to figure out how to connect to the module through the arduino using tera-term or PuTTy. Anyone have some experience with this that can offer some guidance?

Thanks again for all the support.

can it be that if both, dongle and bt module/shield are in master mode you cant then get paired them. What status led do on bt shield, did you get it stop blinking?

as mode change is easy to do with btshield try change it to slave and check if you can then pair it.

did you see blue bluetooth icon next to clock? or as you say device manager >bluetoot devices , can you see bt wizard, search or something like that behind it if you click it?

did you see blue bluetooth icon next to clock?
I do have the bluetooth icon in the system tray and when I click it, I see my ardiuno/bluetooth module connected - it's named "itead". I have removed it and rediscovered it to mimic what you do in your video, but this issue still exists for me. In the above thread entries, where I reference

What status led do on bt shield, did you get it stop blinking?
This is another area of uncertainty for me with respect to my particular bluetooth shield. Per it's datasheet:

"When power on and disconnect the port, states LED blinks 1time/2s ;
when the module connect and open the serial port, states LED blinks
2times/s."

I have gotten to the mode where it blinks twice per second. But that doesn't appear to be the same a being paired.

The datasheet also seems to imply the default setting is "slave mode" with the following:
"Default state:
Slave mode, pin code :1234, device name: H-C-2010-06-01 ,Baud
38400bits/s."

But I would like to confirm that by connecting with a terminal program - which I have been unsuccessful in to doing so far.

In my last post:
"In the above thread entries, where I reference"

Please disregard that incomplete thought...I meant to delete that text.

Thanks,
Mike

note!
4. Restore default
Command Respond Parameter
AT+ORGL OK -
Default state:
Slave mode, pin code :1234, device name: H-C-2010-06-01 ,Baud
38400bits/s.

as datasheet say you can use that command to be sure about mode, baud and pairing code.
you only have to select CMD with switch, power it up and make sketch that send AT+ORGL\r\n via arduino serail port with baudrate 38400.

if you then think you got it paired,(in my video i use hc04 module so it stop blinking when paired, for hc05 led blink time thing is right as it's described in datatsheet) make sketch that send some chars(just use loop to send something ) from arduino and try receive it via terminal on pc.

void loop()
{
Serial.write("test");

delay(500);
}

I got the same cheap BT module you are trying to use.
I get exactly the same behavior in XP, with 2 COM ports listed after Windows connects to the BT module. One port is "outgoing", the other one is "incoming". I think that Bluesoleil software (and others like it) just hides the complexity underneath, so users don't get confused when they see the multitude of ports.

So, at this point, one can either receive from Arduino through BT on the incoming port, or send out to Arduino through BT on the outgoing port. Trying to connect with a terminal app (I tried CoolTermWin) on the incoming results in an error. I could connect on the incoming port with the HyperTerminal though, which allowed me to receive messages from Arduino. This is the sketch I am running (using an ATmega with 2 serial ports, but should be easily adapted to Atmega328):

#include <WProgram.h>

void setup()
{
  Serial.begin(9600);

  // bluetooth serial:
  Serial1.begin(9600);
}


void loop()
{
  while (Serial1.available())
  {
    // get char from bluetooth;
    char inChar = (char) Serial1.read();

    // output to serial monitor;
    Serial.println(inChar);
  }

  Serial1.println("from Arduino");
  delay(2000);
}

I am able to receive, sometimes, in HyperTerminal, the repeated message "from Arduino". So the connection works, but it is not reliable. Even after a fresh re-connect (in Windows), it may still not work. I suspect it is the USB dongle. I only have one, so I have no way to test it.

I tried sending messages from CoolTerm, through the outgoing port, but never got that to work.
I will keep you posted when I figure it out.

I found this thread talking about the same issue:

The solution, from truly knowledgeable fellows, seems to be the installation of the Toshiba BT driver.

I would also suggest trying the BT connection from an Android device (I don't have one at the moment).

In case you still need help on this topic, this is how I solved it, successfully:

i am sending a character from my Android mobile using BLuetooth chat code (attached). I have programmed arduino as attached and is given below. I am sending a character from the chat application but else case in the code below executes every time i.e default pin13 gets on.

Please Please Can any one guide me guide me how to handle it????

byte data;
String message;

void setup ()
{
// Sets the serial communication:
Serial.begin (57600);

// Sets the pins of the LEDs as output:
pinMode (6, OUTPUT);
pinMode (7, OUTPUT);
pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
pinMode (10, OUTPUT);
}

void loop () {
int i=0;
// See if something has been received from the serial port:
if (Serial.available())
{
// Read the last byte received (value between 0 and 255)
data= Serial.read();

Serial.println (data);

if (data=='q') //q
{
digitalWrite(6, HIGH); // turn on LED 1 at pin6
message = "LED 1 On";
Serial.println (message);

}
if (data=='a') // a
{
digitalWrite(6, LOW); // off LED 1 at pin6
message = "LED 1 Off";
Serial.println (message);
}

if (data=='c') //c
{
digitalWrite(7, HIGH); //on LED 2
message = "LED 2 On";
Serial.println (message);
}

if (data=='d') //d
{
digitalWrite(7, LOW); // off LED 2
message = "LED 2 Off";
Serial.println (message);
}

if (data=='e') //e
{
digitalWrite(8, HIGH); //on LED 3
message = "LED 3 On";
Serial.println (message);
}

if (data=='f')// f
{
digitalWrite(8, LOW); //sets the LED 3
message = "LED 3 Off";
Serial.println (message);
}

if (data=='g') //g
{
digitalWrite(9, HIGH); //turn on LED 4
message = "LED 4 On";
Serial.println (message);
}

if (data=='h')//h
{
digitalWrite(9, LOW); //sets the LED 4
message = "LED 4 Off";
Serial.println (message);
}

if (data=='i') //i
{
digitalWrite(10, HIGH); //sets the LED 5
message = "L5 high";
Serial.println (message);
}

if (data=='j') //j
{
digitalWrite(10, LOW); //sets the LED 5
message = "LED 5 Off";
Serial.println (message);
}

if (data=='y') //y
{
digitalWrite(6, HIGH); // turn on ALL LEDs
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
message = "ALL LEDs ON";
Serial.println (message);
}

if (data=='z')//z
{
digitalWrite(6, LOW); //Turn off all LEDs
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
Serial.println ("ALL LEDs OFF");
}

else
{
digitalWrite(13, HIGH); //sets the LED 5
delay(3000); //3sec
digitalWrite(13, LOW);
delay(3000);
Serial.println (" else case executed ");

} ////end of else

// Send response
Serial.println (" end of loop "+message);

}
}

SHS Android code.rar (236 KB)

Arduino Code Led Control.txt (2.65 KB)

Hi Michael,

I found your post in my search for answers on the same problem. No joy at all on win 7. The BT connection always has 2 ports. Any attempt to use the serial monitor on the Arduino software causes a lock up. Putty sometimes opens the ports and sometimes doesnt. The red flashing light never goes out. Strangely now my BT dongle has stopped working and I dont get any ports at all.

On windows XP however a slightly different story. I plugged in the BT dongle (MSI) and allowed XP to download the three drivers from windows update. It had to be done manually one by one as initially 2 devices showed up as unknown or driver not installed correctly. Then when I searched for BT devices it found Linvor (JY-MCU name) and I was able to connect. I got one port outgoing and one port incoming but hey presto the red light on the BT module went continous! Putty was able to connect to the port but i couldn't send any characters from putty. When I tried the Arduino serial monitor it all locked up and the BT LED light went back to flashing. Now I cant reconnect.

Not much help but at least it connected once.

regards

Chris

Hi Michael,

I was able to connect again by removing the dongle, powering off the Arduino and starting from scratch. Windows XP reloads the drivers for the serial communication port and reinstalls the two ports. I also discovered that the red light only goes continuous when I open up the port using putty.

With the BT connected to my XP laptop I'm going to try see if i can get a message from my win 7 laptop through the USB to the bluetooth and then to the Putty sessions on the XP laptop

Chris

Hi Michael,

so I was able to upload a sketch which printed out through the USB serial monitor on the win7 machine and through the BT and putty on the Win XPmachine. The sketch is as follows (courtesy Hobby Components):

/* Include the software serial port library */
#include <SoftwareSerial.h>

/* DIO used to communicate with the Bluetooth module's TXD pin /
#define BT_SERIAL_TX_DIO 8
/
DIO used to communicate with the Bluetooth module's RXD pin */
#define BT_SERIAL_RX_DIO 9

/* Initialise the software serial port */
SoftwareSerial BluetoothSerial(BT_SERIAL_TX_DIO, BT_SERIAL_RX_DIO);

void setup()
{
/* Set the baud rate for the hardware serial port /
Serial.begin(9600);
/
Set the baud rate for the software serial port */
BluetoothSerial.begin(9600);

}

/* Main loop that will pass any data to and from the Bluetooth mode to the
host PC /
void loop()
{
Serial.println("Goodnight moon!");
/
If data is available from the Bluetooth module then pass it on to the
hardware serial port. */
if (BluetoothSerial.available())
Serial.write(BluetoothSerial.read());
BluetoothSerial.println("hello world");

/* If data is available from the hardware serial port then pass it on
to the Bluetooth module. */
if (Serial.available())
BluetoothSerial.write(Serial.read());
}

So under win xp it works after a fashion at least for output to a pc. For some reason I cant send anything to the Arduino from the XP laptop though the other port. This is still no good for my application. I however conclude that all the problems with Win 7 are to do with either my old BT dongle not being compatible or the drivers being no good.

I'm going to try another BT dongle and see if thats any better.

Chris

Hi Michael,

looks like the bluesoliel BT stack is the answer in Win7. See link. Hope my new dongle comes with it.

Chris

Finally got it to work with a new BT dongle and standard Win 7 drivers. It loads up 2 ports but only one actually works. Bluesoliel turned out to be a red herring. It comes with the cheap BT dongles but is disabled and tries to get you to pay $20 for valid licence.Its not necessary to get the dongle to work.

I had to play with the Putty terminal settings to see my input and the output from the Arduino on BT. You have to force local echo and carriage return. The Arduino software serial monitor doesn't seem to work with BT.
here is my code:

/* Include the software serial port library */
#include <SoftwareSerial.h>

/* DIO used to communicate with the Bluetooth module's TXD pin /
#define BT_SERIAL_TX_DIO 8
/
DIO used to communicate with the Bluetooth module's RXD pin */
#define BT_SERIAL_RX_DIO 9

/* Initialise the software serial port */
SoftwareSerial BluetoothSerial(BT_SERIAL_TX_DIO, BT_SERIAL_RX_DIO);

void setup()
{
/* Set the baud rate for the hardware serial port /
Serial.begin(9600);
/
Set the baud rate for the software serial port */
BluetoothSerial.begin(9600);

}

/* Main loop that will pass any data to and from the Bluetooth mode to the
host PC */
void loop()
{

/* If data is available from the Bluetooth module then pass it on to the
hardware serial port. */
if (BluetoothSerial.available())
Serial.write(BluetoothSerial.read());

/* If data is available from the hardware serial port then pass it on
to the Bluetooth module. */
if (Serial.available())
BluetoothSerial.write(Serial.read());
// If the character A is found on Bluetooth Serial port print a message back
if (BluetoothSerial.findUntil ("A","A"))
BluetoothSerial.println ("found A BT");
// If the character A is found on the Serial port print a message back
else if (Serial.findUntil ("A","A"))
Serial.println ("found A SE");
}

This code detects the character A and sends a reply to the same port it was received on. Its not 100% accurate on the BT port for some reason. I've got more work to do before this is going to be a reliable way to send and receive data.

Did anyone mention that the baud rate on the BT module has to be internally change, not just from the code?

it is an AT command, I have the same BT module.

Oh hey Mike, its HazardOfExistance from youtube, your still having problems? I thought I helped you with that already.
also processing doesn't like that type of BT module. thought I told you that too?

Hi Mike,

I’ve followed your steps, made the same mistakes, found the same workarounds, regarding Arduino bluetooth connection to Win7. In my case, I am using a HC-05 modem on this board : http://www.ebay.com/itm/HC-05-Bluetooth-Transceiver-Host-Slave-Master-Module-Wireless-Serial-6pin-/221158958927.

I’ve had the same issues as you about understanding how to create COM ports, why you get 2 COM ports instead of one, how to get them paired… and I had the same success eventually, using the following flow

  • add the BT modem to the computer WITHOUT code.
    => two ports get created (say COM5 with the “DEV” indication, and COM6)
  • launch a terminal (I use Tera Term) – connect to COM5 – code is asked, input 1234
    => LED stop blinking, indicating pairing
  • using terminal, I am able to see both incoming and outgoing flow (eg, the code below allows me to read numbers, reset them, and turn on/off the led 13)
    => I confirm that my BT dongle, my BT modem, and Arduino sketch, are working

Where things break down

  • neither Processing nor Arduino IDE “see” COM5, only COM6. Processing, through Serial.list(), Arduino, in Tools/Ports
  • Processing can be forced to connect to COM5 with new Serial(this, “COM5?, 9600), but it does not lead to windows asking for a bluetooth code, and the pairing of the modem. As a consequence, the LED keeps on blinking, and no data is exchanged.

I think this is where you were on April 6 2012, per your blog post. I understand from your following blog psots that you did find a solution. Any ideas?

—- example Arduino code —
/***********************
Bluetooth test program
***********************/
int counter = 0;
int incomingByte;
int pinLED = 13;
boolean allumeLED = true;

void setup() {
Serial.begin(9600);
pinMode(pinLED, OUTPUT);
}

void loop() {
// see if there’s incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it’s a capital R, reset the counter
if (incomingByte == ‘R’) {
Serial.println(“RESET”);
counter=0;
}
else if (incomingByte == ’1?) {
allumeLED = true;
}
else if (incomingByte == ’0?) {
allumeLED = false;
}
}
Serial.println(counter);
digitalWrite(pinLED, allumeLED);
counter++;
delay(250);
}

—- example Processing code —

import processing.serial.*;

Serial myPort;
String data;

void setup(){
size(800, 200);
background(255);

// List all the available serial ports:
println(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, “COM5?, 9600);
myPort.clear();
myPort.bufferUntil(‘\n’); //read one line at a time

}

void draw(){
background(255);
fill(0);

if (data != null){
text(data, 10, 10);
}
else{
text(“no data”, 10, 10);
}
}

void serialEvent(Serial port){
data = port.readString(); //one line has been buffered
}

In case anybody is still on this topic, I managed to get it to work 5min after my previous post, thanks to a suggestion on Processing forum. Using a virtual serial port emulator (http://www.addictivetips.com/windows-tips/vspe-download-free-virtual-serial-ports-emulator/) you can copy the stream from one port to another using a "splitter".

From my example above, I would take COM5 as input, create a COM2 copy, and write COM2 in the Processing sketch. I don't know why, but it works.

cheers !