Hi all
I'm trying to receive data from an Arduino with an HC-06 module but somehow cannot get the connection and data flow established.
I'm using an Arduino Uno R3 with the HC-06 as follows:
HC-06 Module with:
VCC -> Arduino 5V
GND -> Arduino GND
TXD -> Pin 8
RXD -> Pin 9 (reduced to 3V with a voltage divider)
The following code should just send back some timestamp to validate the data flow:
#include <SoftwareSerial.h>
//HC-06 TXD -> Arduino Pin 8
//HC-06 RXD -> Arduino Pin 9
SoftwareSerial btSerial(9, 8); // New RX, TX pins
const long interval = 1000; // Interval for sending the time (in milliseconds)
unsigned long previousMillis = 0; // Variable to store the last time the message was sent
void setup(){
btSerial.begin(9600);
// Send an initial message
btSerial.println("Arduino is ready. Sending time since start...");
}
void loop() {
// Get the current time in milliseconds since the Arduino started
unsigned long currentMillis = millis();
// Check if the interval has passed
if (currentMillis - previousMillis >= interval) {
// Save the last time the message was sent
previousMillis = currentMillis;
// Send the current time in milliseconds through the serial connection
Serial.print("Time since start: ");
Serial.print(currentMillis);
Serial.println(" ms");
}
}
Connecting with my Mac, the module appears in the bluetooth list and it appears to pair. In terminal I see the device with ls /dev/tty.* appear. However:
- The LED continues blinking (I think it should turn red when paired?)
- Trying to connect with terminal using "screen /dev/tty.HC-06 9600" returns "resource is busy".
Any ideas?