I connect an HC-05 module to an Arduino nano with CH341 serial chip (voltage divider on RX pin). I am trying to make a bridge for a test, i.e. serial in, echo local and echo to Bluetooth and vice versa. I modified the echo code from here.
int incomingByte = 0; // for incoming serial data
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup() {
BTSerial.begin(38400); // opens serial port, sets data rate to 9600 bps
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print((char)incomingByte);
BTSerial.print((char)incomingByte);
}
if (BTSerial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print((char)incomingByte);
BTSerial.print((char)incomingByte);
}
under OSX I open two terminals. In the first terminal using screen /dev/cu.wchusbserial1410 9600
I see local echo as desired. But on the second terminal using screen /dev/cu.HC-05-SPPDev 38400
I see nothing after pairing. The only effect is that by typing the latter command, the module stops blinking rapidly and blinks only two times with long pause in between. Exiting the screen
environment, then again blinks rapidly.
Appreciate any hints what I am doing wrong...
=====
intermediate success but not quite there yet:
I simplified the code and corrected the wrong connection. Local echo on serial works as usual, even between the two, characters are being transferred, but they are black question marks instead of why I typed.
/*
* echo script
*/
byte incomingByte;
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(3, 2); // RX | TX
void setup() {
BTSerial.begin(9600);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
incomingByte = Serial.read();
Serial.print((char)incomingByte);
BTSerial.print((char)incomingByte);
}
if (BTSerial.available()) {
incomingByte = BTSerial.read();
Serial.print((char)incomingByte);
BTSerial.print((char)incomingByte);
}
}
Any ideas?
========
Edited the Buadrate to 9600. Now everything works.