第1步:工具和組件
這就是您需要的-
Attiny84或85
藍牙模塊
面包板
跳線
步驟2:電路
如下設(shè)置ATiny和藍牙之間的連接-
藍牙模塊Rx-》 ATiny85引腳1
藍牙模塊Tx-》 ATiny85引腳2
藍牙模塊接地-》 ATiny85引腳4
藍牙模塊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();
}
責任編輯:wv
-
藍牙
+關(guān)注
關(guān)注
119文章
6345瀏覽量
178996 -
串行通信
+關(guān)注
關(guān)注
4文章
608瀏覽量
37182
發(fā)布評論請先 登錄
NRF54L15DK串行恢復(fù)模式?jīng)]有了藍牙功能,應(yīng)該怎樣在藍牙模式下進行ota
深入解析 Z80C30/Z85C30 CMOS SCC 串行通信控制器
Zilog Z80C30/Z85C30 SCC:高性能串行通信控制器的深度解析
并行與串行的基本通信方式
使用RTT的維護云進行遠程固件升級(OTA),怎么沒有網(wǎng)絡(luò)升級的方式?
SMC串行傳輸系統(tǒng)通過Profinet轉(zhuǎn)EtherCAT網(wǎng)關(guān)進行連接的配置案例
串行通信和并行通信的區(qū)別是什么
全面了解串行通信
ESP32用作經(jīng)典藍牙串口透傳模塊與手機進行串口通信
如何增加藍牙通信距離?
串行通信接口SPI與QSPI的區(qū)別
如何通過藍牙網(wǎng)絡(luò)與ATiny85進行串行通信
評論