• 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 bluetooth sensor arduino messages , enable bluetooth COM port windows 10 , esp32 a2dp source to pc , esp32 Bluetooth pc , esp32 Bluetooth send and receive message , esp32 putty , esp32 serial print bluetooth receive , led control with esp32 and bluetooth serial terminal in laptop , servo motor with esp32 and bluetooth serial terminal app in laptop

This Article Has Been Shared 904 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic 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

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe

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 (21K Followers)
  • Twitter (5.3k 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

  • How Startups Can Convince the Investors April 14, 2021
  • What to Know About the Cloud Storage Services for Smartphones April 13, 2021
  • WonderFox HD Video Converter Factory Pro Review April 10, 2021
  • What is the Maximum Cable Length Between Arduino/ESP32 and a Sensor April 8, 2021
  • Is the Blockchain Hype Running Out of Breath? April 7, 2021

 

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, April 15, 2021, https://thecustomizewindows.com/2020/01/send-receive-message-on-pc-over-bluetooth-from-esp32-arduino/.

Source:The Customize Windows, JiMA.in

 

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.

PC users can consult Corrine Chorney for Security.

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

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

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