Pages: 1 2 [3]   Go Down
Author Topic: Arduino Uno + Bluetooth Connectivity Issue  (Read 18479 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.41 KB - downloaded 24 times.)
* Arduino Code Led Control.txt (2.65 KB - downloaded 22 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Michael,

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

 
http://club.dx.com/forums/forums.dx/threadid.1181758
Chris

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 86
Posts: 3459
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: November 16, 2012, 04:30:13 pm by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 !
Logged

Pages: 1 2 [3]   Go Up
Jump to: