cannot send data from arduino with HC-05 bluetooth board

I installed an HC-05 on an Arduino UNO and paired it to a windows PC. The PC sees 2 com ports for the HC-05 (incoming and outgoing). I cannot transfer data using an HC-05 Library and its arduino test sketches: http://rockingdlabs.dunmire.org/exercises-experiments/hc05-bluetooth

I cannot upload sketches from the 1.05 IDE to the arduino using the com port that is assigned to the HC-05. How can I test the connection and send data to verify the link is working? Later I want to transfer commands from my PC wirelessly.

You might find this simple approach useful. I wrote it for Android but a lot of it applies to a PC too. The biggest problem with using the HC-05 is in realising how easy it is. I would be glad of your comment.

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

thanks, this worked well, but I cannot find sketches to send control commands or upload sketches to the arduino from a PC via bluetooth without any usb cables. none of the android apps to send controls work. Any hints would be appreciated.

Hummm. I'm afraid I can't comment much on this. I am just a humble datalogger myself........

I'm sure I have seen some Android controller apps but I don't know anything about them. I presume they are really just an interface and the Arduino code reads like "If serial.read = k then light LED"

I don't think it is possible to upload sketches via bluetooth, principally, I guess, because a programme has to be running in order to do that. It may be possible with additional hardware and a different IDE, but that is a whole new world, and it might be better to question why you would want to do this before going there. Having said that, there can be a fine line between a programme loaded via bluetooth, and a subroutine controlled by bluetooth.

I have an UNO R3 with an HC-05 bluetooth module. I am able to communicate text from the android via Bluetooth running a terminal emulator program. I am using the attached nice sketch supplied by Nick Pyner.

Now I am trying to trigger different arduino digital out pins based on the particular character sent from the droid. I tried monitoring using Serial.read() but no matter what character I send from the android the Arduino console shows the same special character when I serial.println the serial.read().

any suggestions?

child_guide.ino (420 Bytes)

The code I posted serves no more than to prove that your equipment is functioning correctly. In order to actually do something, Arduino needs to act on a signal, the serial read, rather than merely regurgitate it.

As I said, the input could be tested with if statements, but I imagine the method "switch/case" is a better way, whereby Arduino acts according to a number received from Android. I'm not sure you should be doing this anyway. There are several Android apps for controlling Arduino via bluetooth in the Google Store, and I'm sure they all include the arduino code

So far only your code has worked with my setup… None of the numerous Google store apps for arduino/ bluetooth work. I have tried them (along with their arduino code) and get varying, but unsatisfactory results.

I think I can do what I need with your code if I just use only a single instance of serial.read() for data, not for repeating the string sent by android.

OK, I have not tried any of them and that is pretty disappointing to hear, but now you are one step ahead of me.

Were you able to establish connection with the apps? If so, I can only assume the problem is just some trivial procedural thing and easily fixed. Otherwise there would surely be bad reviews!

I'm afraid I am only involved with data logging and have never so much as flashed a LED myself but, while I'm sure my sketch could be enlarged upon with conditional statements as described, I now believe the effort is better devoted to getting the store-bought stuff to run since you then get the Android code for free.

On reflection, I guess if you just need an on/off trigger, a slight modification of the code will indeed suffice. In this instance, you just want action on receipt of a signal, without needing to interpret anything.

Try the following. It compiles OK but I'm not able to use it at the moment, so I'm guessing.........

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

void setup()
{
    pinMode(led, OUTPUT);    // initialize the digital pin as an output.
    digitalWrite(led, LOW);    // ensure the LED is off by making the voltage LOW
    Serial.begin(9600);
    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("");
  Serial.println("I heard you say:");
  while(Serial.available()>0)
  {
    Serial.write(Serial.read());// note it is Serial.WRITE
    if (led == LOW)
    {
      digitalWrite(led, HIGH);
      Serial.print(" and LED is ON"); 
    }
    else
    {
      digitalWrite(led, LOW); 
      Serial.print(" and LED is OFF");
    }   
  }
  Serial.println("");
}

