Push Nano's Button

Push Nano's Button © GPL3+

Nano 33 Sense BLE is loaded with environment monitoring sensors whose data can stream over using Bluetooth or WiFi communication protocols.

  • 748 views
  • 1 comment
  • 6 respects

Components and supplies

Apps and online services

About this project

Introduction

Arduino launches yet another round of innovation for the IoT world. The Nano 33 Sense BLE is loaded with environment monitoring sensors whose data it can stream over to a host using Bluetooth communication protocols. It is the ideal platform to assess mobile solutions that can take advantage of input from gestures and sound. As with the majority of Arduino platforms, development is conducted using the versatile Integrated Development Environment (IDE) or cloud interfaces. The micro-controller for the board is nRF52480 by Nordic Semiconductor.

This note is the first in a series of simple exercises to explore the libraries that interface with the on-board sensors such as:

  • Inertial measurement unit (IMU) with 9 axes (degrees of freedom)
  • Temperature
  • Pressure
  • Humidity
  • Light
  • Color
  • Microphone

Since the sensors are mounted on the board, there is a faster learning curve since debugging connecting wires on a breadboard is redundant. The board used in these exercises came with the headers mounted – again eliminating the need for post-purchase soldering adventures (for the uninitiated). For more custom solutions, one can purchase a model without the headers.

The Microcomputer

This project is the start of several self-paced training exercises that will illustrate the use of the libraries for the Nano 33:

  • NINA B306 for Bluetooth
  • LSM9DS1 for IMU
  • LPS22HB for barometric pressure and environmental temperature
  • HTS221 for humidity
  • ADPS-9960 for proximity, light, RGB and gesture sensor
  • MP34DT05 for microphone

This note examines only the NINA B306library for Bluetooth connectivity.

NINA B306

The chip-set from u-blox for standalone Bluetooth 5 low energy has its antenna radiation patterns illustrated in the corresponding data-sheet. There are 28digital pins.

Power Modes

There are three power modes for the module:

  • Active
  • Standby
  • Sleep

Serial Communication Interfaces

The module supports the following serial communication interfaces:

  • Universal Asynchronous Receiver/Transmitter (UART), 4-wire, 2x
  • Serial Peripheral Interface (SPI),3x
  • Queued Serial Peripheral Interface (QSPI), 1x
  • Inter-Integrated Circuit (I2C), 2x
  • Inter-IC Sound (I2S), 1x
  • Universal Serial Bus (USB), 2.0, 1x

Digital interfaces

There are two key digital interfaces:

  • Pulse Width Modulation (PWM)
  • Pulse Density Modulation (PDM)

PWM

There are 12independent PWM channels to control:

  • Motors
  • Light Emitting Diode (LED)
  • Audio signals

Each channel uses a single General-purpose input/output (GPIO) pin for output signal.

PDM

PDM in the current application is primarily for use with the digital microphone for 16-bit samples at 16 kHz rate. It supports single or dual channel data over a single GPIO pin.

Analog Interfaces

Using 8 from 38 digital GPIOs, the analog operations are supported through the following functions:

  • Analog-to-Digital (ADC), 8-channel, 1x
  • Full swing input range from 0 V to VCC
  • 8/10/12-bit resolution
  • 14-bit resolution with oversampling
  • Upto 200 kHz sample rate
  • Single shot or continuous sampling
  • Two operation modes:
  • Single-ended with a single input pin
  • Differential with two input pins and the voltage level difference between them is sampled
  • Either: Analog comparator, 1x
  • Or: Low-power analog comparator, 1x

Commands

For the limited purposes of this note, the commands are examined for the Bluetooth functions in the sample code only that introduces the client-server operation which in combination with the notify characteristic becomes and publish-and-subscribe model.

Example

The introductory example illustrates the use of the library withthe following classes:

  • BLE
  • BLECharacteristic
  • BLEService

BLE

The primary class in the library to enable Bluetooth services forthe device is BLE (Bluetooth Low Energy or Bluetooth Smart).The key interfaces used in the sample code are illustrated below:

begin

The begin method initializes the BLE device upon which itreturns 1 for success or 0 for failure.

end

The end method stops the BLE device.

addService

The addService method adds a BLE service to the set of services provided by the BLE device.

setLocalName

The setLocalName method sets the local value (i.e.text string) that is used to advertise the BLE device.

advertise

The advertise method initiates the advertising of the BLEdevice for service.

BLECharacteristic

The BLECharacteristic class permits the settings for the services at the device.

BLECharacteristic

The BLECharacteristic constructor for this class createsa new BLE characteristic for the device.

writeValue

The writeValue method, as the name implies, writes thevalue of the specified BLECharacteristic.

value

The value method, queries the current value of specified BLECharacteristic for the BLE device.

BLEService

The BLEService class enables the services of the BLE device.

BLEService

The BLEService constructor instantiatesa new BLE service for the BLE device using the uuid stringpassed as parameter to the method.

The following uuid string references the LED service:

	"19B10000-E8F2-537E-4F6C-D104768A1214"      

addCharacteristic

The addCharacteristicmethod adds a bleCharacteristic to the instantiated servicefor the BLE device.

The bleCharacteristic parameter is set by instantiating from the corresponding class as shown below:

BLEChacteristic ledCharacteristic(uuid, option)

