Buletooth module(RX-42XVP) sample program

Dependencies:   mbed

Buletoothモジュール(RN-42XVP)の青mbed(LPC1768)での動作確認

<概要>

トランジスタ技術2014年3月号 3章のBuletoothモジュール(RN-42XVP)とLPC810を使った作例で、LPC810を青mbed(LPC1768)に変更して、配線とmbedプログラムを簡素化して動作確認をしやすくしました。

動作例動画:

<機材準備>

  1. 配線 Buletoothモジュールへの電源供給はmbedから行います。またシリアル通信線2本をmbedに接続します。
RN-42XVPmbed(LPC1768)
Pin1(Vcc)VOUT(3.3V)
Pin2(DOUT)p14(rx)
Pin3(DIN)p13(tx)
Pin10GND(0V)
  1. Androidアプリ AndroidアプリはCQ出版社のwebからダウンロードします。 http://toragi.cqpub.co.jp/tabid/707/Default.aspx
    パソコンからandroidへのインストールはトランジスタ技術の記事を参照してください。
  1. 青mbed(LPC1768)のプログラム Mbedのwebからダウンロードしてください。

    Import programRN-42XVPsample

    Buletooth module(RX-42XVP) sample program

<動作>

Androidアプリはテンキー(0~9)と”LED ON/OFF”のボタンがあり、これらのボタンを押すとアスキーコードの’0’~’9’,’+’,’-‘が送信されます。これを青mbedで受信して、mbed上の4つのLEDを制御します。また受信したデータをmbedのUSB-Serialで外部に送信します。パソコンでターミナルソフト(TeraTarmなど)で確認できます。

以上

Revision:
0:66a02c06ec33
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Feb 23 00:24:55 2014 +0000
@@ -0,0 +1,54 @@
+/**
+    Transistor Gijutsu 2014nen 3gatugo page.64 3syo
+    Buletooth ban
+    LPC810 wo LPC1768 ni henko sita sample program
+
+
+RN-42XVP   LPC1768
+-------------------
+Pin1       VOUT
+Pin2       p14(rx)
+Pin3       p13(tx)
+Pin10      GND   
+
+*/
+#include "mbed.h"
+
+BusOut myleds(LED1, LED2, LED3, LED4);
+
+Serial pc(USBTX, USBRX); // (tx, rx) 
+Serial xbee(p13, p14);    // (tx,rx) RN-42XVP tuusinyo serial
+
+int main()
+{
+    uint8_t rawData;
+    uint8_t newData;
+
+    xbee.baud(115200);
+
+    while(1) {
+
+        if(1 == xbee.readable()) {
+            rawData = xbee.getc();
+
+            pc.printf("rawData = %02x\n",rawData);
+            
+            if(rawData != 0x00) {
+                if(rawData == '+') {
+                    newData = 0x0f;
+                } else if(rawData == '-') {
+                    newData = 0x00;
+                } else if(rawData == '0') {
+                    newData = 0x0a;
+                } else {
+                    newData = rawData - '0';
+                }
+
+                myleds = newData;
+
+
+            }
+
+        }
+    }
+}