Differences
This shows you the differences between two versions of the page.
hu:arduino:bluetooth_modul [2017/09/20 13:03] |
hu:arduino:bluetooth_modul [2022/04/21 15:02] () |
||
---|---|---|---|
1: | 1: | ||
+ | ====== Bluetooth kommunikációs modulok ====== | ||
+ | ===== HC-05 ===== | ||
+ | {{anchor: | ||
+ | A [[hu: | ||
+ | |||
+ | ==== A HC-nn sorozat jellemzői ==== | ||
+ | |||
+ | * Míg a HC-05 beállítható Master és Slave modulnak is, addig a HC-06 kizárólag Slave-ként alkalmazható | ||
+ | * A HC-05-nek 6, míg a HC-06-nak 4 lába van | ||
+ | * Ügyelni kell arra, hogy a modulok általában 3,3V tápfeszültséggel üzemelnek. Az 5V-os bemenet teljesen modulgyártó függő. | ||
+ | * A modulok kétféle működési móddal rendelkeznek: | ||
+ | * Sokszor magát a modult un. " | ||
+ | * [[hu: | ||
+ | * Jelszó: 1234 | ||
+ | * Eszköz neve: HC-05 / HC-06 | ||
+ | |||
+ | ^HC-05 fent^HC-05 lent| | ||
+ | |{{: | ||
+ | |||
+ | ==== A HC-05 lábkiosztása ==== | ||
+ | ^port^funkció| | ||
+ | |KEY|Ha a tápellátás bekapcsolása előtt HIGH állapotban van, bekapcsolja az "AT Parancs" | ||
+ | |VCC|+5 táp| | ||
+ | |GND|grund| | ||
+ | |TXD|Jelek átadása az Arduino felé. 3.3V HIGH szint!| | ||
+ | |RXD|Soros adatok fogadása az Arduino felől| | ||
+ | |STATE|Kapcsolat létrejött jelzés| | ||
+ | |||
+ | ==== "AT Parancs" | ||
+ | A Parancs mód kétféle módon aktiválható | ||
+ | - A modul tápjának bekapcolása **után** a " | ||
+ | - A modul tápjának bekapcsolása **előtt** a " | ||
+ | |||
+ | ==== BlueToothCommandUtility ==== | ||
+ | A modult előzőleg kösse össze az Arduino-val az alábbiak szerint | ||
+ | * GND a GND-hoz | ||
+ | * Arduino Pin 2 a HC-05 TXD-hez | ||
+ | * Arduino Pin 3 a HC-05 RXD-hez | ||
+ | * Arduino Pin 4 a HC-05 KEY-hez | ||
+ | * Arduino Pin 5+6 a HC-05 VCC táphoz | ||
+ | |||
+ | A program: | ||
+ | < | ||
+ | /* YourDuino.com Example: BlueTooth HC-05 Setup | ||
+ | - WHAT IT DOES: | ||
+ | - Sets " | ||
+ | - THEN applies Vcc from 2 Arduino pins to start command mode | ||
+ | - SHOULD see the HC-05 LED Blink SLOWLY: 2 seconds ON/ | ||
+ | |||
+ | | ||
+ | For Setup of HC-05 type BlueTooth Module | ||
+ | NOTE: Set Serial Monitor to 'Both NL & CR' and '9600 Baud' at bottom right | ||
+ | - SEE the comments after "//" | ||
+ | - CONNECTIONS: | ||
+ | - GND | ||
+ | - Pin 2 to HC-05 TXD | ||
+ | - Pin 3 to HC-05 RXD | ||
+ | - Pin 4 to HC-05 KEY | ||
+ | - Pin 5+6 to HC-05 VCC for power control | ||
+ | - V1.02 05/02/2015 | ||
+ | | ||
+ | |||
+ | /*-----( Import needed libraries )-----*/ | ||
+ | #include < | ||
+ | /*-----( Declare Constants and Pin Numbers )-----*/ | ||
+ | #define HC_05_TXD_ARDUINO_RXD 2 | ||
+ | #define HC_05_RXD_ARDUINO_TXD 3 | ||
+ | #define HC_05_SETUPKEY | ||
+ | #define HC_05_PWR1 | ||
+ | #define HC_05_PWR2 | ||
+ | |||
+ | /*-----( Declare objects )-----*/ | ||
+ | SoftwareSerial BTSerial(HC_05_TXD_ARDUINO_RXD, | ||
+ | /*-----( Declare Variables )-----*/ | ||
+ | //NONE | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | pinMode(HC_05_SETUPKEY, | ||
+ | pinMode(HC_05_PWR1, | ||
+ | pinMode(HC_05_PWR2, | ||
+ | | ||
+ | digitalWrite(HC_05_SETUPKEY, | ||
+ | | ||
+ | Serial.begin(9600); | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | delay(2000); | ||
+ | Serial.println(" | ||
+ | digitalWrite(HC_05_PWR1, | ||
+ | digitalWrite(HC_05_PWR2, | ||
+ | delay(2000); | ||
+ | Serial.println(" | ||
+ | BTSerial.begin(38400); | ||
+ | |||
+ | }//--(end setup )--- | ||
+ | |||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | // READ from HC-05 and WRITE to Arduino Serial Monitor | ||
+ | if (BTSerial.available()) | ||
+ | Serial.write(BTSerial.read()); | ||
+ | |||
+ | // READ Arduino Serial Monitor and WRITE to HC-05 | ||
+ | if (Serial.available()) | ||
+ | BTSerial.write(Serial.read()); | ||
+ | |||
+ | }//--(end main loop )--- | ||
+ | |||
+ | /*-----( Declare User-written Functions )-----*/ | ||
+ | //NONE | ||
+ | |||
+ | // | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Bluetooth AT parancsok jegyzéke ==== | ||
+ | |||
+ | < | ||
+ | 1 AT Test UART Connection | ||
+ | 2 AT+RESET Reset Device | ||
+ | 3 AT+VERSION Querry firmware version | ||
+ | 4 AT+ORGL Restore settings to Factory Defaults | ||
+ | 5 AT+ADDR Query Device Bluetooth Address | ||
+ | 6 AT+NAME Query/Set Device Name | ||
+ | 7 AT+RNAME Query Remote Bluetooth Device’s Name | ||
+ | 8 AT+ROLE Query/Set Device Role | ||
+ | 9 AT+CLASS Query/Set Class of Device CoD | ||
+ | 10 AT+IAC Query/Set Inquire Access Code | ||
+ | 11 AT+INQM Query/Set Inquire Access Mode | ||
+ | 12 AT+PSWD Query/Set Pairing Passkey | ||
+ | 13 AT+UART Query/Set UART parameter | ||
+ | 14 AT+CMODE Query/Set Connection Mode | ||
+ | 15 AT+BIND Query/Set Binding Bluetooth Address | ||
+ | 16 AT+POLAR Query/Set LED Output Polarity | ||
+ | 17 AT+PIO Set/Reset a User I/O pin | ||
+ | 18 AT+MPIO Set/Reset multiple User I/O pin | ||
+ | 19 AT+MPIO? Query User I/O pin | ||
+ | 20 AT+IPSCAN Query/Set Scanning Parameters | ||
+ | 21 AT+SNIFF Query/Set SNIFF Energy Savings Parameters | ||
+ | 22 AT+SENM Query/Set Security & Encryption Modes | ||
+ | 23 AT+RMSAD Delete Authenticated Device from List | ||
+ | 24 AT+FSAD Find Device from Authenticated Device List | ||
+ | 25 AT+ADCN Query Total Number of Device from Authenticated Device List | ||
+ | 26 AT+MRAD Query Most Recently Used Authenticated Device | ||
+ | 27 AT+STATE Query Current Status of the Device | ||
+ | 28 AT+INIT Initialize SPP Profile | ||
+ | 29 AT+INQ Query Nearby Discoverable Devices | ||
+ | 30 AT+INQC Cancel Search for Discoverable Devices | ||
+ | 31 AT+PAIR Device Pairing | ||
+ | 32 AT+LINK Connect to a Remote Device | ||
+ | 33 AT+DISC Disconnect from a Remote Device | ||
+ | 34 AT+ENSNIFF Enter Energy Saving mode | ||
+ | 35 AT+EXSNIFF Exit Energy Saving mode | ||
+ | </ | ||
+ | |||
+ | ==== Bluetooth AT hibakódok ==== | ||
+ | |||
+ | < | ||
+ | 0 Command Error/ | ||
+ | 1 Results in default value | ||
+ | 2 PSKEY write error | ||
+ | 3 Device name is too long (>32 characters) | ||
+ | 4 No device name specified (0 length) | ||
+ | 5 Bluetooth address NAP is too long | ||
+ | 6 Bluetooth address UAP is too long | ||
+ | 7 Bluetooth address LAP is too long | ||
+ | 8 PIO map not specified (0 lenght) | ||
+ | 9 Invalid PIO port Number entered | ||
+ | A Device Class not specified (0 lenght) | ||
+ | B Device Class too long | ||
+ | C Inquire Access Code not Specified (0 lenght) | ||
+ | D Inquire Access Code too long | ||
+ | E Invalid Iquire Access Code entered | ||
+ | F Pairing Password not specified (0 lenght) | ||
+ | 10 Pairing Password too long (> 16 characters) | ||
+ | 11 Invalid Role entered | ||
+ | 12 Invalid Baud Rate entered | ||
+ | 13 Invalid Stop Bit entered | ||
+ | 14 Invalid Parity Bit entered | ||
+ | 15 No device in the Pairing List | ||
+ | 16 SPP not initialized | ||
+ | 17 SPP already initialized | ||
+ | 18 Invalid Inquiry Mode | ||
+ | 19 Inquiry Timeout occured | ||
+ | 1A Invalid/ | ||
+ | 1B Invalid Security Mode entered | ||
+ | 1C Invalid Encryption Mode entered | ||
+ | </ | ||
+ | |||
+ | ==== HC-05 példaprogram ==== | ||
+ | |||
+ | A lenti példaprogramot [[http:// | ||
+ | |||
+ | Először is, össze kell kötni | ||
+ | * A modul VCC lábát az Arduino 3.3V kimenetével (ne az 5V-tal!) | ||
+ | * Grund a grundhoz | ||
+ | * A modul Rx lábát az Arduino Tx lábával | ||
+ | * A modul Tx lábát az Arduino Rx lábával | ||
+ | |||
+ | {{: | ||
+ | |||
+ | A példaprogram: | ||
+ | |||
+ | < | ||
+ | /* | ||
+ | Arduino Turn LED On/Off using Serial Commands | ||
+ | Created April 22, 2015 | ||
+ | Hammad Tariq, Incubator (Pakistan) | ||
+ | |||
+ | It's a simple sketch which waits for a character on serial | ||
+ | and in case of a desirable character, it turns an LED on/off. | ||
+ | |||
+ | Possible string values: | ||
+ | a (to turn the LED on) | ||
+ | b (tor turn the LED off) | ||
+ | */ | ||
+ | |||
+ | char junk; | ||
+ | String inputString=""; | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | if(Serial.available()){ | ||
+ | while(Serial.available()) | ||
+ | { | ||
+ | char inChar = (char)Serial.read(); | ||
+ | inputString += inChar; | ||
+ | } | ||
+ | Serial.println(inputString); | ||
+ | while (Serial.available() > 0) | ||
+ | { junk = Serial.read() ; } // clear the serial buffer | ||
+ | if(inputString == " | ||
+ | digitalWrite(13, | ||
+ | }else if(inputString == " | ||
+ | digitalWrite(13, | ||
+ | } | ||
+ | inputString = ""; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Források ==== | ||
+ | https:// | ||
+ | http:// | ||
+ | |||
+ | ===== HC-06 ===== | ||
+ | {{anchor: | ||
+ | |||
+ | ^HC-06 fent^HC-06 lent| | ||
+ | |{{: | ||
+ | |||
+ | A HC-06 modul technikailag megegyezik a fenti HC-05-tel, azzal a külömbséggel, |