BLEChacteristic buttonCharacteristic(uuid,option)

where option is the union of any of the following modes:

  • BLENotify
  • BLERead
  • BLEWrite

Documenting the Build

All projects in this introductory set of basic and elementary projects, the microcomputer board and the breadboard are mounted on abase-plate. The advantages of this base-plate are:

  • A recessed profile to eliminate exposure to the bottom side
  • Sufficient screws to mount Arduino (UNO or Mega) or RaspberryPi boards
  • Pre-drilled aligned holes for accompanying screws
  • Holes to restrain the base-plate on a table
  • Full size breadboard slot

The image below illustrates the mounts for the Nano33 in the middle of the full-size breadboard with the push button to the edge to facilitate the insertion of other components and associated wiring for future exercises.

Schematics

The diagram below illustrates the schematic for the elementary exercise to test the ultrasonic sensor:

The assembly diagram below illustrates a proposed layout for the exercise:

References

Arduino Nano 33 BLE Sense

ArduinoBLE Library

Digital Proximity, Ambient Light, RGB and Gesture Sensor

Capacitive Digital Sensor for Relative Humidity and Temperature

INEMO Inertial Module

MEMS Audio Sensor

MEMS Nano Pressure Sensor

NINA-B3 Series

nRF52840 Product Specification

Short Video

Code

Nano 33 Sense BLE ButtonLEDC/C++
1. Pair BLE devices
2. Click push button to toggle LED state
/*
  Button LED

  This example creates a BLE peripheral with service that contains a
  characteristic to control an LED and another characteristic that
  represents the state of the button.

  The circuit:
  - Arduino Nano 33 BLE
  - Button connected to pin 4

  You can use a generic BLE central app, like LightBlue (iOS and Android) or
  nRF Connect (Android), to interact with the services and characteristics
  created in this sketch.

  This example code is in the public domain.
*/

#include <ArduinoBLE.h>

const int ledPin = LED_BUILTIN;     // set ledPin to on-board LED
const int buttonPin = 4;            // set buttonPin to digital pin 4; 7th from bottom on right side

BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create a new BLE LED service

                                    // create switch characteristic and allow remote device to read and write
BLEByteCharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
                                    // create button characteristic and allow remote device to get notifications
BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);

void setup() {
  Serial.begin(115200);
  while (!Serial);

  pinMode(ledPin, OUTPUT);          // use the LED as an output
  pinMode(buttonPin, INPUT);        // use button pin as an input

  if (!BLE.begin())                 // initialize the BLE device
  {                                 // 1 on success, 0 on failure
    Serial.println("Failed to start BLE!");
    while (1);                      // only wait out is to kill execution
  }

  BLE.setLocalName("Nano33 ButtonLED");// set the local value used when advertising
  BLE.setAdvertisedService(ledService);// set the advertised service UUID used when advertising to the value of the BLEService provided
  
  ledService.addCharacteristic(ledCharacteristic);// add the characteristics to the service
  ledService.addCharacteristic(buttonCharacteristic);

  BLE.addService(ledService);       // add the service

  ledCharacteristic.writeValue(0);
  buttonCharacteristic.writeValue(0);

  BLE.advertise();                  // start advertising

  Serial.println("Bluetooth device active, waiting for connections...");
}

void loop() {

  BLE.poll();                       // poll for BLE events

  char buttonValue = digitalRead(buttonPin);  // read the current button pin state

  boolean buttonChanged = (buttonCharacteristic.value() != buttonValue);// has the value changed since the last read

  if (buttonChanged)
  {
    ledCharacteristic.writeValue(buttonValue);// button state changed, update characteristics
    buttonCharacteristic.writeValue(buttonValue);
  }

  if (ledCharacteristic.written() || buttonChanged)
  {
    
    if (ledCharacteristic.value())  // update LED, either central has written to characteristic or button state has changed
    {
      Serial.println("LED on");
      digitalWrite(ledPin, HIGH);
    } 
    else
    {
      Serial.println("LED off");
      digitalWrite(ledPin, LOW);
    }
  }
}

Custom parts and enclosures

ButtonLED assembly
Hardware assembly (for illustration only)
Uploads2ftmp2f7d44488c f25a 433a 96e2 25f305bf27632fbuttonled bb bcxyann0i1

Schematics

ButtonLED schematic
Schematic diagram to assist in determining the pin connectivity
Uploads2ftmp2f836c95e5 446c 4385 a0fd 16acb7bf83072fbuttonled schem tgnto49olh

Comments

Similar projects you might like

Arduino - Use Reset Button Like a Push Button

by RoHa

  • 4,023 views
  • 0 comments
  • 13 respects

Push Button Combination Lock Using Arduino

Project tutorial by Asim Zulfiqar and High Voltages

  • 6,529 views
  • 9 comments
  • 22 respects

Fade Lights and Push Button

Project tutorial by Phuong Vo

  • 3,978 views
  • 3 comments
  • 10 respects

Snap Circuits® - Push Button LED

Project tutorial by Daniel Porrey

  • 2,832 views
  • 0 comments
  • 10 respects

Snap Circuits® - Push Button Monitor

Project tutorial by Daniel Porrey

  • 1,348 views
  • 0 comments
  • 9 respects
Add projectSign up / Login