RN41/42 control lib. RN41/42 is bluetooth module with class 1 or 2.

Dependencies:   StrLib myTimer RingBuffer

Dependents:   Theremin

Embed: (wiki syntax)

« Back to documentation index

RN41 Class Reference

RN41 Class Reference

RN41/42 is Bluetooth module. More...

#include <RN41.h>

Public Member Functions

 RN41 (PinName TX, PinName RX, int baudrate, int bit=8, int parity=SerialBase::None, int stop=1, bool CRLN=true)
 Create Serial port to RN41.
string getLine ()
 RxStrのCRまでを返す。

Detailed Description

RN41/42 is Bluetooth module.

RN41 is calss 1, RN42 is class 2. RN42 refer to http://akizukidenshi.com/catalog/g/gM-07612/ .

 #include "mbed.h"
#include <string>
#include "RN41.h"
RN41 rn41(p13, p14, 9600);
DigitalOut led[]= {LED1, LED2, LED3, LED4};
void connectRN41(string tmpAddr);
int main()
{
    while(true) {
        led[0]= !led[0];
        connectRN41("target BT address");
        rn41.sendLine("test");
        wait_ms(100);
        printf(rn41.getLine().c_str());
        if(rn41.disconnect())
            printf("disconnect");
        wait(5.0);
    }
}
void connectRN41(string tmpAddr)
{
    printf("Connect to: %s.\r\n", tmpAddr);
    int status= rn41.connect(tmpAddr);
    if(status == RN41::OK)                      printf("OK, Connect.");
    else if(status == RN41::ERR_AddrUnder12)    printf("NG, Connect. Under12 Addr.");
    else if(status == RN41::ERR_AddrOver12)     printf("NG, Connect. Over12 Addr.");
    else if(status == RN41::ERR_EnterCmdMode)   printf("Error, failed in to enter Cmd-mode.");
    else if(status == RN41::ERR_Disconnect)     printf("Error, failed in DisConnect.");
    else if(status == RN41::ERR_Connect)        printf("Error, Connect.");
    else if(status == RN41::FAIL_Connect)       printf("Fail, Connect.");
    else if(status == RN41::ERR_Timeout )       printf("Error, TimeOut.");
    else                                        printf("Error Connection: %d.",status);
    return;
}

Bluetooth module RN41/42 control class.

Definition at line 62 of file RN41.h.


Constructor & Destructor Documentation

RN41 ( PinName  TX,
PinName  RX,
int  baudrate,
int  bit = 8,
int  parity = SerialBase::None,
int  stop = 1,
bool  CRLN = true 
)

Create Serial port to RN41.

for LPC1768

Parameters:
TX,RX;Serial port.
baud-rate;Baud rate (bps).
bit,parity,stop;Default: 1Stopbit, NoneParity, 1StopBit. -- parity select; N(None), O(Odd), E(Even).
CRLN;true -> CR&LN (
), false -> CR only ().

Definition at line 31 of file RN41.cpp.


Member Function Documentation

string getLine (  )

RxStrのCRまでを返す。

Definition at line 93 of file RN41.cpp.