A simple BT communication between PC and HT-06

Dependencies:   mbed

Committer:
robertspil
Date:
Mon Apr 18 10:25:38 2016 +0000
Revision:
0:cf3a3ae84ff4
simple test program bluetoth-pc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robertspil 0:cf3a3ae84ff4 1 /* BT01 Test Bluetooth serial communication
robertspil 0:cf3a3ae84ff4 2 mbed1768 sur breadboard, alimenté par cable USB
robertspil 0:cf3a3ae84ff4 3 serial debug par USB et console Gtkterm
robertspil 0:cf3a3ae84ff4 4 device HC-06
robertspil 0:cf3a3ae84ff4 5 GND
robertspil 0:cf3a3ae84ff4 6 VCC = VU du mbed (5V)
robertspil 0:cf3a3ae84ff4 7 RX =P28 (tx du mbed)
robertspil 0:cf3a3ae84ff4 8 TX =P27 (rx du mbed)
robertspil 0:cf3a3ae84ff4 9 au préalable : utiliser BlueTerm pour se connecter et pairage (code 1234) id 20:15:1224:10:03
robertspil 0:cf3a3ae84ff4 10 ensuite utiliser ce programme pour
robertspil 0:cf3a3ae84ff4 11 */
robertspil 0:cf3a3ae84ff4 12 #include "mbed.h"
robertspil 0:cf3a3ae84ff4 13 Serial pc(USBTX, USBRX);
robertspil 0:cf3a3ae84ff4 14 Serial bt (p28,p27);
robertspil 0:cf3a3ae84ff4 15 DigitalOut myled(LED1);
robertspil 0:cf3a3ae84ff4 16
robertspil 0:cf3a3ae84ff4 17 int main() {
robertspil 0:cf3a3ae84ff4 18 // communication avec Gtkterm - prévoir local echo
robertspil 0:cf3a3ae84ff4 19 pc.baud(115200);
robertspil 0:cf3a3ae84ff4 20 pc.printf("Start bt communication\n");
robertspil 0:cf3a3ae84ff4 21 //bt.baud(9600); // HC-06 org speed
robertspil 0:cf3a3ae84ff4 22 bt.baud(115200); // my standart speed BAUD8
robertspil 0:cf3a3ae84ff4 23 // AT commands WITHOUT CONNECTION (blinking led HC-06)
robertspil 0:cf3a3ae84ff4 24 // rove the /* ...*/ to activate
robertspil 0:cf3a3ae84ff4 25 /*wait(1);
robertspil 0:cf3a3ae84ff4 26 bt.printf("AT");
robertspil 0:cf3a3ae84ff4 27 wait(1);*/
robertspil 0:cf3a3ae84ff4 28 /*bt.printf("AT+VERSION");
robertspil 0:cf3a3ae84ff4 29 wait(1);
robertspil 0:cf3a3ae84ff4 30 while(bt.readable()) {
robertspil 0:cf3a3ae84ff4 31 pc.putc(bt.getc());
robertspil 0:cf3a3ae84ff4 32 }
robertspil 0:cf3a3ae84ff4 33 wait(1);
robertspil 0:cf3a3ae84ff4 34 */
robertspil 0:cf3a3ae84ff4 35 /*bt.printf("AT+NAMEHC_06_RcclV5b");
robertspil 0:cf3a3ae84ff4 36 wait(1); */
robertspil 0:cf3a3ae84ff4 37 /*bt.printf("AT+BAUD8"); // 115200 bauds
robertspil 0:cf3a3ae84ff4 38 wait(1);
robertspil 0:cf3a3ae84ff4 39 bt.baud(115200);*/
robertspil 0:cf3a3ae84ff4 40
robertspil 0:cf3a3ae84ff4 41 while(1){ //duplex
robertspil 0:cf3a3ae84ff4 42 while(pc.readable())
robertspil 0:cf3a3ae84ff4 43 bt.putc(pc.getc());
robertspil 0:cf3a3ae84ff4 44 while(bt.readable())
robertspil 0:cf3a3ae84ff4 45 pc.putc(bt.getc());
robertspil 0:cf3a3ae84ff4 46 }
robertspil 0:cf3a3ae84ff4 47
robertspil 0:cf3a3ae84ff4 48 }