Bluetooth System Monitor Using ESP32
MAKER: Dustin Watts
Previously, we introduced ” DIY a small square screen to display Raspberry Pi information “. By deploying a piece of Python code on the computer that needs to be monitored, the monitoring data of the machine can be displayed on another small screen through the MQTT network protocol.
The project to be introduced in this issue has similar functions. The difference is that it uses Bluetooth to connect to the computer and transmit the data that needs to be monitored (such as CPU temperature, fan speed, memory usage, etc.), which is more convenient to use without a network.
Its principle is very simple and its appearance is small. You only need to connect the ILI9488 screen to ESP32. After uploading the code, the device you monitor will run the host script data and send it to this display. You can view the data information at any time. Because it is a Bluetooth connection, no data cable is required, so you can put it on your desk to view the system data information. Isn’t it very convenient!
Component List
ESP32-WROOM-32 development board (38 pin headers) X 1
ILI9488 TFT screen (with XPT2046 touch controller) X 1
ESP32+TFT PCB board X 1 (optional)
Soldering Iron X 1
Solder x 1
Iron pliers X 1
Connecting the TFT Screen to the ESP32
Connect these two parts together in three ways:
1. Use a breadboard.
2. Use a prototype board.
3. Use a custom PCB board to connect ILI9488 to ESP32 DevKitC.
Using a breadboard is a convenient way to test connections and screens. But be careful to keep the table level and the connectors firm when testing; the screen needs to run at 3.3V, 5V will cause damage!
ESP32 -> ILI9488 Make the following connections:
3.3V -> VCC
GND -> GND
GPIO15 -> CS
GPIO4 -> RESET
GPIO2 -> DC/RS
GPIO23 -> SDI(MOSI) and T_DIN
GPIO18 -> SCK and T_CLK
GPIO32 -> LED
GPIO21 -> T_CS
GPIO19 -> T_DO
GPIO27 -> T_IRQ
Note that the screen’s SDO (MISO) is not used, so leave an unconnected pin on the TFT module.
The files for the custom PCB board can also be downloaded in this project’s file library:
https://make.quwj.com/project/404
https://github.com/DustinWatts/ESP32_TFT_Combiner
Installing Arduino IDE Library
Download and install Arduino IDE ESP32 core
1. From the Arduino IDE software, go to File – Preferences
2. Click the text box after Additional Board Managers URLs: and change the URL to: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json and click OK.
3. Click Tools – Board: – Board Manager and enter “ESP32” in the search box. Install the latest version and click Close.
Installing Additional Libraries
From Sketch – Include Library – Manage Libraries search and install the following libraries: Adafruit-GFX-Library and TFT_eSPI.
Additionally, if you are using the ESP32 TouchDown, you will also need to install the capacitive touch library:
Open https://github.com/DustinWatts/FT6236, click “Code” and download “Download .ZIP”.
In the Arduino IDE, select Sketch – Include Library – Add .ZIP library and the download is complete.
Configuring TFT screen
1. Before compiling and uploading the Bluetooth-System-Monitor.ino code file, edit the file containing User_Setup.h in the TFT_eSPI library. It can be found in the Arduino sketchbook folder under “Library”.
2. If you have not renamed the TFT_eSPI library folder, you can find the file User_Setup.h in TFT_eSPI-master.
3. You need to uncomment the code that applies to your hardware configuration. You can find the user_setup.h file required for this project in the downloaded repository in the “user_setup.h Examples” folder.
4. Copy the file “ESP32_Dev_Kit_V1_ILI9488_Resistive.h” to “/TFT_eSPI-master/”. Rename the existing “User_Setup.h” to “User_Setup.old” (this will keep the original file in case of problems).
5. Rename “ESP32_Dev_Kit_V1_ILI9488_Resistive.h” to “User_Setup.h” (case sensitive), save and close the file.
If you are using ESP32 TouchDown, use the same configuration method.
Download the Arduino Sketch and upload it to the ESP32
Use the ESP code data upload tool.
This project uses SPIFFS (ESP32 flash memory) to store images used as backgrounds. You need to upload these to the ESP32 before uploading the code to it. Therefore, you need the ESP32 Code Data Uploader Tool.
You can download it from GitHub:
https://github.com/me-no-dev/arduino-esp32fs-plugin
You can also download it in this project’s document library:
https://make.quwj.com/project/404
Follow the instructions on GitHub to install the tool:
Download the tool folder, the link is:
https://github.com/me-no-dev/arduino-esp32fs-plugin/releases/tag/1.0
If the library does not exist, create it in the Arduino sketchbook library.
Unzip the tool into the tool library (path is /Arduino/tools/ESP32FS/tool/esp32fs.jar).
Restart the Arduino IDE.
For MacOS, create the repository in ~/Documents/Arduino/ and unzip the files there.
Upload data directory
Before uploading the data folder to the ESP32, the correct partitioning scheme must be selected.
Before uploading the data directory to the ESP32, the correct partitioning scheme must be selected.
In the menu Tools – Board, select ESP32 Dev Module.
In Tools, select the partition scheme “Default 4MB with spiffs”.
Plug in the ESP32.
Click Tools and select ESP Sketch Data Upload.
If data upload fails, it may be because you have the serial monitor open. If this happens, close the serial monitor and try again.
Bluetooth-System-Monitor.ino
On Github you can find the full source code:
https://github.com/DustinWatts/Bluetooth-System-Monitor
You can also download it in this project’s document library:
https://make.quwj.com/project/404
From the Bluetooth-System-Monitor GitHub repository, then click on “Code” and “Download.ZIP”
Unzip the folder and rename it to “Bluetooth-System-Monitor”. This way the folder and code in the Arduino IDE will have different names.
If this happens, a window will pop up asking if the code should be moved. This will result in only moving the code and not the data folder, causing the upload to fail!
Open the Bluetooth-System-Monitor.ino code in the Arduino IDE.
Configuration Code
Depending on the board you are using (resistive touch, capacitive touch or no touch) you have to uncomment the right one. For example, if you are using ESP32 TouchDown uncomment: “#define ENABLE_CAP_TOUCH”. If you are using DevKitC with a separate TFT, uncomment “#define ENABLE_RES_TOUCH”.
In the code you can set some warning levels. This will make the text under the icon turn red. Scroll down until you see Define warning levels, change this as you like.
You can also set the scale of the graph’s y-axis. This is done under The scale of the Y-axis per graph. If these are too large or too small, the data will not display correctly on the graph. You may need to experiment a bit.
Uploading the Code to the ESP32
Go ahead and upload the Bluetooth-System-Monitor.ino code to the ESP32. The settings under tools can be left as default, except for the partition scheme (see image).
After waiting for a while, you can arrange for the devices you want to monitor to send data to the system monitor.
Bluetooth connection
Before connecting the Bluetooth Information Monitor to your computer, you must first make a Bluetooth connection and ensure that the ESP32 is powered on.
On Windows:
Right-click the Start menu, click Settings, then click Devices. Click “Add Bluetooth or other device”, select “Bluetooth”, wait for it to find “ESP32” or “MyDisplay”, and click Connect. After this, you can click Finish.
Open the Device Manager (right-click on the start menu) and click on the arrow next to Ports. There should now be a device called “Standard Serial over Bluetooth link”. This is the “COM” port used in the next step.
Note: In my setup, two new devices appeared. I chose the first one, but you will need to verify again.
On MacOS:
Open Preferences and click Bluetooth. It will show “ESP32” or “MyDisplay”, wait for the search to finish, select “ESP32” or “MyDisplay”, and click “Connect”.
If you want to see what the actual device name is, you can open a terminal and type: “ls /dev/tty.*” and it will list all the serial ports for you.
Python script to send data to the monitor
I will provide two Python scripts that will send data to the Information System Monitor. One for Windows and one for MacOS. Both require you to have the latest version of Python installed. You can download and install them here:
https://www.python.org/downloads/
Windows
In order for the script to run correctly, you need to install some Python modules. These modules are psutil, pyserial, and pythonnet. You can install these using PIP, open a command prompt as an administrator by clicking the Start menu and typing cmd, then right-clicking the command prompt and selecting Run as Administrator.
Navigate to the folder Bluetooth-System-Monitor/host_python, where you downloaded the Sketch, and install the required Python modules:
pip install pyserial
pip install psutil
pip install pythonnet
Once the module is installed correctly, open “windows_host.py” in your favorite code editor. I like to use VSCode, but SublimeText or others will also work.
Here, you must edit at least one line of code.
connection = serial.Serial('COM16')
As shown in the image, this is the COM port that the script will send data to. Make sure it is between quotes and uses capital letters. You can change the drive letter to another drive to report its free space. But this step is optional. Save the changes and you are done!
Make sure that the included .dll files are in the same folder no matter where you run this script from. You will need to run this script as an administrator.
MacOS
MacOs is a little easier than Windows. You don’t need to change the COM port, as it’s the same name on all Macs, so there’s no need to edit the script. If you want, you can change the disk’s reporting of free space, and edit the polling time.
On Windows, you need a .dll to read the information, but on MacOS, this can be done with Python. You only need to install two modules. Open a terminal and navigate to the folder where your Python script is located. Install the following two modules:
pip install pyserial
pip install psutil
On MacOS, use
sudo python macos_host.py
To run, you need to run this script as an administrator.
3D Printed Enclosure
This case is designed to be pressed in. Finally use super glue to firmly attach the top to the bottom.
The 3D printable shell file link is:
https://www.thingiverse.com/thing:4661069
You can also download it in this project’s document library:
https://make.quwj.com/project/404
My shell is printed in PLA with a layer height of 0.2mm. If you print it face down, no support is needed on the top. If you print it with the opening facing down, some very small support is needed on the bottom. Of course, you can design the shell according to your own preferences.
For ESP32 TouchDown, you can also refer to the following links:
https://github.com/DustinWatts/esp32-touchdown/tree/main/Case
Finally, the assembly is complete and it can be used!
The code used in the project can be downloaded from the project file library:
https://make.quwj.com/project/404
via instructables.com/Bluetooth-System-Monitor-ESP32-TFT-Screen/