Bluetooth HC05 + KL25Z communicate with Bluetooth dongle in PC in both directions.

Dependencies:   mbed

main.cpp

Committer:
GerritPathuis
Date:
2017-12-02
Revision:
0:0e236e004748
Child:
1:e73a7c99f767

File content as of revision 0:0e236e004748:

/*
 * Author: G. Pathuis
 * Date: 02-12-17
 * Notes: HC05 connected to a KL25Z
 * Pair with PC use password 1234
 *
 * Four wire connection
 * HC05 to KL25Z
 * GND to GND
 * +5V to 5V
 * TX to pin PTE0
 * RX to pin PTE1
 *
 * Open Tera Term session to connect to KL25Z
 * and
 * Open second Tera Term session to read the Bluetooth
 * dongle in the PC
 *
 * Make sute Tera Term uses 9600 baud
*/

#include "mbed.h"


Serial pc(USBTX, USBRX);
Serial blue(PTE0, PTE1);          // TX, RX

DigitalOut myled(LED1);
DigitalOut myled2(LED2);


int main()
{
    int i =0;
    blue.baud(9600);               // Default Bluetooth Baudrate
    pc.baud(9600);

    pc.printf("Bluetooth Start\r\n");

    // Write from Bluetooth to PC
    for (i=0; i<10; i++) {
        blue.printf("Hello PC this is the HC-05, %d\n\r", i);
        myled = !myled;
    }
    wait(1);

    // Echo back characters and toggle the LED
    while (1) {
        if (blue.readable()) {
            pc.putc(blue.getc());
            myled = !myled;
        }
        if (pc.readable()) {
            blue.putc(pc.getc());
            myled2 = !myled2;
        }
        wait_ms(10);
    }
}