I'm trying to get my bluetooth module into command mode. I have pin 0(RX) on the Uno connected to the UART_TX pin on the bluetooth module, and pin 1(TX) on the Uno connected to the UART_RX pin on the bluetooth module.
Heres the sketch thats running on the Uno.
int incomingByte = 0; // for incoming serial data
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
Serial.flush();
//enter command mode
Serial.println("$$$");
}
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("I received: ");
Serial.println(incomingByte, DEC);
}
}
This is what I see on the Serial Monitor
$$$
I expected to see
$$$
I received: C
I received: M
I received: D
What am I doing wrong? Or if its not supposed to do what I expected, what am I not understanding correctly?
1 Answer 1
I think the problem you're having is that you can't both talk to a device on the UART and talk to a terminal (your computer) at the same time using the same pins (0 and 1) of the Arduino. If you want to talk to your computer as well as a device you have to use a SoftSerial library (or NewSoftSerial) and wire the device to use different pins rather than the hardware UART...
(削除) That being said, it seems plausible that the bluetooth module is prompting your for a command with the message "CMD". (削除ここまで) (misread question, this was what you expected, not what actually happened)
-
\$\begingroup\$ Ah, I think I remember running across someone mentioning that elsewhere, \$\endgroup\$antony.trupe– antony.trupe2011年04月10日 15:39:08 +00:00Commented Apr 10, 2011 at 15:39