DevCon23 - Introduction to Bluetooth Low Energy Development in Embedded Systems

Show video

All right, my name is Mohammad Afaneh from Novelbits. And today we'll be talking about Bluetooth Low Energy technology. So first, we'll start off with just an introduction of myself and my company. We'll also talk about what is Bluetooth and cover the differences between Bluetooth Low Energy and the Classic Bluetooth that we're familiar with from the years of using audio streaming.

We'll take a look at the history of Bluetooth, how it progressed over the years. We'll cover just a high level technical overview of Bluetooth. Then we'll get into the advantages and disadvantages of BLE and then look at BLE development, how you would use BLE, some of the challenges that you would face with developing BLE applications and devices. Finally, we'll take a look at what Espressif offers in terms of BLE chipsets, and I'll leave you with some resources towards the end. So let's get started.

So first, an introduction of me. My name is Mohammad Afani from Novelbits. And I started Novelbits in 2015 with a focus to help Bluetooth Low Energy developers, and developers in general, embedded developers specifically, to learn about Bluetooth Low Energy development through blog posts, video courses, and a private online membership that I call the Bluetooth Developer Academy. And some of the projects I've worked on over the years included Smart Door locks, BLE gateways, walkie-talkies, Bluetooth beacons, and a lot more. And I've also consulted with the Bluetooth Special Interest Group, which is the group, the standard organization behind Bluetooth. And recently, I also published a second version, second edition of my book on Intro to Bluetooth Low Energy.

So let's take a look at what is Bluetooth, what it is, how it began. So in the beginning, Bluetooth began in 1994, around that time with Ericsson, and around 1999, the Bluetooth Special Interest Group was formed, which is a company, the standard organization behind the Bluetooth standard. So it's more about combining a number of members from companies and they came together and created this Bluetooth standard. And the first version, version 1.0 was released in 1999.

In the beginning it was really just a cable replacement use case. So it was used for making keyboards and mice wireless instead of wired and also connecting PCs with handheld PDA if you're as old as me and you can remember those. Followed by that the Bluetooth started to get used in audio streaming and headset devices.

So this became a lot popular, a lot more popular when there were laws around using the headset for the handheld and the smartphone in your car and you needed to be hands free. And that's where Bluetooth started to get really popular in the car and then also in audio streaming and wireless speakers. Now, all this up to now was originally the original Bluetooth, and this is referred to as Bluetooth Classic or BR/EDR, Basic Rate and Enhanced Data Rate. In Bluetooth Low Energy, that was introduced in Bluetooth version 4.0

and this is back in 2010, so almost 13 years ago. And Bluetooth Low Energy, just to keep in mind, is very different from Bluetooth Classic. They just share a few things, but overall they're incompatible with each other. So Bluetooth Low Energy is more of a low-power wireless technology. So it's focused on IoT applications, Internet of Things applications, and it's ideal for applications that just need to transfer small amounts of data and in very short periods of time. Also focused on lower speeds.

A lot of these devices that would utilize Bluetooth Low Energy will actually not send a lot of data and they'll be more sensor oriented or sensor focused. They also need to run on batteries for long periods of time. So they require low power consumption and hence the low energy part of the name, Bluetooth Low Energy. And typically they've been short range, although that has changed over the years and there are more options now for achieving much longer range than it was originally designed for. And finally, for a lot of the personal devices, especially with wearables and fitness trackers and such, you could use a, when you want to use a smartphone as more of an interface, Bluetooth Low Energy serves as a great interface and a great wireless technology because it's embedded in 100% of smartphones these days.

So let's take a look at the differences and some of the similarities between BLE and Classic Bluetooth. So I hope you can see this table. It's a lot of text, but I'll just read through a lot of the highlights from it. So the usage again, Classic Bluetooth was used in a lot of streaming application and still is and audio streaming and sometimes for file transfers. Bluetooth Low Energy was primarily for sensor data, controlling devices, and low bandwidth applications.

However, it has changed over the years and there is a new standard for streaming that was just released last year. It's called LE Audio, and it will soon replace Bluetooth Classic. I would say not very soon, but maybe in the next five to 10 years, it will be replacing Bluetooth Classic with a lot more features and a lot more innovative use cases for it. The data rate for Classic, it's up to 3 megabits per second.

For Bluetooth low energy, it's up to 2 megabits per second at the moment. Power consumption, again, Classic is much higher power consumption versus BLE is focused on low power consumption and increased prolonged battery life. The RF channel spectrum, there are 79 RF channels that are each 1 megahertz wide for Bluetooth Classic. With BLE, it's 40 RF channels, and they're spaced out 2 megahertz apart. The discovery, device discovery, occurs on 32 channels in the case of Classic, whereas it's on three primary channels in the case of BLE. So this makes it much quicker to discover a device and much quicker to connect.

