Hi,
I'm trying to get my bluetooth connection working. I made a class called bluetooth for setting up the bluetooth connection and sending a String. The connection uses a Software Serial. Here's the code:
Arduino Sketch:
#include <SoftwareSerial.h>
#include "bluetooth.h"
SoftwareSerial blue_ss(2,3); //Rx_Pin = 2 Tx_Pin = 3
BLUETOOTH bt(&blue_ss);
void setup() {
Serial.begin(9600); //Serial Port via USB connection
}
void loop() {
Serial.println("test"); //send via Hardware Serial Port (USB connection)
bt.senden("test"); //Send via Software Serial Port (Bluetooth)
delay(500);
}
bluetooth.h:
#ifndef BLUETOOTH_H
#define BLUETOOTH_H
#include <Arduino.h>
#include <SoftwareSerial.h>
class BLUETOOTH
{
private:
SoftwareSerial *bt_serial;
public:
BLUETOOTH(SoftwareSerial *ss);
~BLUETOOTH();
void senden(String);
};
#endif
bluetooth.cpp:
#include "bluetooth.h"
BLUETOOTH::BLUETOOTH(SoftwareSerial *_ss) //Constructor, setting up the connection
{
bt_serial = _ss;
this->bt_serial->begin(115200); // The Bluetooth Mate defaults to 115200bps
this->bt_serial->print("$"); // Print three times individually
this->bt_serial->print("$");
this->bt_serial->print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
this->bt_serial->println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
this->bt_serial->begin(9600); // Start bluetooth serial at 9600
}
BLUETOOTH::~BLUETOOTH(){} //Destructor
void BLUETOOTH::senden(String s) //send String
{
this->bt_serial->print(s);
}
Additional to the bluetooth connection i made a serial connection over USB for testing.
I can compile the whole code without errors. My Problem now is, that I don't receive anything over the bluetooth connection or the serial connection via usb. I think that maybe the loop in the sketch isn't executed correctly. I tested the bluetooth connection in one sketch without header and source files and it worked. So maybe I made a mistake with the files I include?!
Hope that someone can help me.
Thank you,
pat_