|
Forum Index : Microcontroller and PC projects : LCD Visual Design Studio Free browser-based UI builder & C++ generator
| Author | Message | ||||
| Batteryman Newbie Joined: 05/04/2016 Location: United KingdomPosts: 32 |
Hi all, I have added Bluetooth support to the ESP32 Visual Studio web designer. This allows an ESP32 or ESP32-S3 (including the Cheap Yellow Display and CrowPanel boards) to exchange serial data with a smartphone, tablet, or PC without needing an existing Wi-Fi network. Key details: BLE UART (Default): Uses the standard Nordic UART Service (UUID 6E400001-...). This connects out-of-the-box on both Android and iOS without needing PIN pairing or custom phone apps. You can use standard terminal apps such as: Android: Serial Bluetooth Terminal (Kai Morich) iOS: Adafruit Bluefruit LE Connect or nRF Connect Classic Bluetooth Serial (SPP): Optional mode available for standard ESP32 boards where a traditional RFCOMM COM-port serial link is preferred. Events & Methods: Works through standard event handlers: Bluetooth1_Connected() Bluetooth1_Disconnected() Bluetooth1_Receive() — incoming text is read via Bluetooth1.Data Bluetooth1.Send(text) and Bluetooth1.SendLine(text) Bluetooth1.IsConnected (Boolean) Simulator support: You can test your code directly in the browser Run Preview before exporting or flashing. Opening the Bluetooth drawer under the virtual screen lets you connect a simulated phone, type incoming text, and view responses from the board. Example code to try: You can test this right now in the web editor without placing any controls by hand. Paste the code below into a blank VB Code tab. The .Create() statements in Form_Load will automatically instantiate the Bluetooth control, screen labels, indicator shape, and send button. ' ESP32 Visual Studio - Bluetooth / BLE Demo ' Connect using 'Serial Bluetooth Terminal' (Android) or 'Bluefruit LE' (iOS) Private Sub Form_Load() ' Auto-create screen controls Label1.Create 15, 12, 290, 24 Label1.Text = "Bluetooth: Waiting..." Label1.Font = 2 Shape1.Create 15, 45, 290, 30 Shape1.Text = "LED: OFF" Shape1.BackColor = RGB(40, 40, 40) Shape1.ForeColor = RGB(160, 160, 160) Label2.Create 15, 88, 290, 45 Label2.Text = "Rx: (none)" Label2.Font = 1 Button1.Create 15, 145, 135, 40 Button1.Text = "Send Status" Button1.Font = 1 Button2.Create 165, 145, 140, 40 Button2.Text = "Toggle LED" Button2.Font = 1 Label3.Create 15, 198, 290, 30 Label3.Text = "Type 'on', 'off' or 'ping' in phone app" Label3.Font = 1 ' Auto-create Bluetooth control (advertises as ESP32-Studio) Bluetooth1.Create 0, 0, 0, 0 End Sub Private Sub Bluetooth1_Connected() Label1.Text = "Bluetooth: Connected" Label1.ForeColor = RGB(0, 200, 0) Bluetooth1.SendLine "Hello from ESP32 Studio!" Bluetooth1.SendLine "Commands: 'on', 'off', 'ping'" End Sub Private Sub Bluetooth1_Disconnected() Label1.Text = "Bluetooth: Disconnected" Label1.ForeColor = RGB(200, 50, 50) End Sub Private Sub Bluetooth1_Receive() Dim msg As String msg = Bluetooth1.Data ' Show received text on the display Label2.Text = "Rx: " & msg ' Parse basic commands sent from the phone terminal If msg = "on" Then Shape1.Text = "LED: ON" Shape1.BackColor = RGB(220, 180, 0) Bluetooth1.SendLine "ACK: LED is now ON" ElseIf msg = "off" Then Shape1.Text = "LED: OFF" Shape1.BackColor = RGB(40, 40, 40) Bluetooth1.SendLine "ACK: LED is now OFF" ElseIf msg = "ping" Then Bluetooth1.SendLine "pong" Else Bluetooth1.SendLine "Echo: " & msg End If End Sub Private Sub Button1_Click() If Bluetooth1.IsConnected Then Bluetooth1.SendLine "Status: " & Shape1.Text Else Label2.Text = "Rx: Not connected" End If End Sub Private Sub Button2_Click() ' Toggle the visual indicator from the touchscreen If Shape1.Text = "LED: ON" Then Shape1.Text = "LED: OFF" Shape1.BackColor = RGB(40, 40, 40) Else Shape1.Text = "LED: ON" Shape1.BackColor = RGB(220, 180, 0) End If If Bluetooth1.IsConnected Then Bluetooth1.SendLine "Touch update: " & Shape1.Text End If End Sub How to test it: In the browser: Click Run, expand the bluetooth: advertising drawer at the bottom of the virtual screen, and click Connect phone. Type on, off, or any text into the box to test the two-way link. On hardware: Click Export ZIP, extract, open the .ino in Arduino IDE, and upload to your ESP32 or ESP32-S3. Open your mobile BLE terminal, scan for ESP32-Studio, and connect. Feedback and bug reports welcome. Peter ESP32 LCD Design Studio - link |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |