DM9H Microscope 7'' IPS Screen 1200X 16MP Camera, Magnification Soldering Microscope Digital Microscope
DM9H Microscope 7'' IPS Screen 1200X 16MP Camera, Magnification Soldering Microscope Digital Microscope السعر الأصلي هو: 7,000.00 EGP.السعر الحالي هو: 6,300.00 EGP.
UNI-T UT33A+ PALM SIZED DIGITAL MULTIMETERS
UNI-T UT33A+ PALM SIZED DIGITAL MULTIMETERS السعر الأصلي هو: 750.00 EGP.السعر الحالي هو: 675.00 EGP.

JDY-31 Bluetooth Module 6 pin (USART)

350.00 EGP

JDY-31 Bluetooth Module 6 pin (USART)

Share:

JDY-31 Bluetooth Module (USART)
Important note: This description was translated from Chinese and taken from the website :
【STM32F103】JDY-31蓝牙模块(USART)_jdy31蓝牙模块-CSDN博客

JDY has a total of 6 pins, and if we want to make it work, we only need to connect two wires, that is, VCC and GND. Connect a voltage of 3.6V~6V to VCC (recommended is 5V), connect GND to ground, and then JDY31 starts working, and we can find JDY’s Bluetooth by turning on Bluetooth on our mobile phones.
After pairing, our mobile phone can communicate with JDY31, but it is meaningless just to communicate with JDY31, so we will connect JDY31 and the microcontroller, so that we can use the mobile phone to control the microcontroller through Bluetooth.
We connect the RXD of JDY31 to the TXD of our STM32F103, and the TXD is connected to the RXT of our STM32F103 (it is recommended to use the resources of USART1, pins 9 and 10 of GPIOA, because the working voltage of JDY is higher, and STM32F103 is generally The pins cannot withstand it, but the pins of the USART1 resource can accept 5V voltage. Please refer to the pin definition table for details)

In this way, as long as our mobile phone is connected to JDY31 through Bluetooth, and JDY31 and STM32F103 are connected through the serial port, as long as the mobile phone sends serial port data through the Bluetooth assistant, then JDY will directly receive it and send it to STM32F103. The data sent by the STM32F103 through the serial port will also be transmitted to our mobile phones via JDY31.

So Bluetooth communication is not that difficult, or it is because of highly integrated modules like JDY31 that make our Bluetooth communication simple.

The remaining two pins are STATE and EN. Simply put, EN is useless. After we connect the Bluetooth from JDY, STATE will output a high level, and an external LED can be connected to visually check whether the Bluetooth is connected. But it’s not really necessary, because JDY comes with a small red light. The small red light will flash when waiting for connection, and the small red light will stay on after connecting.

AT command control JDY31 The above describes how to perform Bluetooth communication through JDY31. And if we want to modify some configuration information of JDY (such as Bluetooth name, connection password, etc.), we need to use AT commands to control JDY. In fact, AT commands sound cool, but they are actually just a bunch of specific strings.

For example, if I want to query the version number, I can directly ask the STM32F103 to send the string “AT+VERSION\r\n” through the serial port, that is, add “\r\n” to the command. Then JDY31 will send the version number through the serial port. In essence, it is still serial communication.

There is nothing much to say about the above nine general instructions. Let’s briefly talk about the instructions with parameters.

The baud rate command can add parameters to modify the baud rate, but it is not freely set. For example, if I want to set the baud rate of 9600, then the command I send should be “AT+BAUD<4>\r\ n”, other baud rate parameters can refer to the figure above.

Set the pairing password, the default is 1234, just send the password to be modified as a parameter.

Bluetooth name setting, there will be a slight delay. You have to wait for the Bluetooth name searched on the phone to be updated.

As mentioned above, under normal circumstances, after JDY31 is connected to Bluetooth, STATE will send out a high level. If we disable the serial port status output, then STATE will be of no use like EN.

Use the serial port to perform AT commands on JDY-31 through STM32F103

The following explanation is used in conjunction with the following code.

There is nothing to say about opening the serial port. Just copy the code from my previous article about USART.

For the convenience of serial port output, I added the stdio library and rewritten fputc. This is to be able to directly use printf for serial port output. keil5 also needs to be configured as shown below.

Then all we need to do is to directly send the AT command. It should be noted that there needs to be a delay between two consecutive commands, otherwise JDY31 will not be able to respond (my guess is that JDY will ignore some commands)

The results obtained are in the figure below the code.

  1. #include “stm32f10x.h” // Device header
  2. #include “Delay.h”
  3. #include <stdio.h>
  4. //interrupt function
  5. void USART1_IRQHandler(void){
  6. //Determine the data receiving flag bit
  7. if(SET==USART_GetFlagStatus(USART1,USART_FLAG_RXNE)){
  8. uint16_t data=USART_ReceiveData(USART1); //Read out the received data
  9. printf(“%c”,data);
  10. USART_ClearITPendingBit(USART1,USART_FLAG_RXNE); //Clear the data receiving flag bit
  11.            }
  12.  }
  13. void sendbyte(uint16_t Data){
  14. //Send data
  15. USART_SendData(USART1,Data);
  16. //Wait for data to be sent
  17. while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
  18. }
  19. //Rewrite fputc here so that you can directly use printf to output the serial port
  20. int fputc(int ch, FILE *f){
  21. sendbyte(ch);
  22. return ch;
  23. }
  24. int main(void){
  25. RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
  26. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  27. GPIO_InitTypeDef itd;
  28. itd.GPIO_Mode=GPIO_Mode_AF_PP; //Multiplex push-pull output
  29. itd.GPIO_Pin=GPIO_Pin_9; //TX pin
  30. itd.GPIO_Speed=GPIO_Speed_2MHz; //This is optional
  31. GPIO_Init(GPIOA,&itd);
  32. itd.GPIO_Mode=GPIO_Mode_IN_FLOATING; //Floating input
  33. itd.GPIO_Pin=GPIO_Pin_10; //RX pin
  34. GPIO_Init(GPIOA,&itd);
  35. USART_InitTypeDef uitd;
  36. uitd.USART_BaudRate=9600; //baud rate
  37. uitd.USART_HardwareFlowControl=USART_HardwareFlowControl_None; //Hardware flow control
  38. uitd.USART_Mode=USART_Mode_Rx|USART_Mode_Tx; //Serial port mode
  39. uitd.USART_Parity=USART_Parity_No; //check
  40. uitd.USART_StopBits=USART_StopBits_1; //Stop bit length
  41. uitd.USART_WordLength=USART_WordLength_8b; //Transmitted word length
  42. USART_Init(USART1,&uitd);
  43. USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //Enable USART receive interrupt
  44. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //NVIC interrupt configuration
  45. NVIC_InitTypeDef nitd;
  46. nitd.NVIC_IRQChannel=USART1_IRQn;
  47. nitd.NVIC_IRQChannelCmd=ENABLE;
  48. nitd.NVIC_IRQChannelPreemptionPriority=2;
  49. nitd.NVIC_IRQChannelSubPriority=2;
  50. NVIC_Init(&nitd);
  51. USART_Cmd(USART1,ENABLE); //Power on USART
  52. printf(“AT+NAME\r\n”); //Query Bluetooth name
  53. Delay_ms(100);
  54. printf(“AT+LADDR\r\n”); //Query mac address
  55. Delay_ms(100);
  56. printf(“AT+BAUD\r\n”); //Query baud rate
  57. Delay_ms(100);
  58. printf(“AT+PIN\r\n”); //Query Bluetooth connection password
  59. Delay_ms(100);
  60. printf(“AT+ENLOG\r\n”); //Query status output enable status
  61. Delay_ms(100);
  62. printf(“AT+VERSION\r\n”); //Query version
  63. Delay_ms(100);
  64. printf(“AT+NAME<JDY>\r\n”); //Change the Bluetooth name, but the response is slow and it will take a while to update.
  65. while(1){
  66. }
  67. }
    Ignore the last line, it is sent by JDY after Bluetooth is disconnected.

    JDY communicates with mobile phone via Bluetooth

    In fact, Bluetooth communication sounds very cool. In fact, after your mobile phone is connected to Bluetooth, the so-called Bluetooth communication actually uses the serial port to send information. Therefore, we can directly use printf to output the content, and then the mobile phone can receive it. However, we need to use a Bluetooth assistant to see it. I use the one provided by a certain merchant. You can find any one. It is even available in the WeChat applet. .

  1. #include “stm32f10x.h” // Device header
  2. #include “Delay.h”
  3. #include <stdio.h>
  4. //interrupt function
  5. void USART1_IRQHandler(void){
  6. //Judge the data receiving flag bit
  7. if(SET==USART_GetFlagStatus(USART1,USART_FLAG_RXNE)){
  8. uint16_t data=USART_ReceiveData(USART1); //Read the received data
  9. printf(“%c”,data);
  10. USART_ClearITPendingBit(USART1,USART_FLAG_RXNE); //Clear the data receiving flag bit
  11. }
  12. }
  13. void sendbyte(uint16_t Data){
  14. //Send data
  15. USART_SendData(USART1,Data);
  16. //Wait for data to be sent
  17. while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
  18. }
  19. int fputc(int ch, FILE *f){
  20. sendbyte(ch);
  21. return ch;
  22. }
  23. int main(void){
  24. RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
  25. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  26. GPIO_InitTypeDef itd;
  27. itd.GPIO_Mode=GPIO_Mode_AF_PP; //Multiplexed push-pull output
  28. itd.GPIO_Pin=GPIO_Pin_9; //TX pin
  29. itd.GPIO_Speed=GPIO_Speed_2MHz; //This is optional
  30. GPIO_Init(GPIOA,&itd);
  31. itd.GPIO_Mode=GPIO_Mode_IN_FLOATING;//floating input
  32. itd.GPIO_Pin=GPIO_Pin_10; //RX pin
  33. GPIO_Init(GPIOA,&itd);
  34. USART_InitTypeDef uitd;
  35. uitd.USART_BaudRate=9600; //baud rate
  36. uitd.USART_HardwareFlowControl=USART_HardwareFlowControl_None; //Hardware flow control
  37. uitd.USART_Mode=USART_Mode_Rx|USART_Mode_Tx; //Serial port mode
  38. uitd.USART_Parity=USART_Parity_No; //check
  39. uitd.USART_StopBits=USART_StopBits_1; //Stop bit length
  40. uitd.USART_WordLength=USART_WordLength_8b; //Transmitted word length
  41. USART_Init(USART1,&uitd);
  42. USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //Enable USART receive interrupt
  43. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //NVIC interrupt configuration
  44. NVIC_InitTypeDef nitd;
  45. nitd.NVIC_IRQChannel=USART1_IRQn;
  46. nitd.NVIC_IRQChannelCmd=ENABLE;
  47. nitd.NVIC_IRQChannelPreemptionPriority=2;
  48. nitd.NVIC_IRQChannelSubPriority=2;
  49. NVIC_Init(&nitd);
  50. USART_Cmd(USART1,ENABLE); //Power on USART
  51. while(1){
  52. printf(“Hello World”);
  53. Delay_ms(2000);
  54. }
  55. }

This is the complete information received by the serial port assistant, including Bluetooth connection and disconnection.

This is the information in the Bluetooth assistant of the mobile phone. The information starting with RX is the received information, and the information starting with TX is the information sent by the mobile phone.

14 Days Warranty

This item is covered with a standard warranty of 14 days from the time of delivery against manufacturing defects only. This warranty is given for the benefit of Micro Ohm customers from any kind of manufacturing defects. Replacement will be done against manufacturing defects.

What voids warranty:

If the product is subject to misuse, tampering, static discharge, accident, water or fire damage, use of chemicals & soldered or altered in any way.

Shopping cart
Sign in


No account yet?

Create an Account
اقدر اخدمك ازي يا فندم ؟
Scan the code