• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Send-Receive Message on PC Over Bluetooth From ESP32 Arduino

By Abhishek Ghosh January 30, 2020 10:35 am Updated on January 30, 2020

Send-Receive Message on PC Over Bluetooth From ESP32 Arduino

Advertisement

This guide intended to be for somewhat advanced users of Arduino and Windows 10. We are using ESP32 setup with Arduino IDE in this mentioned way. We need PuTTY as extra software. Unfortunately, ESP32 with Arduino libraries and Windows 10 is far from being perfect. The original target of this guide is to complete these steps :

  1. ESP32 will remain connected with the Windows 10 PC via USB for code uploading purpose
  2. ESP32 will pair with the Windows 10 PC via Bluetooth
  3. We will send message to the ESP32 from Windows 10 PC over Bluetooth
  4. We will retrive the sent message on Windows 10 PC over Bluetooth

 

Unfortunately, step 4 is not easy to complete. If you somehow use two Arduino IDEs to send and receive the message then they will become unresponsive. Arduino IDE is too simple to guess any error. Using PuTTY to communicate over the COM port of Windows 10 makes the sending message part easy. Espressif themselves has example code to use the Bluetooth serial :

Vim
1
2
3
#
https://github.com/espressif/arduino-esp32/blob/master/libraries/BluetoothSerial/examples/SerialToSerialBT/SerialToSerialBT.ino
#

Below is the code from above link :

Advertisement

---

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "BluetoothSerial.h"
 
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
 
BluetoothSerial SerialBT;
 
void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
}
 
void loop() {
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(20);
}

The BluetoothSerial.h code uses a FreeRTOS queue. Thus the uxQueueMessagesWaiting function is called which returns several messages available on the queue. But that had minor glitch :

Vim
1
2
3
#
https://github.com/espressif/arduino-esp32/issues/1207
#

Go ahead and compile the code and upload it to ESP32 using the Arduino IDE. How open complete the pairing from Windows 10 PC. By going to the Bluetooth settings and Device Manager (on Windows 10 PC) you’ll get the COM port numbers of incoming and outgoing Bluetooth Connection. Usually, COM3 is outgoing and COM5 is incoming. I will completely avoid Arduino IDE, instead, use multiple instances of PuTTY.

To find the Bluetooth COM port number we need to open the Device Manager. Go down the list until you see Ports (COM & LPT). Click “Ports (COM & LPT)” and you will see what ports are in use by Bluetooth.

Now open the first instance of putty. Select Serial in the connection type option, write the correct COM port of USB (COM6 in our example), select a speed of 115200. Click the Terminal tab option on the left-hand side and select Force On both for Local echo and Local line editing options. Save this setting with some name. Launch the terminal session. You’ll get this kind of output :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
ets Jun  8 2016 00:22:57
 
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:10208
load:0x40080400,len:6460
entry 0x400806a4
The device started, now you can pair it with bluetooth!

Now open the second instance of putty. Select Serial in the connection type option, write the correct COM port of outgoing Bluetooth (COM3 in our example). You can load the previously saved value or do manually – select a speed of 115200, click the Terminal tab option on the left-hand side and select Force On both for Local echo and Local line editing options. Launch the terminal session. This will be an empty terminal where you can type, hit enter and send a message.

Now open the third instance of putty. Select Serial in the connection type option, write the correct COM port of incoming Bluetooth (COM5 in our example). You can load the previously saved value or do manually – select a speed of 115200, click the Terminal tab option on the left-hand side and select Force On both for Local echo and Local line editing options. Launch the terminal session. This will be an empty terminal where your typed message will arrive over Bluetooth.

I have the below code which turns ON and OFF the on-board blue LED upon pressing 1 and 0 respectively. Also, it echoes a useful message. Usually, peoples use these kinds of codes to control ESP32 with smartphone apps. But, in our case, we are using one Windows 10 PC.

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "BluetoothSerial.h"
BluetoothSerial ESP_BT;
int incoming;
int LED_BUILTIN = 2; // on-board LED pin number
 
void callback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param){
  if(event == ESP_SPP_SRV_OPEN_EVT){
    Serial.println("Client Connected");
  }
}
 
void setup() {
  Serial.begin(115200); //serial monitor at 115200
  ESP_BT.register_callback(callback);
  ESP_BT.begin("ESP32"); //name of Bluetooth
  Serial.println("Bluetooth Device is Ready to Pair");
  pinMode (LED_BUILTIN, OUTPUT);
}
void loop() {
  
  if (ESP_BT.available()) // checking if we receive data from Bluetooth
  {
    incoming = ESP_BT.read(); // check what we recevived
    Serial.write(incoming); // print on Bluetooth serial
    Serial.print("Received:"); Serial.println(incoming);
    if (incoming == 49)
        {
        digitalWrite(LED_BUILTIN, HIGH);
        ESP_BT.println("LED turned ON");
        }
        
    if (incoming == 48)
        {
        digitalWrite(LED_BUILTIN, LOW);
        ESP_BT.println("LED turned OFF");
        }    
  }
  delay(20);
}

Send-Receive Message on PC Over Bluetooth From ESP32 Arduino

End-result in my case – no print on PuTTY terminal attached to the incoming Bluetooth port. That is probably out of bug of Arduino libraries. You can install the Android App named “Bluetooth Serial Terminal” (by Kai) to test the code.

I have kept the code on my GitHub repo for your usage and edit.

Tagged With https://thecustomizewindows com/2020/01/send-receive-message-on-pc-over-bluetooth-from-esp32-arduino/ , how to test esp32 bluetooth with pc , esp32 serial print bluetooth receive , esp32 putty , esp32 Bluetooth send and receive message , esp32 Bluetooth pc , esp32 bluetooth data transfer to windows 10 , esp32 bluetooth communicating with windows system , esp32 a2dp source to pc , enable bluetooth COM port windows 10

This Article Has Been Shared 825 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Send-Receive Message on PC Over Bluetooth From ESP32 Arduino

  • ESP32 Arduino : Create a Webpage to Control a Relay Module

    Here is How to Create a Webpage to Control a Relay Module Using ESP32 Arduino. This is a basic example which provides the base of advanced projects.

  • ESP32 Arduino Built-in Hall Sensor Code & Theory

    ESP32 has a Hall Effect Sensor near pin 22. Here is ESP32 Arduino Built-in Hall Sensor Code & Theory. Here is something about Hall Effect Sensor as well.

  • ESP32 Arduino OLED Display Example (I2C)

    Interfacing OLED without I2C is difficult with ESP32, as it requires 6 connections. I2C based OLED display need only two IO lines.

  • ESP32 Arduino : Fetching Current Weather Data (No JSON Parsing)

    In this guide we have shown how to fetch current weather data from ESP32 Arduino. This code example is basic and no JSON parsing is shown.

  • Tips For Building Digital Switch With ESP32 Arduino

    There are some design considerations to increase safety while building an ESP32 Arduino based physical switch controlled by IoT project.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • What is Voice User Interface (VUI) January 31, 2023
  • Proxy Server: Design Pattern in Programming January 30, 2023
  • Cyberpunk Aesthetics: What’s in it Special January 27, 2023
  • How to Do Electrical Layout Plan for Adding Smart Switches January 26, 2023
  • What is a Data Mesh? January 25, 2023

About This Article

Cite this article as: Abhishek Ghosh, "Send-Receive Message on PC Over Bluetooth From ESP32 Arduino," in The Customize Windows, January 30, 2020, February 1, 2023, https://thecustomizewindows.com/2020/01/send-receive-message-on-pc-over-bluetooth-from-esp32-arduino/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT