2016年10月26日 星期三

RN42 藍芽 BlueSMiRF 連線說明

由於買了 SparkFun Bluetooth Modem - BlueSMiRF Silver 發現設定問題一堆,以下有解決方案
規格: SparkFun Bluetooth Modem - BlueSMiRF Silver

產品網站: https://www.sparkfun.com/products/12577

AT 命令表: http://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf

BlueSMiRF 系列產品操作說明: https://learn.sparkfun.com/tutorials/using-the-bluesmirf/example-code-using-command-mode

如何辨認 SMiRF 與 Mate 硬體: https://learn.sparkfun.com/tutorials/using-the-bluesmirf

AT Command 程式碼:

/*
  Example Bluetooth Serial Passthrough Sketch
 by: Jim Lindblom
 SparkFun Electronics
 date: February 26, 2013
 license: Public domain

 This example sketch converts an RN-42 bluetooth module to
 communicate at 9600 bps (from 115200), and passes any serial
 data between Serial Monitor and bluetooth module.
 */
#include <SoftwareSerial.h>  

int bluetoothTx = 2;  // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3;  // RX-I pin of bluetooth mate, Arduino D3

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  Serial.begin(9600);  // Begin the serial monitor at 9600bps

  bluetooth.begin(115200);  // The Bluetooth Mate defaults to 115200bps
  bluetooth.print("$");  // Print three times individually
  bluetooth.print("$");
  bluetooth.print("$");  // Enter command mode
  delay(100);  // Short delay, wait for the Mate to send back CMD
  bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600, no parity
  // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
  bluetooth.begin(9600);  // Start bluetooth serial at 9600
}

void loop()
{
  if(bluetooth.available())  // If the bluetooth sent any characters
  {
    // Send any characters the bluetooth prints to the serial monitor
    Serial.print((char)bluetooth.read());  
  }
  if(Serial.available())  // If stuff was typed in the serial monitor
  {
    // Send any characters the Serial monitor prints to the bluetooth
    bluetooth.print((char)Serial.read());
  }
  // and loop forever and ever!
}
接腳:
Vcc : 5v
GND: GND
RX: Arduino Digital Pin 3
TX: Arduino Digital Pin 2

燒錄 Arduino 後,打開視窗,先修改模式為 No line ending,然後輸入 $$$ ,就會打開 CMD 模式,此時 BT 上的 LED 會狂閃爍,然後再把模式切換成 New Line。

接下來指令請參考:


互相聯繫:




Reference:
https://learn.sparkfun.com/tutorials/using-the-bluesmirf/example-code-using-command-mode
https://learn.sparkfun.com/tutorials/using-the-bluesmirf
http://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf
https://www.sparkfun.com/products/12577
http://ruten-proteus.blogspot.tw/2014/07/Bluetooth-Kit-tutorial-02-hc-05-02.html
http://swf.com.tw/?p=750

沒有留言:

張貼留言

© ERIC RILEY , 自由無須告知轉貼
Background Japanese Sayagata by Olga Libby