I am trying out a HC-05 Bluetooth device with the code below to see if I can test the serial communication.
When writing on the PC serial monitor the data is transferred to the android tablet terminal all ok (running a Bluetooth terminal app).
But when I write in the tablet terminal and click on send nothing appears in the PC terminal.
am I missing something
The cables are connected correct TX from HC-05 to Arduino 15 and RX from HC-05 to Arduino 14
#include <SoftwareSerial.h>
SoftwareSerial BTserial(15, 14); //RX / TX
void setup() {
Serial.begin(9600);
Serial.println("Enter AT commands:");
BTserial.begin(9600);
}
void loop() {
// Read from BT and send to arduino serial monitor
if (BTserial.available())
{
Serial.println(BTserial.read());
Serial.println("test");
}
// read from arduino serial and send to BT
if (Serial.available())
{
BTserial.println(Serial.read());
}
}
steve8428:
am I missing something
#include <SoftwareSerial.h>
void setup() {
Serial.begin(9600);
Serial.println("Enter AT commands:");
}
Well, the intention is unclear. Are you really trying to send an AT command, or are you just trying to talk?
You might find the following background notes useful.
http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino
Arr yes forget to take the At serial part out. originally was following an example for AT communication which also checked communication between the device and PC.
In doing this I found the communication from tablet to PC is not working for some reason. I will have a look over your links thank you
Also to add if this helps
I can turn on an LED by sending a character from app inventor but only if I am using the main TX and RX pins on the Arduino (1 and 0) . This does not work with the SoftwareSerial changing the pins to 14 and 15 so I think this is where my problem is.
int led = 13;
char x;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
x = Serial.read();
}
delay(100);
if (x == 'h'){
digitalWrite (led, HIGH);
}
if (x == 'w'){
digitalWrite (led, LOW);
}
}
got it working using AltSoftSerial
#include <AltSoftSerial.h>
AltSoftSerial BTserial; //RX / TX
void setup() {
Serial.begin(9600);
Serial.println("Enter AT commands:");
BTserial.begin(9600);
}
void loop() {
// Read from BT and send to arduino serial monitor
if (BTserial.available())
{
Serial.println(BTserial.read());
Serial.println("test");
}
// read from arduino serial and send to BT
if (Serial.available())
{
BTserial.println(Serial.read());
}
}