Arduino Uno - 2 way bluetooth communication
We successfully got two Arduino Uno's to communicate with eachother using the RX/TX pins and wires.
We used the serial monitor to trace two way communication using this code:
int incomingByte = 0; // for incoming serial data
int i = 0;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
// Try to change this for quicker speed.
}
void loop() {
Serial.print(i);
Serial.println(" * ");
i++;
// 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);
}
}
Now we would like to use the HC-05 Bluetooth modules (6 pin) to have two communication.
We have searched for a good guild and have found bits a pieces here and there to help with this project.
Could someone please throw me a bone on a good guide to achieve this objective.
This is the code we are using to test two way. We are not able to trace two way communication.
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>
SoftwareSerial mySerial(8, 9); //RX,TX
const int ledPin = 13; // the pin that the LED is attached to
byte iB; // a variable to read incoming serial data into
int count = 0;
void setup()
{
// initialize serial communication:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
mySerial.begin(9600);
Serial.print("set up complete...");
// make sure that the default chip select pin is set to
}
void loop()
{
count++;
mySerial.listen();
mySerial.println(" * * * ");
Serial.print(" * * * ");
if (mySerial.available() > 0) {
// read the oldest byte in the serial buffer:
iB = mySerial.read();
Serial.println(iB);
Serial.print("+");
if (count % 16)Serial.println();
analogWrite(ledPin, iB);
delay (100);
}
}