Click here to Skip to main content
15,884,794 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello. This is my scenario, i have an arduino uno and a hc-05 bluetooth module.
i use software serial for hc-05, this is my arduino code:
(from this link : http://stackoverflow.com/questions/18376468/arduino-using-serial-and-software-serial-with-bluetooth-module[^])

#include <SoftwareSerial.h>

#define rxPin 8
#define txPin 7

SoftwareSerial mySerial(rxPin, txPin); // RX, TX
char myChar ; 

void setup() {
  Serial.begin(9600);   
  Serial.println("Goodnight moon!");

  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop(){
  while(mySerial.available()){
    myChar = mySerial.read();
    Serial.print(myChar);
    mySerial.print(myChar);
  }

  while(Serial.available()){
   myChar = Serial.read();
   mySerial.print(myChar);
  }
}


And i downloaded the app2device sample from msdn (link : https://code.msdn.microsoft.com/Bluetooth-app-to-device-644870ba[^])

I can connect my hc-05 bluetooth module, i see connected message box with host name. And when i send data to arduino hc-05, arduino receives it. I send the data with this method (link A Simple Bluetooth Application[^]) :

C#
DataWriter dataWriter = new DataWriter(_socket.OutputStream);
               // send the message length first
               string message = "selammm";
               dataWriter.WriteInt32(message.Length);
               await dataWriter.StoreAsync();
               //send the actual message
               dataWriter.WriteString(message);
               await dataWriter.StoreAsync();


There is no problem here. But arduino should send this message back from bluetooth,
with SoftwareSerial with
mySerial.print(myChar);


But with this code from last codeproject link 'A Simple Bluetooth Application', windows phone does not receive anything.

C#
DataReader dataReader = new DataReader(socket.InputStream);
await dataReader.LoadAsync(4);// get the size of message
uint messageLen =(uint)dataReader.ReadInt32();
await dataReader.loadAsync(messageLen)//send the message
String Message = dataReader.ReadString(messageLen); 


i set a breakpoint to datareader, and i see it stacked at
C#
await dataReader.LoadAsync(4);
. no errors, but no messages.

You can see there is nothing special from me with this codes, i am a beginner, and from samples i want to make my own app (bluetooth connection between arduino and windows phone ), but i can't manage to get this working...

arduino wiring is here:

5v to hc-05 vcc
gnd to gnd
hc-05 tx to pin 8
hc-05 rx with 1k resistor to pin7 and 2k resistor to gnd

i also copied this from a site http://www.instructables.com/id/Cheap-2-Way-Bluetooth-Connection-Between-Arduino-a/[^]

my arduino wiring is this except the rx,tx. i use 7,8 instead of 0,1 and software serial.

I will be really happy if someone helps me on this.
Thanks from now.
Posted
Updated 15-Aug-15 5:41am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900