Bluetooth program for the Seeed bot

Dependencies:   BluetoothSerial SeeedShieldBot mbed

Fork of Seeed_BlueBot_demo by ST

Files at this revision

API Documentation at this revision

Comitter:
bcostm
Date:
Mon Sep 08 08:22:07 2014 +0000
Child:
1:6a67ad238815
Commit message:
Initial version.

Changed in this revision

BluetoothSerial.lib Show annotated file Show diff for this revision Revisions of this file
SeeedShieldBot.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-src.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BluetoothSerial.lib	Mon Sep 08 08:22:07 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/yihui/code/BluetoothSerial/#f56002898ee8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SeeedShieldBot.lib	Mon Sep 08 08:22:07 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/components/code/SeeedShieldBot/#9fd1722259a1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Sep 08 08:22:07 2014 +0000
@@ -0,0 +1,111 @@
+#include "mbed.h"
+#include "BluetoothSerial.h"
+#include "SeeedStudioShieldBot.h"
+
+// The following configuration must be done on the NUCLEO board:
+// - Close SB62/SB63 and open SB13/SB14 solder bridges to enable the D0/D1 pins
+// - Open SB21 solder bridge to disconnect the LED
+
+BluetoothSerial bluetooth(D1, D0); // TX, RX
+
+SeeedStudioShieldBot bot(
+    D8, D9, D11,       // Right motor pins (PwmOut, DigitalOut, DigitalOut) -> Motor 1
+    D12, D10, D13,     // Left motor pins (PwmOut, DigitalOut, DigitalOut) -> Motor 2
+    A0, A1, A2, A3, A4 // Sensors pins (all DigitalIn)
+);
+
+// Enable it for debugging on hyperterminal
+#define DEBUG 1
+#if DEBUG == 1
+Serial pc(PC_10, PC_11);
+#define PC_DEBUG(args...) pc.printf(args)
+#else
+#define PC_DEBUG(args...)
+#endif
+
+Ticker tick;
+
+float speed = 1.0; // Motors speed
+    
+void ReadCommand(void)
+{
+    int cmd = 0;
+    PC_DEBUG(">>> Read command...\n");
+    if (bluetooth.readable())
+    {
+        cmd = bluetooth.getc();
+        PC_DEBUG(">>> Bluetooth read [%c]\n", cmd);
+        switch(cmd)
+        {
+        case 1: // Forward
+            bot.forward(speed);
+            break;
+        case 2: // Backward
+            bot.backward(speed);
+            break;              
+        case 3: // Left
+            bot.left(speed);
+            break;
+        case 4: // Right
+            bot.right(speed);
+            break;              
+        case 5: // Turn left
+            bot.turn_right(speed);
+            break;
+         case 6: // Turn right
+            bot.turn_left(speed);
+            break; 
+         case 7: // Slow
+            speed = 0.4;
+            break;
+         case 8: // Fast
+            speed = 1.0;
+            break;
+         default: // Stop
+            bot.stopAll();
+            break;
+         }
+    }    
+}
+    
+int main()
+{
+    PC_DEBUG("\n\nSeeed Bluetooth shield test started.\n");
+      
+    // Enable motors
+    bot.enable_right_motor();
+    bot.enable_left_motor();
+    
+    // Check if they are alive
+    bot.left(speed);
+    wait(0.2);
+    bot.right(speed);
+    wait(0.2);
+    bot.stopAll();
+  
+    PC_DEBUG(">>> Bluetooth setup...");
+    bluetooth.setup();
+    PC_DEBUG("done\n");
+  
+    PC_DEBUG(">>> Bluetooth in slave mode...");
+    bluetooth.slave("btslave8seeed");  // default PIN code: 0000
+    PC_DEBUG("done\n");
+    
+    wait(2);
+    
+    PC_DEBUG(">>> Bluetooth connect...");
+    bluetooth.connect();
+    PC_DEBUG("done\n");
+    
+    tick.attach_us(ReadCommand, 500000); // Every 500ms read Bluetooth command
+
+    bot.forward(speed);
+    wait(0.4);
+    bot.backward(speed);
+    wait(0.4);
+    bot.stopAll();
+      
+    while (1) {
+        wait(1);
+    } 
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-src.lib	Mon Sep 08 08:22:07 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-src/#8f72041da6ba