Hi,
first of all thanks for lot’s of good information on this forum. I’ve been reading a lot more than writing. Hopfully i can contribute more in the future!
I am attempting to use a HC-05 bluetooth module with my spark. For testing purposes i am using a my Android phone and a small application developed in MIT App Inventor 2. I have verified that the HC-05 module is working by connecting it using loopback (direct connection between the TX and RX on the bluetooth module) and the data are sent back to my phone.
However, when I try to establish serial connection with the bluetooth module, the serial connection is not established.
The module is connected as @timb has explained in this thread: https://community.spark.io/t/spark-core-bluetooth-serial/3294/2
My code is shown below. When i start the code the blue led stays solid. I have tried connecting to the HC-05 module both after and before resetting the spark core.
Any help would be greatly appreciated!
CODE:
char val; // variable to receive data from the serial port
int ledpin = D7; // LED connected to pin 48 (on-board LED)
void setup() {
pinMode(ledpin,OUTPUT); // Turn on the D7 led so we know it’s time
digitalWrite(ledpin,HIGH); // to open the Serial Terminal.
Serial.begin(9600);
while(!Serial.available()); // Wait here until the user presses ENTER in the Serial Terminal
digitalWrite(ledpin,LOW); // Turn off the D7 led … your serial is serializing!
Serial.println("Spark Core serial initialized ");
}
void loop() {
if( Serial.available() ) // if data is available to read
{
val = Serial.read(); // read it and store it in 'val'
Serial.print("Received: "); // report back
Serial.println(val);
delay(100); // 10 blinks a sec indicates serial is available
digitalWrite(ledpin,HIGH);
delay(250);
digitalWrite(ledpin,LOW);
}
else
{
digitalWrite(ledpin,HIGH); // 3 blinks a sec indicates serial is not available
delay(250);
digitalWrite(ledpin,LOW);
delay(950);
Serial.begin(9600);
}
}