Skip to content

Hotfixes for Nano ble sense rev2 launch #737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
All you need to know to get started with your new Arduino board.
</EssentialElement>

<EssentialElement title="BLE Sense Cheat Sheet" type="tutorial" link="/tutorials/nano-33-ble-sense-rev2/cheat-sheet">
Learn about the Nano 33 BLE Sense's onboard sensors, supported serial & wireless protocols, pins and much more.
<EssentialElement title="BLE Sense Rev2 Cheat Sheet" type="tutorial" link="/tutorials/nano-33-ble-sense-rev2/cheat-sheet">
Learn about the Nano 33 BLE Sense Rev2's onboard sensors, supported serial & wireless protocols, pins and much more.
</EssentialElement>

<EssentialElement title="Nano Hardware Design Guide" type="tutorial" link="/learn/hardware/nano-pcb-guide">
Learn how to create your own custom hardware that is compatible with the Arduino Nano Family.
</EssentialElement>

<EssentialElement title="Community Projects" type="tutorial" link="/tutorials/nano-33-ble-sense-rev2/community-projects">
Discover interesting projects from the community based on the Nano 33 BLE Sense board.
Discover interesting projects from the community based on the Nano 33 BLE Sense Rev2 board.
</EssentialElement>

</EssentialsColumn>
Expand All @@ -32,11 +32,11 @@ The HS300x library is designed for reading temperature and humidity values from
</EssentialElement>

<EssentialElement title="PDM" type="library" link="https://www.arduino.cc/en/Reference/PDM">
The PDM library allows you to use PDM (Pulse-density modulation) microphones, like the MP34DT05 onboard the Arduino Nano 33 BLE Sense.
The PDM library allows you to use PDM (Pulse-density modulation) microphones, like the MP34DT06JTR onboard the Arduino Nano 33 BLE Sense Rev2.
</EssentialElement>

<EssentialElement title="Arduino_APDS9960" type="library" link="https://www.arduino.cc/en/Reference/ArduinoAPDS9960">
The Arduino_APDS9960 library allows you to use the APDS9960 sensor available on the Arduino Nano 33 BLE Sense to read gestures, color, light intensity and proximity.
The Arduino_APDS9960 library allows you to use the APDS9960 sensor available on the Arduino Nano 33 BLE Sense Rev2 to read gestures, color, light intensity and proximity.
</EssentialElement>

</EssentialsColumn>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<FeatureDescription>

The Arduino Nano 33 BLE Sense Rev2 is a great choice for any beginner, maker or professional to get started with embedded machine learning. It is build upon the [nRF52840 microcontroller](https://content.arduino.cc/assets/Nano_BLE_MCU-nRF52840_PS_v1.1.pdf) and runs on **Arm® Mbed™ OS**. The Nano 33 BLE Sense not only features the possibility to connect via **Bluetooth® Low Energy** but also comes equipped with **sensors** to detect color, proximity, motion, temperature, humidity, audio and more.
The Arduino Nano 33 BLE Sense Rev2 is a great choice for any beginner, maker or professional to get started with embedded machine learning. It is build upon the [nRF52840 microcontroller](https://content.arduino.cc/assets/Nano_BLE_MCU-nRF52840_PS_v1.1.pdf) and runs on **Arm® Mbed™ OS**. The Nano 33 BLE Sense Rev2 not only features the possibility to connect via **Bluetooth® Low Energy** but also comes equipped with **sensors** to detect color, proximity, motion, temperature, humidity, audio and more.

</FeatureDescription>

Expand Down Expand Up @@ -59,7 +59,7 @@ The Arduino Nano 33 BLE Sense Rev2 is a great choice for any beginner, maker or

<Feature title="Lauterbach TRACE32 debugger" image="file-icon">

This board is compatible with Lauterbach TRACE32 debugger, and a free license can be obtained using the boards serial number.
This board is compatible with Lauterbach TRACE32 debugger, and a free license can be obtained using the board's serial number.

<FeatureLink title="Learn More" url="/tutorials/nano-33-ble-sense/trace-32"/>
</Feature>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Nano 33 BLE Sense Rev2
url_shop: https://store.arduino.cc/arduino-nano-33-ble-sense-rev2
url_guide: /software/ide-v1/installing-mbed-os-nano-boards
url_shop: https://store.arduino.cc/nano-33-ble-sense-rev2
core: arduino:mbed_nano
forumCategorySlug: '/hardware/nano-family/nano-33-ble-sense-rev2/160'
certifications: [FCC, IC, REACH, CE, RoHS, WEEE, RCM, UKCA]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ The microcontroller on the Arduino Nano 33 BLE Sense Rev2 runs at 3.3V, which me

To avoid such risk with existing projects, where you should be able to pull out a Nano and replace it with the new Nano 33 BLE Sense, we have the 5V pin on the header, positioned between RST and A7 that is not connected as default factory setting. This means that if you have a design that takes 5V from that pin, it won't work immediately, as a precaution we put in place to draw your attention to the 3.3V compliance on digital and analog inputs.

5V on that pin is available only when two conditions are met: you make a solder bridge on the two pads marked as VUSB and you power the Nano 33 BLE Sense Rev2 through the USB port. If you power the board from the VIN pin, you won't get any regulated 5V and therefore even if you do the solder bridge, nothing will come out of that 5V pin. The 3.3V, on the other hand, is always available and supports enough current to drive your sensors. Please make your designs so that sensors and actuators are driven with 3.3V and work with 3.3V digital IO levels. 5V is now an option for many modules and 3.3V is becoming the standard voltage for electronic ICs.
5V on that pin is available only when two conditions are met: you make a solder bridge on the two pads marked as VUSB and you power the Nano 33 BLE Sense Rev2 through the USB port. There are two sets of VUSB pads on the Arduino Nano 33 BLE Sense Rev2, one set on the bottom and one set on top. To enable the 5V Pin, either one of these need to be connected If you power the board from the VIN pin, you won't get any regulated 5V and therefore even if you do the solder bridge, nothing will come out of that 5V pin. The 3.3V, on the other hand, is always available and supports enough current to drive your sensors. Please make your designs so that sensors and actuators are driven with 3.3V and work with 3.3V digital IO levels. 5V is now an option for many modules and 3.3V is becoming the standard voltage for electronic ICs.

![Soldering the VUSB pins.](assets/Nano33_ble_sense_vusb.png)

Expand Down

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
---
title: 'Controlling the On-Board RGB LED with Microphone'
difficulty: intermediate
compatible-products: [nano-33-ble-sense-rev2]
description: 'Learn how to create a soundmeter using the built-in microphone on the Nano 33 BLE Sense Rev2.'
tags:
- Microphone
- Sound
- Sensor
author: 'Fabricio Troya'
libraries:
- name: Arduino PDM
url: https://www.arduino.cc/en/Reference/PDM
hardware:
- hardware/03.nano/boards/nano-33-ble-sense
software:
- web-editor
- ide-v1
- ide-v2
featuredImage: 'chip'
---

In this tutorial we will use an **Arduino Nano 33 BLE Sense Rev2** board to measure and display the sound values of your surroundings, made possible by the embedded **MP34DT06JTR** sensor.

> **Warning:** A very small percentage of people may experience a seizure when exposed to flashing lights or patterns. Even people who have no history of seizures or epilepsy may have an undiagnosed condition that can cause these “photosensitive epileptic seizures” while watching lights blinking fast. **Immediately stop and consult a doctor if you experience any symptoms.**


## Goals

The goals of this project are:

- Learn how to output raw sensor data from the Arduino Nano 33 BLE Sense Rev2.
- Use the PDM(Pulse-density modulation) library.
- Print sound values in the Serial Monitor.
- Create your own RGB sound meter.



## Hardware & Software Needed
* Arduino Nano 33 BLE Sense Rev2.
* This project uses no external sensors or components.
* In this tutorial we will use the [Arduino Web Editor](https://create.arduino.cc/editor) to program the board.



## The MP34DT06JTR Sensor

![The MP34DT06JTR microphone sensor.](assets/nano33BS_08_sensor.png)

Microphones are components that convert physical sound into digital data. Microphones are commonly used in mobile terminals, speech recognition systems or even gaming and virtual reality input devices.

The MP34DT06JTR sensor is a ultra-compact microphone that use PDM (Pulse-Density Modulation) to represent an analog signal with a binary signal. The sensor's range of different values are the following:

- Signal-to-noise ratio: 64dB
- Sensitivity: -26dBFS ±3dB
- Temperature range: -40 to 85°C

If you want to read more about the MP34DT06JTR sensor you can take a look at the <a href="https://docs.arduino.cc/resources/datasheets/MP34DT06JTR.pdf" target="_blank">datasheet</a>.



## Creating the Program

**1. Setting up**

Let's start by opening the [Arduino Web Editor](https://create.arduino.cc/editor), click on the **Libraries** tab, search for the **PDM FOR MBED** library, then in **Examples**, open the **PDMSerialPlotter** example. Once the sketch is open, rename it as **Sound_Meter**.

![Finding the library in the Web Editor.](assets/nano33BS_08_library.png)

**2. Connecting the board**

Now, connect the Arduino Nano 33 BLE Sense Rev2 to the computer to check that the Web Editor recognizes it, if so, the board and port should appear as shown in the image. If they don't appear, follow the [instructions](https://create.arduino.cc/getting-started/plugin/welcome) to install the plugin that will allow the Editor to recognize your board.

![Selecting the board.](assets/nano33BS_08_board_port.png)


**3. Printing and displaying sound values**

Now we will need to modify the code of the example, in order to print the sound values and turn on a different LED based how noisy is the sound.

Before the `setup()` there are two types of variables initialized. One is a `short` variable and the other is a `volatile int` variable. We use the `short` type variable to store 16-bit data-types as the `sampleBuffer[256]`. The other, `volatile`, is a keyword known as a variable qualifier. It is usually used before the datatype of a variable, in order to modify the way in which the compiler and subsequent program treat the variable. In this case, it directs the compiler to load the variable `samplesRead` from RAM and not from a storage register.

```arduino
#include <PDM.h>

// buffer to read samples into, each sample is 16-bits
short sampleBuffer[256];

// number of samples read
volatile int samplesRead;
```

In the `setup()`, we use the `PDM.conReceive()` function to configure the data receive callback. Lastly, the `PDM.begin()` sets the sensor to read data from just one channel and a sample rate of 16 kHz, this statement is inside an `if()` that will print a message, as a string, in case the sensor has not been properly initialized.

```arduino
void setup() {
Serial.begin(9600);
while (!Serial);

// configure the data receive callback
PDM.onReceive(onPDMdata);

// optionally set the gain, defaults to 20
// PDM.setGain(30);

// initialize PDM with:
// - one channel (mono mode)
// - a 16 kHz sample rate
if (!PDM.begin(1, 16000)) {
Serial.println("Failed to start PDM!");
while (1);
}
}
```

Then, in the `loop()`, let's modify the example code by adding the following portion of code inside the `for()` loop, after the `Serial.println()` function.

```arduino
// check if the sound value is higher than 500
if (sampleBuffer[i]>=500){
digitalWrite(LEDR,LOW);
digitalWrite(LEDG,HIGH);
digitalWrite(LEDB,HIGH);
}
// check if the sound value is higher than 250 and lower than 500
if (sampleBuffer[i]>=250 && sampleBuffer[i] < 500){
digitalWrite(LEDB,LOW);
digitalWrite(LEDR,HIGH);
digitalWrite(LEDG,HIGH);
}
//check if the sound value is higher than 0 and lower than 250
if (sampleBuffer[i]>=0 && sampleBuffer[i] < 250){
digitalWrite(LEDG,LOW);
digitalWrite(LEDR,HIGH);
digitalWrite(LEDB,HIGH);
}
```

With this portion of the code, we will turn on the RGB LED based on the amount of sound that the microphones is receiving.

**4. Complete code**

If you choose to skip the code building section, the complete code can be found below:

```arduino
/*
This example reads audio data from the on-board PDM microphones, and prints
out the samples to the Serial console. The Serial Plotter built into the
Arduino IDE can be used to plot the audio data (Tools -> Serial Plotter)

Circuit:
- Arduino Nano 33 BLE Sense Rev2 board

This example code is in the public domain.
*/

#include <PDM.h>

// buffer to read samples into, each sample is 16-bits
short sampleBuffer[256];

// number of samples read
volatile int samplesRead;

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

// configure the data receive callback
PDM.onReceive(onPDMdata);

// optionally set the gain, defaults to 20
// PDM.setGain(30);

// initialize PDM with:
// - one channel (mono mode)
// - a 16 kHz sample rate
if (!PDM.begin(1, 16000)) {
Serial.println("Failed to start PDM!");
while (1);
}
}

void loop() {
// wait for samples to be read
if (samplesRead) {

// print samples to the serial monitor or plotter
for (int i = 0; i < samplesRead; i++) {
Serial.println(sampleBuffer[i]);
// check if the sound value is higher than 500
if (sampleBuffer[i]>=500){
digitalWrite(LEDR,LOW);
digitalWrite(LEDG,HIGH);
digitalWrite(LEDB,HIGH);
}
// check if the sound value is higher than 250 and lower than 500
if (sampleBuffer[i]>=250 && sampleBuffer[i] < 500){
digitalWrite(LEDB,LOW);
digitalWrite(LEDR,HIGH);
digitalWrite(LEDG,HIGH);
}
//check if the sound value is higher than 0 and lower than 250
if (sampleBuffer[i]>=0 && sampleBuffer[i] < 250){
digitalWrite(LEDG,LOW);
digitalWrite(LEDR,HIGH);
digitalWrite(LEDB,HIGH);
}
}

// clear the read count
samplesRead = 0;
}
}

void onPDMdata() {
// query the number of bytes available
int bytesAvailable = PDM.available();

// read into the sample buffer
PDM.read(sampleBuffer, bytesAvailable);

// 16-bit, 2 bytes per sample
samplesRead = bytesAvailable / 2;
}
```



## Testing It Out

After you have successfully verified and uploaded the sketch to the board, open the Serial Monitor from the menu on the left. You will now see the new values printed.

![Microphone data in the Serial Monitor.](assets/nano33BS_08_printing_values.png)

If you want to test it, the only thing you need to do is to place the board next to a speaker and play some music to see how the colors of the RGB LED change based on the music.

![RGB LED blinking according to the music.](assets/nano33BS_08_testing.png)

**Warning:** Remember that depending of the music, lights might blink too fast. **Immediately stop playing and consult a doctor if you experience any symptoms of “photosensitive epileptic seizures”.**


### Troubleshoot

Sometimes errors occur, if the project is not working as intended there are some common issues we can troubleshoot:
- Missing a bracket or a semicolon.
- If your Arduino board is not recognized, check that the Create plugin is running properly on your computer.
- Accidental interruption of cable connection.
- The sound of the music is too low or the board is too far from the speaker.


## Conclusion

In this simple tutorial we learned how to read sound values from the **MP34DT06JTR** sensor using the [PDM library](https://github.com/arduino/ArduinoCore-nRF528x-mbedos/tree/master/libraries/PDM), and how to use the sensor embedded in the Arduino Nano 33 BLE Sense Rev2 board in order to print out sound values from the environment and visualize them through the RGB LED.