Again, the audio streaming, currently, most of, if not 99% of audio streaming applications use Classic Bluetooth. However, as I mentioned, there is a new standard called LE Audio that will eventually replace Classic Bluetooth. This allows you to achieve the same use cases and applications that you could use Bluetooth Classic for at the moment. But it also introduces a lot more new and flexible use cases, such as broadcasting audio, standardizing the hearing aid industry and the hearing aid devices.

So you can use multiple hearing aids from different companies and different vendors, and they will be interoperable, and they operate together and without any issues. Let's get to the range. The range is up to around 100 meters for Classic. Whereas with LE, there are a lot of options that are added in terms of being able to increase the range, in terms of transmit power, and then using a long-range mode that you can actually achieve up to over one kilometer of the range in line of sight. And there have been a few videos on YouTube from different vendors that showcase this. So you can look that up as well.

In terms of topology, Classic has been traditionally just a point to point, peer to peer, whereas with BLE, there's options for star topology and doing broadcast and also mesh and doing many to many. So that's just an overview of the differences. There's a lot more differences that we can, we don't have the time to go through today. So let's take a look at the history of Bluetooth, how it progressed over the years and what kind of changes were introduced over the years in the specification. So 1999 again, this was when Classic or BR/EDR was first released. This was version 1.0 and Low Energy or BLE

was introduced in version 4.0 in 2010. In 2011, Apple announced and released the iPhone 4S, which was the first smartphone in the market to support BLE. Now that was in addition to Classic Bluetooth because that was widely supported in smartphones, but this was the first dual mode smartphone that supported LE. And that really opened up the space for a lot of new use cases where like fitness trackers and wearables and smart watches that all started when BLE was introduced because it allowed devices to run on batteries for much longer periods of time. In 2013, Apple also announced the iBeacon standard And iBeacons or Beacons in general are just broadcasting BLE devices that allow you to discover them.

And they are used a lot in retail marketing, asset tracking, and sometimes in even in-door navigation applications where GPS might not work that well. In 2016, there was a new version, probably the biggest update to BLE since 4.0 at that point, and it's Bluetooth 5.0. And that introduced two different modes.

One is for achieving double the speed, so it went from one megabit per second to two megabits per second. And this was at the radio rate, so it's not 100% going towards the application data rate or what you can achieve at the application layer, but it introduced the PHY the physical layer radio data to be double the speed at 2M, and then also introduced a long-range mode, which you can achieve up to four times the range of using the 1M PHY. In 2017, Bluetooth came into the space of many-to-many or mesh topologies in order to compete with Zigbee and Thread and all the other competitors in that space. Specifically, there's been a focus with Bluetooth Mesh on commercial lighting.

And then in 2019, Bluetooth announced 5.1, which included direction finding. This uses angle of arrival and angle of departure. 2020, Bluetooth 5.2 was announced,

and this introduced Isochronous channels, which is basically the foundation for LE Audio, the new Bluetooth Audio standard. Now this didn't coincide with the actual LE Audio standards yet. Those were released a couple of years later. So in 2021, Bluetooth 5.3 was announced

with very little feature updates. One of them was just called Connection Subrating that helped also achieve the LE Audio standard. So in 2022, that's when they completed specs of LE Audio. So LE Audio really builds on top of BLE, but it has its own specs. It has up to, I think, 22 specs on its own.

So it's a big standard, but it's very ambitious and has a lot of potential for the future of Bluetooth Low Energy. In 2023, just earlier this year, Bluetooth 5.4 was released with a new update with some new features highlighting periodic advertising with responses. These are just a new mechanism for doing advertising and broadcasting at scale, but also getting responses back so it's now bidirectional. Think of it, really the main use case for this has been in electronic shelf labels. So where you have grocery items or even items in a department store where they have labels that display the price and the name, you can update those from a central location within the department store and do it in real time.

And looking at the future of Bluetooth Low Energy, there's a lot going on, a lot that is, you know, going to happen with Bluetooth. Some of them, some of the new features that are looking to be included include high accuracy distance measurement, significant data rate increases, even above the two megabits per second. And also going into the higher frequency band.

So we know Wi-Fi is already in the 5 GHz band and Bluetooth is actually exploring the path or the opportunity to go to the 5 or 6 GHz spectrum. So let's just take a very quick overview of the technical facts about BLE. So first, again, it operates in the 2.4 GHz.

That's the unlicensed ISM band. So this is global, and it's available for any technology to use without any licensing. It has a mandatory 1M PHY.

This is at the physical layer, the radio. And this has been the standard since the very beginning of VLE since version 4.0. Then it also has an optional 2M PHY. And this is used for the high speed data mode and also has a coded PHY. This is used for the long range mode, which can achieve up to one kilometer or even more line of sight. Finally, the RF spectrum is kind of split up into two different types of channels.

And three of them are called the primary advertising channels. This is where the discovery happens. This is where the device discovers another device and decides maybe to connect to it and establish more of a bi-directional communication between the two devices.

And then we have what's called the general purpose channels. And these are used for either what's called secondary advertisement or for data exchange during a connection. And you'll notice the 37, 38 and 39, those are the primary advertising channels, they're spaced apart in a different, in a weird way, but it really comes to light when you understand that they are actually placed apart in a way to avoid the Wi-FI channels, channels one, six and 11, the most popular Wi-FI channels in order to reduce any interference and make it more, you know, being able to coexist with Wi-FI in that space, in that spectrum. So let's take a look at some of the advantages and disadvantages of using BLE as a technology. So the advantages, it has lower power consumption and even compared to other low power wireless technologies.

There's also no cost to access the official specification documents with some other competitor wireless technologies, especially low power, you have to join some kind of organization and you have to pay fees in order to become a member and access the specification documents With Bluetooth, it's all available online. You can download it at any time, and you can just go through the spec, the 3,000 plus pages of the spec by yourself without having to pay a single dollar. There's also low cost of modules and chipsets, and this is even going down even lower and lower. There's low cost of licensing and certification. You can become a member with a nominal, you know, some fee for a year or so, and then you can get some discounts for certification as well. And there's also 100% support in smartphones and there's no other really low power technology that can compete with this at the moment.

In terms of disadvantages, again, data throughput is a little bit limited, especially when you want to achieve low power consumption. So the raw data transfer of rates can range from 250 kilobits per second to two megabits per second. And again, this is at the radio level. So when you take into account headers and gaps and a lot of overhead, it comes down to maybe 1.3, 1.4 megabits per second at the application layer. And this is using the high speed mode.

In terms of range, again, it was designed for short range communication. So if you want to achieve the low power consumption aspect of it, then you might want to stick to, you'll be restricted with the range that you can achieve with your application. However, if you do have a little bit more in terms of power consumption that you can sacrifice, then you can go longer range and achieve much better ranges. And the last one is finally just having, or the need to have a gateway or some kind of proxy device in order to send the data from a BLE device to the internet because there's no IP connectivity. So again, why would you choose BLE as a developer, as a project manager for your project? I think Bluetooth has really proven that it has a track record and credibility.

The name, the brand is known by almost every person. I mean, it's a consumer brand as well. So that helps the brand, even though it's getting, you know, going into different markets and even industrial and manufacturing. It's also truly globally interoperable. So you can run it and you can license that technology and employ it in your devices anywhere in the world and they will work with each other as long as it's certified and with the Bluetooth SIG. The Bluetooth SIG also has full control over the technology stack.

What this means is if you compare that to some other technologies that might rely on IEEE as the standard, then they have to go back to the IEEE standard and be able to, if they want to make changes, they have to go back to that standard body and propose these changes and wait for that to happen. With Bluetooth, they can just make changes at any stack, any level of the stack, without having to go back to any other standard body. There's also, again, ubiquitous support on smartphones, so it's 100% supported on all smartphones these days. There's also continuous improvement and innovation in the spec and updates. It allows you to introduce, you know, it introduces a lot of flexibility for developers, so some of the features that were introduced are optional, but they allow a lot more flexibility for for developers to tailor it towards their application use case. And again, as a developer, if you are learning Bluetooth Low Energy, this is a technology that can be applied across many industries.

So your learning and your efforts do not go to waste. In terms of BLE development, just a few slides on that to look at the different development aspects as well, some of the challenges. So there are three main types of Bluetooth Low Energy platforms. We can think of Microcontrollers, Smartphones and Desktop Apps. And sometimes the Linux devices, such as gateways and routers might be grouped with microcontrollers, although they're kind of in between desktop apps and microcontrollers. Microcontrollers and chipsets often give you the most flexibility that they can, they also give you usually the latest and greatest of the features, even the optional ones that are available with Bluetooth.

Desktop applications can be challenging just because there are differences between the different APIs that are available on the major operating systems. In terms of smartphones, there are restrictions, a lot more restrictions than what you can do with microcontrollers, so on iOS and Android and iOS even more than Android. So in terms of specification versions, just a few notes on that. So again, Bluetooth Classic or BR/EDR and Bluetooth Low Energy, they share the same specification. This is a specification that's over 3,000 pages, and it's all kind of mixed together in there.

So it can be difficult sometimes to navigate through that and find what's relevant really for BLE versus Classic. Also, another note is that Bluetooth, the version of Bluetooth does not really indicate whether LE or Classic is supported by a chipset. So if you see a chipset that says 5.0, it doesn't mean that that's Classic or that's LE.

You have to go and look at the data sheet and find out whether LE or Classic are supported or whether it's actually dual mode. A lot of the features are optional. So again, we mentioned like the two new features that were added in 5.0, which is long range and the high speed mode.

Both of these were optional. So it doesn't mean that if you find a chipset that supports 5.0, that that means that these options are available. You just have to make sure that they are through looking at the data sheet or contacting the vendor. Mesh is also another spec, and this was added as a standalone spec, so it's actually not compatible with LE. It is compatible with LE, but it's not embedded or built in with any LE device.

So it has to be added. It is backwards compatible all the way up to Bluetooth version 4.0 with Bluetooth Low Energy, so it does require BLE, but it also requires an additional layer on top of that in order to support it at the firmware level. And it also has to be qualified if the device needs to be Bluetooth Mesh certified with the Bluetooth SIG. So again, on smartphones, some of the challenges - iOS and Android SDKs have restrictions. There's also a wide diversity of Android devices, so there's gonna be a lot of testing that you need to do to make sure that your app may be running on an Android device is compatible with your device, and it's operating and running and functioning properly.

There's also changes in mobile OS releases that might affect the application, the BLE application, due to changes in stack or some changes in the APIs themselves. On microcontrollers, there can be a steep learning curve, especially when trying to learn the APIs, the SDK that's involved. So in addition to learning, Bluetooth Low Energy itself, you have to learn how to use the SDK and the APIs. And a lot of vendors will provide good examples of using those. So it's not always the case, but it's just something to keep an eye out for. There's something called services and characteristics in Bluetooth Low Energy specifically.

And it's basically just a way to structure the data that your BLE device exposes to another device. And designing this can be a challenge sometimes, and specifically to satisfy the requirements. So that's one of the challenges that you might face.

Debugging BLE can be difficult at times, and it can be made a lot easier with a Bluetooth sniffer. The problem is some of these Bluetooth sniffers, if you are really looking for one that's reliable and it can support a lot of features, it's going to run you at least $10,000, $15,000, all the way up to maybe $70,000 or $80,000. So it's not a cheap investment. Then optimizing for range, data throughput, power consumption, and optimizing for multiple connections, these are all things that usually come up with a BLE application or developing a BLE device.

And in a lot of times, one or two of these will have to be sacrificed in favor of the other two. So let's take a look at what Espressif offers in terms of BLE chipsets. So we have a few options actually. The ESP32 is probably the one that everybody's most familiar with.

This is the original and it included Bluetooth 4.2. So again, this doesn't mean that it's just BLE or Classic. And in fact, this is a dual mode chipset. So it supports both BLE and Bluetooth Classic. Also included Wi-FI, which is very common across the ESP32 chipsets.

ESP32-C2, this one includes 2.4 GHz Wi-FI as well, and it's Bluetooth 5.0, so it's qualified up to version 5.0 as of this recording, and it's BLE is supported only, there is no Classic, but it does support the coded PHY and the 2M PHY, so those are the long-range mode and the high-speed mode, which are optional features in 5.0.

We also have the C3 series, which is similar, It supports Wi-Fi, Bluetooth 5.0, and it's BLE only, so there's no Classic, but it does support Bluetooth Mesh, and it has the two optional features from Bluetooth 5.0, coded PHY and 2M PHY, similar for C6, except this is Bluetooth 5.3 certified.

And then finally, we have the new H2 series, which actually drops the Wi-Fi support, but supports the IEEE 802.15.4, so think of Thread and Matter technologies, but it also supports Bluetooth Low Energy, so it's BLE only, supports Bluetooth Mesh, and it's Bluetooth 5.3 certified, and also includes support for the coded PHY and 2M PHY. Again, the last one is S3. This is a Wi-Fi plus BLE chipset, and it's Bluetooth 5.0, has Bluetooth Low Energy only, and supports Bluetooth Mesh, but also has the coded PHY and the 2M PHY.

In terms of resources, So just to let you know about a couple more resources, if you want to learn more about BLE. So I have a new book, a second edition of my original book, which was originally in 2018, released in 2018. So I just have a new edition of that intro to Bluetooth Low Energy. And the title really for this is, the goal is to help you learn Bluetooth Low Energy in a single weekend.

And if you want to learn more about it, just go to learnblutooth.com and finally, I have an online membership, and this is a private membership that you can gain access to via the website, novelbits.io/academy it includes video courses, as well as access to me personally and a few other experts in the Bluetooth space via a private forum. So that's where a lot of my content, the new content that I add goes into. It goes into the academy.

Thank you all for watching. I appreciate it and I'll be ready for any questions.

2023-09-22

Show video