A Simple arduino library for the WT12 bluetooth module by Bluegiga
To generate the documentation
Run the .bat file provided to generate a markdown file with the documentation
- Connect TX/RX and VCC/GND from the module to the Arduino
- The module is configured so that only one connection is allowed. Unexpected disconnections are not handled (MUX mode should be used instead).
- An alternative comprehensive library for WT modules Link
Members | Descriptions |
---|---|
define WT12DEBUG |
Set to true if you want the library to output debug information on Serial 0 |
define WT12_MAX_BUFFER_SIZE |
Maximum size in bytes of the internal buffer used to receive serial information |
class WT12Bluetooth |
Arduino library for WT12 Bluetooth module |
define
WT12DEBUG
Set to true if you want the library to output debug information on Serial 0
define
WT12_MAX_BUFFER_SIZE
Maximum size in bytes of the internal buffer used to receive serial information
Arduino library for WT12 Bluetooth module
Members | Descriptions |
---|---|
public WT12Bluetooth (HardwareSerial * serial,unsigned long baudrate) |
Constructor. |
public bool on () |
Turns the module on. |
public bool off () |
Turns the module off. |
public bool reset () |
Resets the module. |
public bool isConnected () |
True if in data mode (a connection is established) |
public bool send (const char data[],int dataSize) |
Sends data using the current active connection. |
public bool sendAsString (int data) |
Sends a single value (as String) using the current active connection. |
public bool sendString (const char data[]) |
Sends a string using the current active connection. |
public bool connect (const char btMacAddr[]) |
Opens a connection to the specified bluetooth mac addr. |
public bool waitForConnection (unsigned long timeoutMs) |
Waits for a connection to be initiated from a remote module. |
public int receiveData (char buffer[],int maxBytes) |
Receives data from the active connection. |
public bool closeConnection () |
Closes the current connection. |
public bool setName (const char name[]) |
Sets the name of the module. |
public
WT12Bluetooth
(HardwareSerial * serial,unsigned long baudrate)
Constructor.
Creates an instance of the library but does not actually opens a connection with the module on() must be called before using the instance
-
serial.
Reference to the serial port where the module has been connected -
baudrate.
(Optional) Serial baud rate. 115200 if not specified.
public bool
on
()
Turns the module on.
It opens the serial connection to the module, it sets some configuration parameters and resets it
public bool
off
()
Turns the module off.
Closes the serial connection to the module
true if the operation went well, false otherwise
public bool
reset
()
Resets the module.
true if the operation went well, false otherwise
public bool
isConnected
()
True if in data mode (a connection is established)
true if the operation went well, false otherwise
public bool
send
(const char data[],int dataSize)
Sends data using the current active connection.
-
data.
Array of bytes to be sent -
dataSize.
Size of the data to be sent in bytes
true if the operation went well (a connection is active), false otherwise
public bool
sendAsString
(int data)
Sends a single value (as String) using the current active connection.
true if the operation went well (a connection is active), false otherwise
public bool
sendString
(const char data[])
Sends a string using the current active connection.
data.
Data to be sent. All the data up to the \0 character will be sent (excluding \0)
true if the operation went well (a connection is active), false otherwise
public bool
connect
(const char btMacAddr[])
Opens a connection to the specified bluetooth mac addr.
btMacAddr.
String with the mac address of the destination module. e.g. "BB:D3:8C:70:E0:DA" or "BBD38C70E0DA"
true if the operation went well, false otherwise
public bool
waitForConnection
(unsigned long timeoutMs)
Waits for a connection to be initiated from a remote module.
If a connection is already active this method does nothing
timeoutMs.
If a connection is not activated withtin the specified timeout in ms the method returns
true if the operation went well, false if timeout
public int
receiveData
(char buffer[],int maxBytes)
Receives data from the active connection.
If a connection is not active this method does nothing. This method does not block. It only returns the data that is available in the module at that moment.
-
buffer.
Buffer where the data will be received -
maxBytes.
Maximum number of bytes to be received
the number of bytes that have been received
public bool
closeConnection
()
Closes the current connection.
If there is no active connection, the method does nothing
true if the operation went well, false otherwise
public bool
setName
(const char name[])
Sets the name of the module.
A maximum length of 16 bytes is allowed
true if the operation went well, false otherwise