This shows you the differences between two versions of the page.
| — | en:examples:communication:bluetooth:btbee [2026/02/19 11:30] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Bluetooth BTBee ====== | ||
| + | |||
| + | |||
| + | //Required knowledge: | ||
| + | [HW] [[et: | ||
| + | [AVR] [[et: | ||
| + | [LIB] [[et: | ||
| + | [LIB] [[et: | ||
| + | |||
| + | /* | ||
| + | **For the Eunistone module see here:** | ||
| + | [[et/ | ||
| + | **For the Bluetooth Bee module see here:** | ||
| + | |||
| + | [[et/ | ||
| + | */ | ||
| + | |||
| + | ===== Theory ===== | ||
| + | |||
| + | [{{ :: | ||
| + | Bluetooth is an industry standard for creating wireless connections between devices. Bluetooth is primarily intended for connecting computers and mobile phones with various peripheral devices, such as headsets, printers, GPS receivers, etc. Bluetooth also enables easy and secure data exchange between two devices. Bluetooth is a two-layer standard that defines the physical layer (radio frequencies) and the protocol layer (how data is transmitted). It is a wireless data exchange standard that uses radio frequencies in the range 2.402 - 2.480 GHz. Many other consumer radio devices operate in the same band. Bluetooth has three power classes, but most devices are class 2, which limits the range to about 10 meters. Line of sight is not required, although walls and other obstacles reduce the range. Up to 8 Bluetooth devices can be connected at the same time without interfering with each other. This is ensured by spread-spectrum frequency hopping, which makes connected devices use slightly different frequencies and change them continuously. | ||
| + | |||
| + | One characteristic of Bluetooth is automatic connectivity. When a Bluetooth device appears within the visibility range of another device, an automatic information exchange takes place to determine whether data exchange should begin or whether one device should take control of the other. This exchange happens automatically without any special commands from the user. If the exchange shows that the devices are authorized to communicate, | ||
| + | |||
| + | Security is an important factor in Bluetooth, and different modes ensure secure data exchange and connections. Generally the user can define trusted devices with which connections can be established without asking for a separate password. If a new device tries to connect, the user can allow or deny it. Security measures include authorization and device identification before data exchange begins. | ||
| + | |||
| + | Today there are four main Bluetooth versions and many minor versions. Most modules intended for hobby projects are still based on version 2.0. Version 3 introduced higher data rates (up to 24 Mbit/s) and version 4 introduced lower power consumption, | ||
| + | |||
| + | ===== Practice ===== | ||
| + | [{{ : | ||
| + | |||
| + | Bluetooth Bee (BTBee) is a Bluetooth Serial Port Profile (Bluetooth SPP) module that fits into the Robotic HomeLab Combo module' | ||
| + | When the module is connected to the XBee socket and the HomeLab kit is powered, the BTBee enters slave mode by default. After that, commands can be sent to the module over UART. Communication uses AT commands documented in the module {{: | ||
| + | |||
| + | Default settings of the BTBee module: | ||
| + | * Mode: //slave// | ||
| + | * Serial interface: 38400 b/s, 1 STOP, No Parity | ||
| + | * Password: 1234 | ||
| + | |||
| + | To communicate with the module, you can use a computer (usually a laptop) or a mobile phone Bluetooth interface. For Android phones you can use the " | ||
| + | |||
| + | ~~CL~~ | ||
| + | <code c> | ||
| + | // HomeLab wireless BTBee module example program | ||
| + | // Text received from an external device is displayed on the LCD screen | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | // Main program | ||
| + | int main(void) | ||
| + | { | ||
| + | // LCD setup | ||
| + | lcd_gfx_init(); | ||
| + | lcd_gfx_goto_char_xy(0, | ||
| + | lcd_gfx_write_string(" | ||
| + | |||
| + | // USART interface setup | ||
| + | usart_init_async(1, | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | // Infinite loop | ||
| + | while (1) | ||
| + | { | ||
| + | char info[30]; | ||
| + | |||
| + | // Is there incoming data? | ||
| + | if (usart_has_data(1)) | ||
| + | { | ||
| + | // Read incoming data | ||
| + | usart_read_string(1, | ||
| + | // Display text on LCD | ||
| + | lcd_gfx_write_string(info); | ||
| + | } | ||
| + | |||
| + | // Is the button pressed? | ||
| + | if (button_read(S1)) | ||
| + | { | ||
| + | // Send text | ||
| + | usart_send_string(1," | ||
| + | // Wait for button release | ||
| + | while(button_read(S1)); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||