Maker.io main logo

Build a Pocket Bluetooth Controller with LED Status Indicators

2023-01-18 | By Don Wilcher

License: See Original Project 3D Print Accessories

M5Stack is an Internet of Things (IoT) modular platform. The intent of this platform is to allow ‎makers to rapidly create electronic devices that can connect to wireless networks and hubs. The ‎M5Stack Core 2 module can easily connect to Bluetooth or WiFi networks using wireless ‎communication chipset technology. The wireless communication scheme for Bluetooth or WiFi ‎can be developed using a blockly code software platform known as UiFlow. ‎

An Application Programming Interface (API) for the Arduino Integrated Development ‎Environment (IDE) or the MicroPython programming language can allow the building of ‎M5Stack Core 2 wireless devices. This project will show you how to build a pocket Bluetooth ‎controller using the M5Stack Core 2 and 2-channel relay unit with LED status indicators. Read ‎below for the BOM and step-by-step instructions on how to make this yourself!‎

The ESP32 Microcontroller Bluetooth Chipset

The M5Stack Core 2 uses an ESP32-DOWDQ6-V3 microcontroller incorporating a 240MHz, ‎dual-core microprocessor which provides efficiency in computation and managing input and ‎output (I/O) operations of the microchip using two central processing units (CPUs). Within this ‎family of ESP32 microcontrollers, the chip has a Bluetooth chipset consisting of a link controller ‎and baseband. ‎

The Bluetooth link controller handles the physical layer packets and all communication timing. ‎The link controller implements the signal connectivity (the link), the low-level real-time ‎protocol that operates Bluetooth communications. The baseband is the physical layer of ‎Bluetooth communications, and it manages physical channels and uses other services in ‎communication, like security and error correction. The baseband protocol or operating rules ‎perform the link within the Bluetooth chipset.‎

block_1

ESP32 Bluetooth Chipset Architecture Block Diagram.‎

The clock generator within the Bluetooth chipset architecture is an electronic oscillator that ‎produces a repetitive signal for synchronizing the Bluetooth link controller with the baseband. ‎The RF transmit circuit block allows for sending a modulated signal with the appropriate carrier ‎wave and intelligence data to a designated or paired receiver. The RF receiver circuit is ‎responsible for obtaining the intelligence data from a demodulated designated paired ‎transmitter signal, and the RF switch is an electronic device used to route the 2.4GHz signal ‎received from the designated paired transmitter. ‎

Finally, the balun is an electrical device that converts an unbalanced modulated received signal ‎into a balanced or differential demodulated waveform. Traditionally, the balun is wired to the ‎Bluetooth antenna to achieve a differential or balanced load for RF signal integrity. The balun ‎electrical circuit concept is shown below. ‎

antenna_2

The Antenna Balun electrical circuit concept.‎

The Pocket Bluetooth Controller Concept

The pocket Bluetooth controller concept is that a smartphone or tablet user can remotely ‎operate an M5Stack Core 2 electrically connected to a 2-channel relay unit. The smartphone or ‎tablet is Bluetooth paired with an M5Stack Core 2 module, and the user will be able to interact ‎with the relay unit using a binary digit message. The below image illustrates the pocket ‎Bluetooth controller concept.‎

concept_3

The Pocket Bluetooth controller concept.‎

As seen above, the smartphone or tablet user will provide a binary number “1” or “0” message ‎by entering the value using the free Nordic Semiconductor nrF Toolbox mobile app. The mobile ‎app is available for Android and Apple mobile devices. Typing a “1” into the app’s Universal ‎Asynchronous Receiver/Transmitter (UART) Utils services section will transmit an ON command ‎to the M5Stack Core 2 module. The M5Stack Core module will turn on the two relays. The ‎M5Stack Core 2 side RBG LED bars and the blue LED status indicators on the relay unit will also ‎be on. ‎

Typing a “0” into the UART Utils service section will turn off the electromechanical relays, the ‎blue LED status indicators, and the side RGB LED bars. Electrical AC or DC loads like motors, ‎solenoids, LED bulbs, or small appliances can be operated with this Bluetooth controller device. ‎

Building the Pocket Bluetooth Controller

Building the Pocket Bluetooth controller involves attaching the 2-channel Single Pole Single ‎Throw (SPST) relay unit to the M5Stack Core 2 using a mini-4-wire jumper harness. Attaching ‎the mini-4-wire jumper harness between the M5Stack Core 2 and the 2-channel SPST relay unit ‎will provide electrical control signals, ground, and 5V voltage source needed to operate the ‎electromechanical relays. ‎

Attach the relay unit to the M5Stack Core 2’s port A using the mini-4-wire jumper harness. A ‎circuit diagram and parts list can be found here:

‎https://www.digikey.com/schemeit/project/pocket-ble-controller-with-led-status-indicators-‎‎77c4e3a064274da1afe4b778de3c41c8‎

attach_3

Electrically attaching the 2-channel SPST relay unit to the M5Stack Core 2 module.‎

diagram_4

The pocket Bluetooth controller electrical wiring diagram

 schematic_5

The 2-Channel SPST Relay Unit electronic circuit schematic diagram, Courtesy of M5Stack.‎

You can make the pocket Bluetooth controller a self-contained device using small Lego parts by ‎attaching the 2-Channel SPST Relay Unit to the M5Stack Core 2. The backside of the M5Stack ‎Core 2 provides mounting provisions for attaching Lego parts to it. With such a feature, the ‎controller device can easily be placed in a shirt pocket, a backpack, a purse, or a small ‎electronic case for easy transportability.‎

controller_6 

The pocket Bluetooth controller is assembled for easy transportability.‎

UiFlow BLE Block Code Blocks

The UiFlow BLE code block is centered on the M5Stack Core 2 Universal Asynchronous ‎Receiver-Transmitter (UART) for sending and receiving intelligence data packets. Six primary ‎BLE code blocks within the UiFlow software palette are used for wireless communication ‎activities. ‎

blocks_7

UiFlow BLE-UART code blocks.‎

  • Init blue uart name – used to initialize and configure wireless settings of the specified ‎named Bluetooth device.‎
  • BLE UART write – used to send data using the BLE UART.
  • BLE UART remain cache – used to check the BLE UART number of data bytes.‎
  • BLE UART read – for reading the BLE UART cache data.‎
  • BLE UART read characters – allows reading n-number of the BLE UART cache data.‎
  • BLE UART on recv – allows decoding received data.‎

The UiFlow coding process consists of the following steps: initializing the BLE UART name, ‎establishing the BLE UART conditional logic, and sending the BLE UART data. Note: This project ‎will not provide an overview of the UiFlow software environment. You may obtain an ‎overview of the coding environment by reading the UiFlow - M5Core information from the ‎M5Stack website: https://docs.m5stack.com/en/quick_start/m5core/uiflow

align_8

The BLE implementation coding process alignment.‎

code_9 

BLE implementation code blocks.‎

The code shown above will be downloaded onto the M5Stack Core 2 for implementing the ‎wireless control function of the pocket BLE controller. After loading the code to the pocket BLE ‎controller, the final step is activating the pocket BLE controller using the Nordic Semiconductor ‎nrF Toolbox mobile app.‎

Operating the Nordic Semiconductor nrF Toolbox app

The Nordic Semiconductor nRF application is a toolbox that provides a wide range of popular ‎BLE accessories and profiles. Some nRF BLE profiles include Heart Rate, Blood Pressure, and ‎Proximity monitors. These BLE monitors allow developers to explore user interface (UI)/User ‎Experience (UX) designs and data aggregation methods.‎

example_10 

Example Nordic Semiconductor nRF toolbox app profiles ‎

The profile you will explore will be the Nordic UART utility service profile shown below.‎

profile_11 

The Nordic UART utility service profile

Before starting the Nordic UART utility service profile, the M5Stack Core 2 UI screen needs to ‎be designed. You may customize the fonts and background screen to meet your needs. Further, ‎the message may be changed to suit a more appealing ready prompt.‎

layout_12 

M5Stack Core 2 UI layout

Open the UART utility service app from the installed Nordic nRF Toolbox software. Tap on the ‎UART icon to see scanned BLE devices. Select the Core2-connected device from the list.‎

list_13

List of connected BLE devices

Touching the Core2 listed device shown above will display an OUTPUT window. You will type in ‎the text to send from the Nordic nRF Toolbox app to the M5Stack Core 2 module. Type a “1” in ‎the textbox to turn ON the relay unit, the blue LED indicators, and the M5Stack Core 2 side LED ‎bars. ‎

window_14

Nordic nRF Toolbox UART OUTPUT window

Tap the Send button on the app’s UI to send the message to the M5Stack Core 2.‎‎ ‎ ‎ ‎

send_15 

Sending a Binary “1” to the M5Stack Core 2 module

The actual message displayed on the M5Stack Core 2 is shown below. To turn off the relays and ‎the LED status indicators, type and send a binary “0” to the pocket BLE controller. ‎

message_16 

Operational pocket BLE controller

The following video clip illustrates the operation of the pocket BLE controller: ‎

 

There is truly a world of possibilities out there for BLE controllers, and you now have your own ‎pocket BLE controller!‎

制造商零件编号 K010-AWS
CORE2 ESP32 FOR AWS IOT EDUKIT
M5Stack Technology Co., Ltd.
制造商零件编号 U131
2-CHANNEL SPST RELAY UNIT
M5Stack Technology Co., Ltd.
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum