Hi
I just mannaged to get 2 bluetooth modules to communicate. it has been really tricky to get it running due to defective firmware in one module. I guess I have spend 25+ hours figuring out what was wrong...
Now I can transmitt data from a arduino that reads a adc and via bluetooth to a reciever arduino. Just what I needed.
But the connection can sometimes be tricky to get running. It appears that there is a timing issue and if the recieving arduino starts while the sender is transmitting it newer connects like it was intended.
I quess that some kind of end of transmition would be the solution but I cannot get it to work.
Even the samples for serial in the arduino IDE does not help me.
My code is:
int a, b, c;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
delay(100); // allowing my bluetooth module to boot up correctly. Might be a to long break, but it works for now.
Serial.println("The serial port is up ");
Serial.println("and running ");
Serial.println("");
}
void loop() {
while (Serial.available() > 0 )
{
//Serial.println("*** RECIEVING DATA ***");
a = Serial.parseInt(); // reads the ints from serial to the a,b and c ints.
b = Serial.parseInt();
c = Serial.parseInt();
Serial.println(a); // send the recieved data to serial so I can see if it looks right
Serial.println(b);
Serial.println(c);
Visual(); // to turn a led if b>20
if (b > 20)
{
Serial.println("*** ALARM ");// the b parameter is > 20
Serial.println(" END OF DATA ");
Serial.println();
}
else {
Serial.println(" END OF DATA ***");
Serial.println();
}
//Serial.flush();
}
}
void Visual() // turns a led on if the data in b is more than 20.
{
if (b > 20) {
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
}
/*
Serial Monitor
The sending Arduino is sending a series of 3 integers and a Serial.println
It looks like
01,0,3
The first int is a counter that counts up for each transmition.
The next int is a reading from a sensor. This is really what Im after.
The last int is just rubbish nmbers, but I might use it later for a checksum or similar error detection purpose to get data validation a cheap way.
This is a sample of two reaadings in my serial monitor.
52 // the first int who is just a counter
293 // the first int who is just a counter
198
*** ALARM ***
*** END OF DATA ***
53
0
0
*** END OF DATA ***
*/