第1步:工具和組件
這就是您需要的-
Attiny84或85
藍(lán)牙模塊
面包板
跳線
步驟2:電路
如下設(shè)置ATiny和藍(lán)牙之間的連接-
藍(lán)牙模塊Rx-》 ATiny85引腳1
藍(lán)牙模塊Tx-》 ATiny85引腳2
藍(lán)牙模塊接地-》 ATiny85引腳4
藍(lán)牙模塊VCC-》 ATiny85引腳8
步驟3:代碼
在這里是可以運行的測試草圖,連接6點的led并上傳代碼。從串行終端發(fā)送1將打開LED指示燈,發(fā)送0將關(guān)閉它。
#include //Software Serial Port
#define RxD 1
#define TxD 2
#define DEBUG_ENABLED 1
SoftwareSerial blueToothSerial(RxD,TxD);
int led = 4;
void setup()
{
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
pinMode(led,OUTPUT);
digitalWrite(led,HIGH);
}
void loop()
{
char recvChar;
while(1){
//check if there‘s any data sent from the remote bluetooth shield
if(blueToothSerial.available()){
recvChar = blueToothSerial.read();
if(recvChar == ’1‘)
digitalWrite(led,HIGH);
else
digitalWrite(led,LOW);
}
}
}
void setupBlueToothConnection()
{
blueToothSerial.begin(9600); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print(“ +STWMOD=0 ”); //set the bluetooth work in slave mode
blueToothSerial.print(“ +STNA=HC-05 ”); //set the bluetooth name as “HC-05”
blueToothSerial.print(“ +STOAUT=1 ”); // Permit Paired device to connect me
blueToothSerial.print(“ +STAUTO=0 ”); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
//blueToothSerial.print(“ +INQ=1 ”); //make the slave bluetooth inquirable
blueToothSerial.print(“bluetooth connected! ”);
delay(2000); // This delay is required.
blueToothSerial.flush();
}
責(zé)任編輯:wv
-
藍(lán)牙
+關(guān)注
關(guān)注
119文章
6417瀏覽量
179455 -
串行通信
+關(guān)注
關(guān)注
4文章
610瀏覽量
37250
發(fā)布評論請先 登錄
NRF54L15DK串行恢復(fù)模式?jīng)]有了藍(lán)牙功能,應(yīng)該怎樣在藍(lán)牙模式下進(jìn)行ota
深入解析 Z80C30/Z85C30 CMOS SCC 串行通信控制器
Zilog Z80C30/Z85C30 SCC:高性能串行通信控制器的深度解析
并行與串行的基本通信方式
Xilinx FPGA串行通信協(xié)議介紹
使用RTT的維護(hù)云進(jìn)行遠(yuǎn)程固件升級(OTA),怎么沒有網(wǎng)絡(luò)升級的方式?
SMC串行傳輸系統(tǒng)通過Profinet轉(zhuǎn)EtherCAT網(wǎng)關(guān)進(jìn)行連接的配置案例
藍(lán)牙無線通訊-藍(lán)牙5.4概述
串行通信和并行通信的區(qū)別是什么
全面了解串行通信
ESP32用作經(jīng)典藍(lán)牙串口透傳模塊與手機(jī)進(jìn)行串口通信
如何通過藍(lán)牙網(wǎng)絡(luò)與ATiny85進(jìn)行串行通信
評論