What I want is using visual studio to read and write to arduino UNO using a bluetooth device HC-05. In the previous step, I am able to communicate using visual studio c++ and Arduino directly through usb port. The code I am using is basically same as arduino and visual studio c++, 2 way serial communication. In arduino, I have command as:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0) {
char c = Serial.read();
if (c == '1')
Serial.write("FORW");
else if (c == '2')
Serial.write("LEFT");
else if (c == '3')
Serial.write("RIGTH");
else if (c == '4')
Serial.write("BACK");
else if (c == '5')
Serial.write("STOP");
else
Serial.write("Invalid");
}
and my/output is (using arduino usb directly):
Connection established!!!
Enter your command: 1
arduino: FORW
Enter your command: 2
arduino: LEFT
Enter your command: 3
arduino: RIGTH
Enter your command: 6
arduino: Invalid
Enter your command:
When I added a bluetooth Module HC-05 with it. Using serial monitor can get same output, but when I used visual studio, the first input never gives back a output, while for the following output, it always gives a previous output not a current one, as following:
Connection established!!!
Enter your command: 1
arduino:
Enter your command: 2
arduino: FORW
Enter your command: 1
arduino: LEFT
Enter your command: 4
arduino: FORW
Enter your command: 6
arduino: BACK
Enter your command: 2
arduino: Invalid
Enter your command:
I don't know if following steps may give error:
- bluetooth is supplied with 5v
- I cross connected bluetooth TX RX with Arduino Uno
- bluetooth HC-05 is in default mode, I didn't change anything about it.
- When bluetooth is connected with PC, it shows two ports: COM4 'DEV-B' & COM5,so I just changed the code in visual studio to make it connect to COM4.
- Bound rate is set to be 9600 on Arduino also indicated in visual studio.
So any idea why this would happen?