element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Design For A Cause 2021
  • Challenges & Projects
  • Design Challenges
  • Design For A Cause 2021
  • More
  • Cancel
Design For A Cause 2021
Blog MicroGrid Connection Unit #5: BLE on the Nano33 IoT
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: makervanlabs
  • Date Created: 19 May 2021 9:14 PM Date Created
  • Views 931 views
  • Likes 4 likes
  • Comments 0 comments
  • ble
  • hardwarebleserial
  • arduinoble
  • adafuit bluefruit
  • arduino libraries
  • arduino nano 33 iot
  • design_for_a_cause_2021
Related
Recommended

MicroGrid Connection Unit #5: BLE on the Nano33 IoT

makervanlabs
makervanlabs
19 May 2021

I've been thinking about how to connect the MicroGrid Connection Unit with a smartphone or similar device to read data or write configuration. The Arduino Nano 33 IoT offers both BLE and WiFi connectivity, but from my understanding they cannot be used at the same time unfortunately. Building something that presents a website using WiFi might be simpler, but it also feels a little bit inconvenient to connect to a dedicated WiFi network just to interact with the connection unit. So I decided to evaluate BLE, as I've never done anything with it on an Arduino before.

Updating the WiFiNINA module

The Nano 33 IoT uses a separate module for the WiFi and BLE connectivity, with its own firmware. Some of the guides and tutorials mention that this might be outdated when you receive the Nano 33 IoT, so I went ahead to update it. Thankfully, javagoza already wrote a great blog post about how to do that, which you can find here: VenTTracker #09 - Checking and updating WiFiNINA Firmware. He describes the process on Windows, but it's almost identical on macOS. Now, instead of running on firmware version 1.2.3, we're on the latest release, 1.4.5. On to the BLE part.

 

ArduinoBLE library

Arduino provides a library to interact with the BLE side of the WiFiNINA module, called "ArduinoBLE", which you can find in the Arduino Library Manager:

image

It comes with a few examples, like a simple example on how to control the builtin LED of the Nano 33 IoT board via BLE.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

To control the Arduino and its LED from my phone, I'm using a dedicated app called "LightBlue", which is available for both Android and iOS. It allows you to connect to a BLE devices, and read and write values to it. Not really convenient, but it still works surprisingly well.

 

UART via BLE

The other smartphone app I found that looked interesting is "Bluefruit" by Adafruit. They have a wonderful tutorial on how to use it: https://learn.adafruit.com/bluefruit-le-connect

 

It's really targetted at their line of BLE devices, based on nRF BLE chips, and makes use an nRF specific emulation of UART communication via BLE. Thankfully, there's another library out there to emulate exactly this protocol using the ArduinoBLE libary, called "HardwareBLESerial".

image

The library works great, but the examples didn't convince me, so I wrote my own:

#include <HardwareBLESerial.h>

HardwareBLESerial &bleSerial = HardwareBLESerial::getInstance();

bool connected = false;
bool hello_worlded = false;

void setup() {
  if (!bleSerial.beginAndSetupBLE("Nano33IoT UART Test")) {
    Serial.begin(9600);
    while (true) {
      Serial.println("failed to initialize HardwareBLESerial!");
      delay(1000);
    }
  }
}

void loop() {
  // this must be called regularly to perform BLE updates
  bleSerial.poll();

  if (connected) {
    if (!bleSerial) {
      Serial.println("BLE central disconnected");
      connected = false;
    } else {
      while (bleSerial.availableLines() > 0) {
        Serial.print("Received data: ");
        char line[128]; bleSerial.readLine(line, 128);
        Serial.println(line);

        if (!hello_worlded) {
          Serial.println("Sending Hello World (once only)");
          bleSerial.println("Hello world!");
          hello_worlded = true;
        }
      }
    }
  } else {
    if (bleSerial) {
      Serial.println("BLE central connected");
      connected = true;
      hello_worlded = false;
    }
  }

  delay(500);
}

Now this is what that would look like in the Bluefruit App, and in the Arduino Serial Monitor:

 

{gallery} HardwareBLESerial and the Bluefuit App

image

Selecting the Nano33 IoT: In the Bluefruit App, you first need to select the device to connect to. I've filtered out the UART capable devices only, so it shows just the Nano33 with my example sketch

image

Connecting to the Nano33: Connecting to the Nano33 IoT can take a few moments

image

Different options to interact with the Nano33: After connecting to the Nano33 IoT, you can choose different modules to interact with the BLE device. I chose UART here.

image

The UART terminal: Now I can send and receive text via the UART terminal. Bold text is messages sent from the smartphone, regular text message received from the Nano33 IoT

image

Arduino Serial Monitor: This is what that communication looks like from the Arduino Serial Monitor

 

The plotter is nice to visualize any sensor readings. Unfortunately, it doesn't work well if you plan to send other stuff across the serial connection, so I'm not sure it'll be all that useful to me.

 

There are a number of other apps for BLE around, like the nRF Toolbox, or Blynk, but this was only my first introduction, and I think I can use the UART quite well for now.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube