This project will demonstrate the Bluetooth Low Energy (BLE) connectivity of the MAX32666FTHR microcontroller, explain advantages of BLE over standard Bluetooth, and showcase an example use case with an IoT node. This microcontroller comes with a built-in BLE stack so creating a BLE connection and application is super easy. But first let's look at BLE basics.
Bluetooth Low Energy (BLE) BasicsBluetooth Low Energy is a similar but different protocol than standard Bluetooth. This means that devices that can connect to Bluetooth won't always be able to connect to BLE as well, so keep that in mind when choosing a device to connect to the microcontroller.
To first establish a connection, one device advertises its services at a predefined interval, which just means that it periodically sends out information about what it can do and the data it has. If another device is listening, it can send a connection request or just pull the data out of the advertisement.
The main advantage of BLE is low power consumption, hence the name. It achieves this in many ways such as longer advertising intervals, sending smaller packets, slower modulating schemes, shorter connection durations, connection-less and multi-connection networks, and advanced controls for developers to optimize parameters for each application. The power savings can be further increased using the microcontroller low power mode as discussed.
BLE is able to send data in more ways than standard Bluetooth. It can connect point-to-point, data broadcast, or in a mesh network, whereas Bluetooth can only connect point-to-point. Broadcast and mesh networks are advantageous because they help to save energy and improve range over normal point-to-point.
There are three main roles that each device can play in a BLE connection: central, peripheral, and broadcaster. The central and peripheral may also go by the names client and server, respectively. The roles aren't limited to these, for example in the mesh network there are many more.
- Central: The central is able to connect to multiple other devices and is considered the 'Master' of the connection. It listens for the advertisements and sends requests.
- Peripheral: The peripheral advertises its services and is able to accept connection requests from centrals. It is only able to connect to one central at a time.
- Broadcaster: This type of device sends its data without making a connection by sending the data in the advertisement. A central is still able to send requests to this type of device but no connection is needed.
BLE isn't able to achieve lower power consumption without drawbacks though. BLE 5.0 has a throughput of only 1.4 Mbps which is slow compared to Bluetooth's maximum throughput of 20 Mbps. However, the lower throughput is usually not a problem since the applications for BLE, like sensors, don't require high throughput.
For more information on the basics of BLE, watch this video series! There are 7 parts so go to YouTube for more.
What is an Internet of Things (IoT) Node?Before looking at the example IoT node, first it's important to understand what an IoT node is. An IoT node is a physical device or sensor that is connected to internet or other network to share data with other IoT devices on the network. Each node can have a special purpose depending on the network. For example, BLE mesh networks can have 'relay nodes', 'proxy nodes', 'low power node', 'publisher node', and so on.
For the example IoT node below, the node consists of two microcontrollers, a sensor, and actuators in the form of servos. One of the microcontrollers handles the BLE connection, talking to the sensor, and has low power consumption. The other handles PWM generation for the servos, which uses a lot more power
System SetupThis example connects a PC running a python GUI to the MAX32666FTHR over BLE. The MAX32666 can be configured as the central or peripheral, but for the sake of the demonstration and ease of use, it acts as the peripheral and the PC is the central. The MAX32666 can read data from the MAX31865 temperature sensor or forward data to the MAX78000 microcontroller. The MAX78000 controls a robot arm made with servos. Since this is an example application the temperature sensor, MAX78000, and or robot arm can be switched out for your application. Also, more BLE nodes could easily be added to expand the network.
For the pinout of each board, check the links below:
MAX32666FTHR Application Platform-Evaluates: MAX32666 (analog.com)
MAX78000FTHR Application Platform-Evaluates: MAX78000 (analog.com)
Notes:
- Both jumpers on the MAX31865pmb1 board should be connected
- Only one servo actually needs to be connected for the demonstration to work, there are six because that's how many are in the Robot Arm shown below
I used the Maxim Software Development Kit, Eclipse, to code the microcontrollers. If you want to use this as well to flash your microcontrollers or change the code, here is a pdf document to help with Eclipse.
getting-started-with-eclipse.pdf (analog.com)
Refer to the GitHub link to find the latest version of the code.
Microcontroller Low Power ModesTo make further use of the low power consumption of the BLE protocol, we can use low power modes on the MAX32666 microcontroller, which are sleep, deepsleep, and backup mode. In this project, only the sleep mode is utilized, but I will explain the benefits of deepsleep and situations to use it. Note: for this example, only the MAX32666FTHR and MAX31865 are optimized for low power consumption, the MAX78000 and robot arm servos will consume a lot more power.
In sleep mode, the CPUs in the microcontroller are turned off, and everything else, including the BLE stack is left on. This allows for some power savings, while still being able to maintain a BLE connection. Since the MAX32666 is using a point-to-point connection in this project, sleep mode was utilized so that connection could be maintained.
Indeepsleepmode, everything is turned off except what is necessary to turn the microcontroller back on. This means HUGE power savings, from approximately 21.5 mW to 43 uW. This also means that the BLE stack is turned off so a connection cannot be maintained in deepsleep mode. However, this would work great for a connection-less device role, like a broadcaster, where the device only needs to stay awake for long enough times to advertise/publish their data and respond to any requests that come in before powering off again.
Each servo is controlled using a dedicated pulse width modulated signal. For a standard servo, the pulse lasts between 500 and 2500 microseconds, which corresponds to 0 and 180 degrees respectively. The robot arm has six servos, so six PWM signals need to be generated, but the MAX78000 only has four timers.
This discrepancy can be solved using the dual one-shot mode of the timers. 'Dual' means that the timer registers are split into the upper 16 bits and the lower 16 bits so that each timer effectively work as two timers. 'One-shot' means that the output of the timer is only enabled for one clock cycle.
I set up 3 of the timers to be in dual one-shot mode and left the last timer in continuous mode. The output of the continuous timer is used to turn the PWM signals high and start the six one-shot timers. The output of each one-shot timer is used to turn off its respective PWM signal.
This project demonstrates the basic features of BLE, which still means there is a lot left on the table to experiment with and add. My ideas include adding support for broadcasting or mesh networks, security/encryption of data, over-the-air updates, testing throughput of BLE stack, and possibly incorporating the convolutional neural network (CNN) built into the MAX78000.
Broadcasting or Mesh Networks: Currently my application connects point-to-point and doesn't use either of the network types unique to BLE. Also, incorporating either of these would help with range and power savings.
Security/Encryption: The MAX32666 microcontroller has a Trust Protection Unit (TPU) which is used for encryption and decryption. Using this to encrypt data before sending over BLE would help to make a more secure transaction. The MAX78000 also has an AES encryption block which could be used.
Over-The-Air Updates: BLE has the capability to update the microcontroller firmware wirelessly, which can be used if it is impractical or impossible to plug a wire into the microcontroller.
Convolutional Neural Network: The MAX78000 has a built in CNN and examples for face recognition and more. The face recognition embedding could be sent over BLE to the PC which can then do the processing to figure out if the face is known or not.
Comments
Please log in or sign up to comment.