Skip to content

A simple bluetooth library for Arduino (wt12 module by Bluegiga)

License

Notifications You must be signed in to change notification settings

HF0/bluetooth-wt12-for-arduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bluetooth WT12 library for Arduino

WT12 module

A Simple arduino library for the WT12 bluetooth module by Bluegiga

Dependencies

To generate the documentation

  • doxygen Link
  • moxygen. Link
    • (npm install moxygen -g to install it)

Run the .bat file provided to generate a markdown file with the documentation

Connection

  • Connect TX/RX and VCC/GND from the module to the Arduino

Limitations

  • The module is configured so that only one connection is allowed. Unexpected disconnections are not handled (MUX mode should be used instead).

Links

  • An alternative comprehensive library for WT modules Link

Documentation

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

Members

define WT12DEBUG

Set to true if you want the library to output debug information on Serial 0

Maximum size in bytes of the internal buffer used to receive serial information

class WT12Bluetooth

Arduino library for WT12 Bluetooth module

Summary

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.

Members

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

Parameters

  • 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

Returns

true if the operation went well, false otherwise

public bool reset()

Resets the module.

Returns

true if the operation went well, false otherwise

public bool isConnected()

True if in data mode (a connection is established)

Returns

true if the operation went well, false otherwise

public bool send(const char data[],int dataSize)

Sends data using the current active connection.

Parameters

  • data. Array of bytes to be sent

  • dataSize. Size of the data to be sent in bytes

Returns

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.

Returns

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.

Parameters

  • data. Data to be sent. All the data up to the \0 character will be sent (excluding \0)

Returns

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.

Parameters

  • btMacAddr. String with the mac address of the destination module. e.g. "BB:D3:8C:70:E0:DA" or "BBD38C70E0DA"

Returns

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

Parameters

  • timeoutMs. If a connection is not activated withtin the specified timeout in ms the method returns

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.

Parameters

  • buffer. Buffer where the data will be received

  • maxBytes. Maximum number of bytes to be received

Returns

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

Returns

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

Returns

true if the operation went well, false otherwise

About

A simple bluetooth library for Arduino (wt12 module by Bluegiga)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published