You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- The length of the extracted audio data is stored in the `len` variable.
540
540
- The extracted audio data is passed to the G722 encoder, which compresses the audio and sends it to the serial port.
541
541
542
-
To extract the audio data on a computer, you will need to set up the serial port as raw and dump the data to a file (e.g., test.g722). Then, you can open the file with a software like [Audacity](https://www.audacityteam.org/) to play back the audio.
542
+
To extract the audio data on a **Linux computer**, you will need to set up the serial port as raw:
543
+
544
+
```bash
545
+
stty -F /dev/ttyACM0 115200 raw
546
+
```
547
+
Dump the data to a file (e.g., test.g722):
548
+
549
+
```bash
550
+
cat /dev/ttyACM0 > test.g722
551
+
```
552
+
Then, you can open the file with a software like [Audacity](https://www.audacityteam.org/) to play back the audio.
543
553
544
554
#### Machine Learning and Audio Analysis
545
555
546
556
You can use the Nicla Voice and the [Machine Learning Tools](https://cloud.arduino.cc/machine-learning-tools/) of the Arduino Cloud to create your own audio analysis Machine Learning models. Check out this [tutorial](https://docs.arduino.cc/tutorials/nicla-voice/getting-started-ml) and start with Machine Learning with the Nicla Voice.
547
557
548
-
### IMU and Magnetometer
558
+
### IMU
549
559
550
560
The Nicla Voice features an advanced IMU and a magnetometer, which allows the board to sense motion, orientation, and magnetic fields. The IMU on the Nicla Voice board is the BMI270 from Bosch®. It consists of a 3-axis accelerometer and a 3-axis gyroscope. They can provide information about the board's motion, orientation, and rotation in a 3D space. The BMI270 is designed for wearables and offers low power consumption and high performance, making it suitable for various applications, such as gesture recognition, motion tracking, or stabilization.
The onboard magnetometer of the Nicla Voice can be used to determine the board's orientation relative to Earth's magnetic field, which is helpful for compass applications, navigation, or detecting the presence of nearby magnetic objects. The magnetometer on the Nicla Voice board is the BMM150, also from Bosch®. It is a 3-axis sensor that measures the strength and direction of magnetic fields surrounding the board.
The example sketch below shows how to get acceleration (m/s<sup>2</sup>) and angular velocity (in °/s) data from the onboard IMU and streams it to the Arduino IDE Serial Monitor and Serial Plotter. The sketch needs the `BMI270_Init.h` header file to be in the same directory as the sketch. You can download the example sketch and the header files [here](assets/nv_acc_gyro_test.rar).
566
+
The example sketch below shows how to get acceleration (m/s<sup>2</sup>) and angular velocity (in °/s) data from the onboard IMU and streams it to the Arduino IDE Serial Monitor and Serial Plotter. The sketch needs the `BMI270_Init.h` header file to be in the same directory as the sketch. You can download the example sketch and the header files [here](assets/nv_acc_gyro_test.zip).
561
567
562
-
```arduino
563
-
/**
564
-
Nicla Voice accelerometer and gyroscope test sketch
565
-
Name: nv_acc_gyro_test.ino
566
-
Purpose: Sketch tests onboard accelerometer and gyroscope (BMI270)
567
-
568
-
@author Arduino PRO Content Team
569
-
@version 1.0 22/05/23
570
-
*/
568
+
***For this example to work you must update the NDP processor, see the details on this [section](#ndp120-processor-firmware-update).***
571
569
570
+
```arduino
572
571
#include "NDP.h"
573
572
#include "BMI270_Init.h"
574
573
575
574
// Named constants
576
-
#define READ_START_ADDRESS 0x0C
577
-
#define READ_BYTE_COUNT 16
578
-
#define SENSOR_DATA_LENGTH 16
575
+
#define READ_START_ADDRESS 0x0C
576
+
#define READ_BYTE_COUNT 16
577
+
#define SENSOR_DATA_LENGTH 16
579
578
580
579
// Accelerometer range is set to +/-2g
581
-
// Raw accelerometer data is represented as a signed 16-bit integer
582
-
// Raw accelerometer data can be converted to acceleration in m/s^2 units using the following scale factor:
// Convert raw accelerometer data to acceleration expressed in m/s^2.
699
+
// Convert raw accelerometer data to acceleration expressed in m/s^2.
741
700
x_acc = x_acc_raw * ACCEL_SCALE_FACTOR;
742
701
y_acc = y_acc_raw * ACCEL_SCALE_FACTOR;
743
702
z_acc = z_acc_raw * ACCEL_SCALE_FACTOR;
@@ -746,8 +705,8 @@ void loop() {
746
705
x_gyr = x_gyr_raw * GYRO_SCALE_FACTOR;
747
706
y_gyr = y_gyr_raw * GYRO_SCALE_FACTOR;
748
707
z_gyr = z_gyr_raw * GYRO_SCALE_FACTOR;
749
-
750
-
// Print accelerometer data (expressed in m/s^2).
708
+
709
+
// Print accelerometer data (expressed in m/s^2).
751
710
Serial.print("x_acc:");
752
711
Serial.print(x_acc);
753
712
Serial.print(",");
@@ -767,7 +726,7 @@ void loop() {
767
726
Serial.print("z_gyr:");
768
727
Serial.println(z_gyr);
769
728
770
-
delay(1000);
729
+
delay(10);
771
730
}
772
731
```
773
732
@@ -778,59 +737,36 @@ First, the necessary libraries are included:
778
737
- `NDP.h` and `BMI270_Init.h` for the Nicla Voice board's basic functions and the IMU control.
779
738
- Macros are defined for checking the status of the IMU; these macros allow the sketch to detect and handle sensor errors.
780
739
781
-
Next, user functions `ledBlueOn()`, `ledGreenOn()`, and `ledRedBlink()` definition:
782
-
783
-
- These functions allow the onboard LEDs to flash specific colors to indicate different states: blue for a successful match, green for an event, and red to indicate an error.
784
-
785
740
Next, in the `setup()` function:
786
741
787
-
- The serial communication is initialized at a baud rate of 115200.
742
+
- The serial communication is initialized at a baud rate of `115200`.
788
743
- The Nicla Voice board is initialized, and the LDO regulator (used for putting the board into power-saving mode) is disabled to avoid communication problems with the IMU.
789
744
- Error and event handlers are initialized.
790
-
- NDP processor is initialized; this process includes populating the external Flash memory of the board with the NDP processor's internal microcontroller firmware (`mcu_fw_120_v91.synpkg`), the NDP processor's internal DSP firmware (`dsp_firmware_v91.synpkg`), and the Machine Learning model (`ei_model.synpkg`).
745
+
- NDP processor is initialized; this process includes populating the external Flash memory of the board with the NDP processor's internal microcontroller firmware (`mcu_fw_120_v91.synpkg`), and the NDP processor's internal DSP firmware (`dsp_firmware_v91.synpkg`).
791
746
- The BMI270 sensor is initialized; this includes a software reset, loading the sensor configuration, and setting it into normal power mode with the accelerometer and gyroscope operational.
792
747
793
748
Finally, in the `loop()` function:
794
749
795
750
- Memory is allocated forthe sensor data; data is then read from the sensor and storedin this allocated space.
796
-
- Raw sensor data is then parsed and extracted into raw accelerometer and gyroscope data. This data is represented as 16-bit signed integers ranging from -32 768 to 32 767.
751
+
- Raw sensor data is then parsed and extracted into raw accelerometer and gyroscope data. This data is represented as 16-bit signed integers ranging from -32768 to 32767.
797
752
- Raw sensor data is converted into understandable and standard unit measurements;for the accelerometer, data is converted to meters per second squared, and for the gyroscope, data is converted to degrees per second.
798
753
- Converted accelerometer and gyroscope data are printed on the Serial Monitor, allowing the user to observe sensor data in real-time.
799
754
800
755
After uploading the example code, you should see accelerometer and gyroscope data on the IDE's Serial Monitor as shown below:
801
756
802
757

803
758
804
-
Let's use also the Arduino IDE Serial Plotter to test the example IMU sketch; let's start visualizing only accelerometer data. To do so, comment the gyroscope data output as shown below:
759
+
Let's use also the Arduino IDE Serial Plotter to test the example IMU sketch, open the IDE's Serial Plotter by navigating to **Tools > Serial Plotter**. After a while, you should see a real-time graph showing data from the board's onboard accelerometer and gyroscope, as shown below:
805
760
806
-
```arduino
807
-
// Print accelerometer data (expressed in meters per second squared).
808
-
Serial.print("x_acc:");
809
-
Serial.print(x_acc);
810
-
Serial.print(",");
811
-
Serial.print("y_acc:");
812
-
Serial.print(y_acc);
813
-
Serial.print(",");
814
-
Serial.print("z_acc:");
815
-
Serial.println(z_acc);
761
+

816
762
817
-
/* Print gyroscope data (expressed in degrees per second).
818
-
Serial.print("x_gyr:");
819
-
Serial.print(x_gyr);
820
-
Serial.print(",");
821
-
Serial.print("y_gyr:");
822
-
Serial.print(y_gyr);
823
-
Serial.print(",");
824
-
Serial.print("z_gyr:");
825
-
Serial.println(z_gyr);*/
826
-
```
827
-
828
-
Upload the example sketch again and open the IDE's Serial Plotter by navigating to **Tools > Serial Plotter**. After a while, you should see a real-time graph showing data from the board's onboard accelerometer, as shown below (move the board):
763
+
When the board is not moving, you should see acceleration measurements close to zero on the x and y-axis, while the z-axis will be close to 1g (approximately 9.81 m/s<sup>2</sup>), the gyroscope measurements on the three-axis will stay close to zero.
829
764
765
+
### Magnetometer
830
766
831
-

767
+
The onboard magnetometer of the Nicla Voice can be used to determine the board's orientation relative to Earth's magnetic field, which is helpful for compass applications, navigation, or detecting the presence of nearby magnetic objects. The magnetometer on the Nicla Voice board is the BMM150, also from Bosch®. It is a 3-axis sensor that measures the strength and direction of magnetic fields surrounding the board.
832
768
833
-
When the board is not moving, you should see acceleration measurements close to zero on the x and y-axis, while the z-axis will be close to 1g (approximately 9.81 m/s<sup>2</sup>). If you want to visualize gyroscope readings, uncomment the gyroscope data output and comment on the accelerometer data output; when the board is not moving, you should see gyroscope measurements on the three-axis close to zero.
0 commit comments