Bluetoothモジュール(HC-6)の名前の変え方 with Arduino
やりたいこと
HC-6というBluetoothモジュールの名前を変えたい。
以下の順で名前変更指示をする。
PC → Arduino Nano → Bluetoothモジュール
そのために
PC、Arduino間はハードウェアシリアル
Arduino、Bluetooth間はソフトウェアシリアル
で接続する。
参考サイト
前提
Arduino IDEがインストールされていること。
www.arduino.cc
材料
- Mini USB Nano V3.0 ATmega328P
HiLetgo® 3個セット Mini USB Nano V3.0 ATmega328P CH340G 5V 16M マイクロコントローラーボード Arduinoと互換
- 出版社/メーカー: HiLetgo
- メディア: エレクトロニクス
- この商品を含むブログ (1件) を見る
これは純正のArduinoではなく、中華製なのでドライバのインストールが必要。
このページを参考に。
qiita.com
- ブルートゥースモジュール [HC-06-4P] www.aitendo.com
TODO
- まずは配線
- Arduinoプログラムの作成
- ビルド&書き込み
- 名前変更
1. まずは配線
+ ArduinoとPCがつながっていること
2. Arduinoプログラムの作成
#include <stdio.h> #include <stdlib.h> #include <SoftwareSerial.h> #define PIN_BLUETOOTH_TX 10 // Bluetooth TX #define PIN_BLUETOOTH_RX 11 // Bluetooth RX /* Bluetoothモジュールと通信をするためのソフトウェアシリアル */ SoftwareSerial mySerial(PIN_BLUETOOTH_RX, PIN_BLUETOOTH_TX); // TX, RX void setup() { Serial.begin(9600); //ハードウェアシリアルの初期化 mySerial.begin(9600); // ソフトウェアシリアルの初期化 } void loop() { while( Serial.available() ) { char c = Serial.read(); mySerial.print(c); delay(5); } while( mySerial.available() ) { char c = mySerial.read(); Serial.print(c); delay(5); } }
3. ビルド&書き込み
「ツール」→「シリアルポート」をクリックし、接続したArduinoのポートを選択する。
「マイコンボードに書き込む」をクリック。
これによりビルドされ、書き込みまで行われる。
4. 名前変更
Arduino IDEの右上の虫眼鏡ボタンをクリックしてコンソールを表示。
AT+NAME:好きな名前
OKと表示されれば入力した名前に変更されているので、実際にBluetoothを検索してみて指定した名前が見つかれば成功。