Nucleo board with Seeed bot and bluetooth shields demo.

Dependencies:   BluetoothSerial SeeedShieldBot mbed

This code shows a simple application composed of a Nucleo board, a Seeed Bot and Seeed Bluetooth shieds:

This picture shows how the three boards are stacked together:

/media/uploads/bcostm/nucleo_bluetooth_bot.jpg

You will need also to use an application on your phone to send Bluetooth commands and to be able to control the Bot shield. We have used the Bluetooth spp tools pro Android application.

Look at this video to have more details about this demo:

Revision:
0:fa6bc104fe2d
Child:
1:6a67ad238815
--- /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);
+    } 
+}