hib1:
I installed an HC-05 on an Arduino UNO and paired it to a windows PC. The PC sees 2 com ports for the HC-05 (incoming and outgoing). I cannot transfer data using an HC-05 Library and its arduino test sketches:
http://rockingdlabs.dunmire.org/exercises-experiments/hc05-bluetooth

I cannot upload sketches from the 1.05 IDE to the arduino using the com port that is assigned to the HC-05.
How can I test the connection and send data to verify the link is working? Later I want to transfer commands from my PC wirelessly.

You can’t send sketches to the Arduino via Bluetooth. To test the HC-05 connection, you can use the sketch below. To connect to the HC-05 use a terminal program on your PC, set it to 9600 baud, No parity, 1-stop bit. Connect to the HC-05 (whatever the paired name is). As you type in the terminal, the characters will echo back to you. If you type and press enter, it should echo the whole string back to you (up to 19 chars).

Mel

// arduino>>bluetooth
// D3   >>>  Tx
// D2   >>>  Rx

#include <SoftwareSerial.h>// import the serial library

SoftwareSerial serialBT(2, 3); // RX, TX
char bufferBT[20];// this is the array all incoming data is stored in
int posBuffer=0;// this is the position within the array to store the data
int bufferMax = sizeof(bufferBT)-1;// array goes from 0-whatever, minus 1 because zero is a number
const char term ='\r';// \n = LINE FEED or newline, \r = CARRIAGE RETURN
const char backSpace = 0x08;
boolean echoBT=true;// want to echo back to the host term what was received?

void setup() {
  serialBT.begin(9600);
  serialBT.println("Welcome to Buffy BlueTooth");
}

void loop() {
  if (serialBT.available()){
    char btData=serialBT.read();// read a byte from the bluetooth serial
    bufferBT[posBuffer]=btData;// store the data in the array
    if (echoBT == true) serialBT.print(btData);
    switch (btData) {
    case term:// look for the terminating character
      showBuffer();// go send back the string we received
      posBuffer = 0;// reset the array pointer for new data coming in
      break;
    case backSpace:// if we get a backspace character, we need to backup in the array pointer (kind of an overwrite)
      posBuffer --;// backup the buffer pointer, so next character overwrites this one
      if (posBuffer < 0) posBuffer=0;// limit, keep the pointer within the buffer limit
      break;
    default:
      posBuffer ++;// increment the storeage pointer to the next array position
      break;
    }
    if (posBuffer > bufferMax ) posBuffer=0;// if we try to increment beyond the size of the buffer, wrap around
  }
}
void showBuffer() {
  serialBT.println("This is the info received:");
  int i=0;// this is the pointer into the BT array
  while (bufferBT[i] != term) {// we loop through the array sending data until we find the term character
    serialBT.print(bufferBT[i]);
    i++;// point to the next array position
  }
  serialBT.println();// just sends a lf to the terminal to scroll down to new line
}

Thanks for your help. I got it working by doing this simple but barely mentioned step.

DISCONNECT RX when uploading a sketch if you have any external circuit connected to pins D0 and D1 .

hib1: Thanks for your help. I got it working by doing this simple but barely mentioned step.

DISCONNECT RX when uploading a sketch if you have any external circuit connected to pins D0 and D1 .

I've never hooked any Bluetooth up to D0 or D1 because those are RX/TX that the USB uses and you can't have them working at the same time. Thus, I've always used SoftwareSerial to use two other pins for RX/TX dedication to Bluetooth so that I can have Bluetooth and USB working at the same time.

My understanding of the upload process: what prevents the Bluetooth from being used to upload sketches is that the modules can’t be used as-is to reset the Arduino which will start the bootloader and the upload process after that. Maybe you can manually press the reset button to do it as I've seen some do with Arduino MINI's.

The only other way I've seen is to use the Watchdog timer to trigger a reset and start the boot loader.

I did try your suggestion of disconnecting the RX, it did nothing (I even tried timing the pressing of the reset button). You've got better magic than I do...:)

Mel

hib1: DISCONNECT RX when uploading a sketch if you have any external circuit connected to pins D0 and D1 .

Glad to see you got it working OK. It didn't occur to me that you had this problem. It is mentioned in the link I posted above. I will make it clearer on the strength of this!