RGB的控制是通过wifi芯片实现的,虽然在arduino编程中使用方法没有变化,不过需要调用这个库才能使用RGB,而且有一点需要注意,在NINA模块上使用蓝牙®低功耗模式时,默认不能使用RGB。当模块处于蓝牙®低功耗模式时,RGB通过W-102模块连接,因此需要安装WiFiNINA库。
主要代码如下:
#include <WiFiNINA.h>
char RGB_flag = 0;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Hello DigiKey & EEWorld!");
pinMode(LEDB, OUTPUT);
pinMode(LEDR,OUTPUT);
pinMode(LEDG,OUTPUT);
digitalWrite(LEDB,LOW);
digitalWrite(LEDR,LOW);
digitalWrite(LEDG,LOW);
}
void loop() {
if(RGB_flag) {
digitalWrite(LEDB, LOW);
digitalWrite(LEDR, LOW);
digitalWrite(LEDG, LOW);
} else {
digitalWrite(LEDB, HIGH);
digitalWrite(LEDR, HIGH);
digitalWrite(LEDG, HIGH);
}
RGB_flag = !RGB_flag;
delay(1000);
}
详细内容可参见分任务贴:https://bbs.eeworld.com.cn/thread-1300872-1-1.html
任务二:本任务旨在通过Arduino Nano RP2040 Connect开发板,深入学习和调试IMU(惯性测量单元)传感器,特别是ST的六轴IMU LSM6DSOXTR。此传感器能够测量三轴加速度和三轴角速度,对于设备的运动跟踪和姿态计算至关重要。通过本项目,我们将实现通过串口打印出IMU传感器的六轴原始数据,为后续的设备姿态分析和运动控制提供基础。
主要代码如下:
#include <Arduino_LSM6DSOX.h>
float Ax, Ay, Az;
float Gx, Gy, Gz;
void setup() {
Serial.begin(9600);
while(!Serial);
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println("Hz");
Serial.println();
Serial.print("Gyroscope sample rate = ");
Serial.print(IMU.gyroscopeSampleRate());
Serial.println("Hz");
Serial.println();
}
void loop() {
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(Ax, Ay, Az);
Serial.println("Accelerometer data: ");
Serial.print(Ax);
Serial.print('\t');
Serial.print(Ay);
Serial.print('\t');
Serial.println(Az);
Serial.println();
}
if (IMU.gyroscopeAvailable()) {
IMU.readGyroscope(Gx, Gy, Gz);
Serial.println("Gyroscope data: ");
Serial.print(Gx);
Serial.print('\t');
Serial.print(Gy);
Serial.print('\t');
Serial.println(Gz);
Serial.println();
}
delay(500);
}
详细内容可参见分任务贴:https://bbs.eeworld.com.cn/thread-1300874-1-1.html
任务三:本任务旨在调试PDM(Pulse Density Modulation)麦克风,并通过串口打印收音数据以及在上位机上展示音频波形。PDM麦克风作为一种数字音频输入设备,具有信号抗干扰能力强、传输效率高等优点,广泛应用于智能音箱、蓝牙耳机等音频设备中。本项目通过Arduino Nano RP2040开发板板载的PDM麦克风,实现音频信号的采集、处理与展示,为后续的音频分析与应用提供基础。
主要代码如下:
#include <WiFiNINA.h>
#include <PDM.h>
bool LED_SWITCH = false;
// default number of output channels
static const char channels = 1;
// default PCM output frequency
static const int frequency = 20000;
// Buffer to read samples into, each sample is 16-bits
short sampleBuffer[512];
// Number of audio samples read
volatile int samplesRead;
void setup() {
Serial.begin(9600);
pinMode(LEDB, OUTPUT);
while (!Serial);
// Configure the data receive callback
PDM.onReceive(onPDMdata);
// Optionally set the gain
// Defaults to 20 on the BLE Sense and -10 on the Portenta Vision Shields
// PDM.setGain(30);
// Initialize PDM with:
// - one channel (mono mode)
// - a 16 kHz sample rate for the Arduino Nano 33 BLE Sense
// - a 32 kHz or 64 kHz sample rate for the Arduino Portenta Vision Shields
if (!PDM.begin(channels, frequency)) {
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++) {
if (channels == 2) {
Serial.print("L:");
Serial.print(sampleBuffer[i]);
Serial.print(" R:");
i++;
}
Serial.println(sampleBuffer[i]);
// Clear the read count
samplesRead = 0;
}
}
}
/**
Callback function to process the data from the PDM microphone.
NOTE: This callback is executed as part of an ISR.
Therefore using `Serial` to print messages inside this function isn't supported.
* */
void onPDMdata() {
// Query the number of available bytes
int bytesAvailable = PDM.available();
// Read into the sample buffer
PDM.read(sampleBuffer, bytesAvailable);
// 16-bit, 2 bytes per sample
samplesRead = bytesAvailable / 2;
}
详细内容可参见分任务贴:https://bbs.eeworld.com.cn/thread-1300876-1-1.html
第四部分:心得体会
通过本次“Blink三色LED并串口打印”、“IMU传感器应用”以及“调试PDM麦克风”的一系列项目实践,我对Arduino平台及其相关硬件开发有了全面而深刻的认识和体验。Arduino平台在硬件开发中的便捷性和灵活性给我留下了深刻的印象。利用Arduino IDE,我能够快速地编写、上传和调试代码,这不仅大大提高了开发效率,还让我能够更加专注于功能的实现和逻辑的优化。本次项目实践让我对Arduino平台和RP2040开发板有了更深入的了解和认识,同时也锻炼了我的硬件连接、软件编程和调试能力。通过这些实践,我不仅掌握了相关技能,还学会了如何在遇到问题时寻求解决方案,这对于我未来的学习和工作都将产生积极的影响。
第五部分:代码分享