Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: btbee m3pi_ng mbed
Fork of configure_btbee by
main.cpp@2:d0adbf94c4c0, 2013-11-13 (annotated)
- Committer:
- smeisel
- Date:
- Wed Nov 13 17:58:30 2013 +0000
- Revision:
- 2:d0adbf94c4c0
- Parent:
- 1:af0aa8d6e586
Took a program from Nikolas Goldin and added additional instrucitons and tip and hints for success This has been tested for the DFRobot BlueTooth Bee ver 2.0.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ngoldin | 0:e674a8b2b330 | 1 | #include "mbed.h" |
| ngoldin | 0:e674a8b2b330 | 2 | #include "m3pi_ng.h" |
| ngoldin | 1:af0aa8d6e586 | 3 | #include "btbee.h" |
| ngoldin | 0:e674a8b2b330 | 4 | |
| ngoldin | 0:e674a8b2b330 | 5 | m3pi m3pi; |
| ngoldin | 1:af0aa8d6e586 | 6 | btbee btbee; |
| ngoldin | 0:e674a8b2b330 | 7 | |
| ngoldin | 0:e674a8b2b330 | 8 | DigitalOut mbed_led[] = {(LED1), (LED2),(LED3), (LED4)}; |
| ngoldin | 0:e674a8b2b330 | 9 | DigitalOut m3pi_led[] = {(p13), (p14), (p15), (p16), (p17), (p18), (p19), (p20)}; |
| ngoldin | 0:e674a8b2b330 | 10 | |
| ngoldin | 1:af0aa8d6e586 | 11 | int main () |
| ngoldin | 1:af0aa8d6e586 | 12 | { |
| ngoldin | 1:af0aa8d6e586 | 13 | // initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////////// |
| ngoldin | 0:e674a8b2b330 | 14 | for (int i = 0; i <4; i++) { |
| ngoldin | 0:e674a8b2b330 | 15 | mbed_led[i] = 0; |
| ngoldin | 0:e674a8b2b330 | 16 | } |
| ngoldin | 0:e674a8b2b330 | 17 | for (int i = 0; i <8; i++) { |
| ngoldin | 1:af0aa8d6e586 | 18 | m3pi_led[i] = 0; |
| ngoldin | 0:e674a8b2b330 | 19 | } |
| ngoldin | 1:af0aa8d6e586 | 20 | btbee.at_baud(); |
| ngoldin | 1:af0aa8d6e586 | 21 | // end initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////// |
| smeisel | 2:d0adbf94c4c0 | 22 | m3pi.locate(0,0); |
| ngoldin | 0:e674a8b2b330 | 23 | m3pi.printf("ATSWITCH"); |
| smeisel | 2:d0adbf94c4c0 | 24 | m3pi.locate(0,1); |
| ngoldin | 0:e674a8b2b330 | 25 | m3pi.printf("RIGHT???"); |
| ngoldin | 0:e674a8b2b330 | 26 | wait(0.1); |
| ngoldin | 0:e674a8b2b330 | 27 | m3pi_led[0]=1; |
| smeisel | 2:d0adbf94c4c0 | 28 | /***************** |
| smeisel | 2:d0adbf94c4c0 | 29 | The commands sent to the bee have to be lower case |
| smeisel | 2:d0adbf94c4c0 | 30 | The commands sent to the bee do not start with \r\n as the BlueTooth Bee wiki state |
| smeisel | 2:d0adbf94c4c0 | 31 | This works with the DFRobot BlueToothBee ver 2.0 Tested and verified 11/13/13 on my personal M3PI and BTBee module |
| smeisel | 2:d0adbf94c4c0 | 32 | Additional commands can be found at: http://www.dfrobot.com/image/data/TEL0026/TEL0026_Datasheet.pdf |
| ngoldin | 0:e674a8b2b330 | 33 | |
| smeisel | 2:d0adbf94c4c0 | 34 | Steps to success: |
| smeisel | 2:d0adbf94c4c0 | 35 | 1.Power off |
| smeisel | 2:d0adbf94c4c0 | 36 | 2.switch on bee to AT Mode |
| smeisel | 2:d0adbf94c4c0 | 37 | 3.Power on |
| smeisel | 2:d0adbf94c4c0 | 38 | 4.Download program to MBED |
| smeisel | 2:d0adbf94c4c0 | 39 | 5.Run MBED program |
| smeisel | 2:d0adbf94c4c0 | 40 | 6.Power off settings in the bee are sent to ROM and will be retained after the power cycle |
| smeisel | 2:d0adbf94c4c0 | 41 | 7.Switch to !AT Mode |
| smeisel | 2:d0adbf94c4c0 | 42 | 8.Power On |
| smeisel | 2:d0adbf94c4c0 | 43 | *****************/ |
| smeisel | 2:d0adbf94c4c0 | 44 | |
| ngoldin | 0:e674a8b2b330 | 45 | |
| smeisel | 2:d0adbf94c4c0 | 46 | //btbee.printf("at\r\n"); // test command, returns "OK\r\n" |
| smeisel | 2:d0adbf94c4c0 | 47 | //btbee.printf("at+uart=9600,0,0\r\n"); //default values, returns "OK\r\n" |
| smeisel | 2:d0adbf94c4c0 | 48 | //btbee.printf("at+uart=115200,0,0\r\n"); //changing the baud rate, returns "OK\r\n" |
| smeisel | 2:d0adbf94c4c0 | 49 | //wait(2.0); //necessary delay after a baud rate change |
| smeisel | 2:d0adbf94c4c0 | 50 | |
| smeisel | 2:d0adbf94c4c0 | 51 | //btbee.printf("at+name=Pololu_Car\r\n"); /set the name of the Bluetooth Module to: Pololu_Car |
| smeisel | 2:d0adbf94c4c0 | 52 | |
| smeisel | 2:d0adbf94c4c0 | 53 | wait(2.0); //found that this delay elmiminates a lot of issues Never Remove it |
| smeisel | 2:d0adbf94c4c0 | 54 | |
| smeisel | 2:d0adbf94c4c0 | 55 | //btbee.printf("at+uart?\r\n"); //asking for the serial set parameters, replies "+UART:baud,stop,parity\r\n" |
| smeisel | 2:d0adbf94c4c0 | 56 | //btbee.printf("at+name?\r\n"); //returns the name assigned to the bee module |
| smeisel | 2:d0adbf94c4c0 | 57 | //btbee.printf("at+role?\r\n"); //returns the role of the bee (master = 1, slave=0, slave is default) |
| smeisel | 2:d0adbf94c4c0 | 58 | btbee.printf("at+pswd?\r\n"); //returns the current bee paring password (default is 1234) |
| smeisel | 2:d0adbf94c4c0 | 59 | |
| smeisel | 2:d0adbf94c4c0 | 60 | |
| ngoldin | 0:e674a8b2b330 | 61 | m3pi_led[1]=1; |
| ngoldin | 0:e674a8b2b330 | 62 | |
| ngoldin | 1:af0aa8d6e586 | 63 | while (!btbee.readable()) { //wait for reply |
| ngoldin | 1:af0aa8d6e586 | 64 | mbed_led[0]=!mbed_led[0]; |
| ngoldin | 1:af0aa8d6e586 | 65 | wait(0.1); |
| ngoldin | 0:e674a8b2b330 | 66 | } |
| ngoldin | 1:af0aa8d6e586 | 67 | |
| ngoldin | 1:af0aa8d6e586 | 68 | char reply_array[30]; |
| ngoldin | 1:af0aa8d6e586 | 69 | int reply_length=0; |
| ngoldin | 0:e674a8b2b330 | 70 | |
| ngoldin | 0:e674a8b2b330 | 71 | m3pi_led[2]=1; |
| ngoldin | 1:af0aa8d6e586 | 72 | btbee.read_all(reply_array, 30, &reply_length); |
| ngoldin | 1:af0aa8d6e586 | 73 | m3pi_led[3]=1; |
| ngoldin | 1:af0aa8d6e586 | 74 | |
| ngoldin | 0:e674a8b2b330 | 75 | m3pi.locate(0,0); |
| ngoldin | 1:af0aa8d6e586 | 76 | m3pi.cls(); |
| ngoldin | 1:af0aa8d6e586 | 77 | if (reply_length<9) { |
| ngoldin | 1:af0aa8d6e586 | 78 | m3pi.print(reply_array, reply_length); |
| ngoldin | 1:af0aa8d6e586 | 79 | } else { |
| ngoldin | 1:af0aa8d6e586 | 80 | m3pi.print(reply_array, 8); |
| ngoldin | 1:af0aa8d6e586 | 81 | m3pi.locate(0,1); |
| ngoldin | 1:af0aa8d6e586 | 82 | m3pi.print(reply_array+8, reply_length-8); |
| ngoldin | 0:e674a8b2b330 | 83 | } |
| ngoldin | 1:af0aa8d6e586 | 84 | m3pi_led[4]=1; |
| ngoldin | 0:e674a8b2b330 | 85 | |
| ngoldin | 1:af0aa8d6e586 | 86 | }//main |
| ngoldin | 1:af0aa8d6e586 | 87 |
