莫非233 发表于 2025-1-14 10:25

【Follow me第二季第4期】汇总提交帖:全部任务

<div>收到这次活动的板子也有一段时间了,本人是一个电子小白,这是第一次参加Follow Me的活动,准备的有点仓促,还请各位见谅。本期活动的主角是Arduino Nano RP2040 Connect,一块功能强大,集成度很高的微控制器芯片,玩法有很多,待我以后慢慢尝试~感谢社区和得捷能提供这样的机会给大家研究学习还有分享。下面是关于这期汇总帖子的主要内容。</div>

<div><strong>项目视频演示</strong></div>

<div>a8b011b96cccd0105688eb2af3e85d70<br />
&nbsp;</div>

<div>物料展示</div>

<div>本次只购入了RP 2040 connect,后续准备购买oled屏和电机驱动板进行尝试,这就是本期的主角</div>

<div></div>

<div><strong>任务成果展示</strong></div>

<div>任务一:搭建环境并开启第一步Blink三色LED / 串口打印Hello DigiKey &amp; EEWorld!</div>

<div>开发环境:</div>

<div>以下三个任务都是由Arduino的IDE来完成的,环境搭建很简单,我这就简单跟大家分享一下。这是Arduino官方的IDE下载链接<a href="https://www.arduino.cc/en/software">Software | Arduino</a></div>

<div></div>

<div>这里根据大家的开发环境选择就可以,我是window系统所以我选择了第一个,下载安装好之后IDE会先提示安装相关的驱动,直接一路同意就可以。此处省略一万字~</div>

<div>解决完环境搭建的问题之后我们就要开始上手点灯了!要点灯,我们得先知道灯在哪里,通过查看数据手册我们知道,rp2040搭载了一颗共阳的RGB灯,但是并没有直接连接在芯片的引脚上,而是连接在了wifi模块上,这就意味着我们得操作wifi模块才能把我们的灯点起来。</div>

<div>但是别担心,Arduino&nbsp;WiFiNINA library帮咱简化了这一过程(这也是官方库的好处之一),咱们只需要下载封装好的wifi模块的库,下载方法如下:</div>

<div></div>

<div>之后我们只需要初始化io口就可以点亮我们的RGB灯了!</div>

<div>光是点灯还无法完成任务,我们还得通过串口打印出我们想要的内容,不过Arduino已经封装好了,咱直接用就可以了。至此,第一个任务就算是完成了!</div>

<div><strong>程序流程图:</strong></div>

<div><strong></strong></div>

<div><strong>代码:</strong>

<pre>
<code>#include &lt;WiFiNINA.h&gt;
#define led1 LEDR
#define led2 LEDG
#define led3 LEDB
float angle1;
float angle2;
float angle3;
void setup() {
  // put your setup code here, to run once:
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
  for(int i = 0; i &lt; 5;i++)
  {
    digitalWrite(led1,LOW);
    digitalWrite(led2,HIGH);
    delay(200);
    digitalWrite(led2,LOW);
    digitalWrite(led3,HIGH);
    delay(200);
    digitalWrite(led3,LOW);
    digitalWrite(led1,HIGH);
    delay(200);
  }
  angle1 = 0.0;
  angle2 = 0.0 + PI /3.0;
  angle3 = 0.0 +2.0* PI /3.0;
  Serial.begin(115200);
}
void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Hello Digikey &amp;&amp; EEWorld!");
  angle1 += 0.01;
  angle2 += 0.01;
  angle3 += 0.01;
  if(angle1 &gt;= PI)
    angle1 -= PI;
  if(angle2 &gt;= PI)
    angle2 -= PI;
  if(angle3 &gt;= PI)
    angle3 -= PI;
  int a = sin(angle1)*255;
  int b = sin(angle2)*255;
  int c = sin(angle3)*255;
  analogWrite(led1,a);
  analogWrite(led2,b);
  analogWrite(led3,c);
  delay(5);
}</code></pre>

<p>&nbsp;</p>
</div>

<div><strong>演示:</strong></div>

<div>&nbsp;</div>

<div><strong></strong></div>

<div><strong></strong></div>

<div>任务二:学习IMU基础知识,调试IMU传感器,通过串口打印六轴原始数据<strong>;</strong></div>

<div>Arduino Nano RP2040 Connect里面有一个集成了三轴加速度计和三轴陀螺仪的IMU(LSM6DSOXTR),可以进行重大运动检测和倾斜检测,也可感知设备的运动状态和姿态变化。而且还内置了机器学习核心,可以实现姿态识别等功能。Arduino中有LSM6DSOXTR的库,我们只需要调用库就可以实现获取基础的加速度和陀螺仪还有温度的数据,以此进行更复杂的功能实现。</div>

<div></div>

<div><strong>软件流程图:</strong></div>

<div></div>

<div><strong>代码:</strong>

<pre>
<code>#include &lt;Arduino_LSM6DSOX.h&gt;

float acc_x,acc_y,acc_z;
float gyro_x,gyro_y,gyro_z;
int temp;
int update_flag;

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);

if(!IMU.begin())
{
    Serial.println("Failed to initialize IMU");
    while(1);
}
Serial.print("ACC sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println("HZ");
Serial.print("Gyro sample rate = ");
Serial.print(IMU.gyroscopeSampleRate());
Serial.println("HZ");
}

void loop() {
// put your main code here, to run repeatedly:
if(IMU.accelerationAvailable())
{
    IMU.readAcceleration(acc_x, acc_y, acc_z);
    update_flag = 1;
}
if(IMU.gyroscopeAvailable())
{
    IMU.readGyroscope(gyro_x, gyro_y, gyro_z);
    update_flag = 1;
}
if(IMU.temperatureAvailable())
{
    IMU.readTemperature(temp);
    update_flag = 1;
}

if(update_flag)
{
    update_flag = 0;
    Serial.print(acc_x);
    Serial.print(",");
    Serial.print(acc_y);
    Serial.print(",");
    Serial.print(acc_z);
    Serial.print(",");
    Serial.print(gyro_x);
    Serial.print(",");
    Serial.print(gyro_y);
    Serial.print(",");
    Serial.print(gyro_z);
    Serial.print(",");
    Serial.println(temp);
}
delay(50);
}
</code></pre>

<p>&nbsp;</p>
</div>

<div><strong>演示:</strong><strong></strong></div>

<div><strong>任务三:</strong>学习PDM麦克风技术知识,调试PDM麦克风,通过串口打印收音数据和音频波形。</div>

<div>Arduino Nano RP2040 Connect搭载了一颗由意法半导体推出的全向&nbsp;MEMS 麦克风,具有 64dB 的信噪比,能够有效抑制背景噪声,提供清晰的声音采集效果。我们主要是实现能识别到声音并让其可视化。用到的库有PDM,不过rp2040connect自带了,所以我们不需要下载也能直接使用</div>

<div><strong>软件流程图:</strong></div>

<div><strong></strong></div>

<div><strong>代码:</strong>

<pre>
<code>// #include "PDM.h"

// static const char channels = 1;
// static const int frequency = 24000;
// short sampleBuffer;
// volatile int samplesRead;

// void setup() {
//   // put your setup code here, to run once:
//   Serial.begin(115200);

//   PDM.onReceive(onPDMdata);

//   if(!PDM.begin(channels, frequency));
//   {
//   Serial.println("Failed to start PDM!");
//   while(1);
//   }
// }

// void loop() {
//   // put your main code here, to run repeatedly:
//   if(samplesRead)
//   {
//   for(int i = 0;i &lt; samplesRead; i++)
//   {
//       Serial.println(sampleBuffer);
//   }
//   samplesRead = 0;
//   }
//   delay(1);

// }


// void onPDMdata()
// {
//   int bytesAvailable = PDM.available();

//   PDM.read(sampleBuffer, bytesAvailable);

//   samplesRead = bytesAvailable / 2;
// }

#include &lt;WiFiNINA.h&gt;
#include &lt;PDM.h&gt;
bool LED_SWITCH = false;
// default number of output channels
static const char channels = 1;
// default PCM output frequency
static const int frequency = 14000;
// Buffer to read samples into, each sample is 16-bits
short sampleBuffer;
#define PIN_LED (13u)
#define PIN_S (10u)
// Number of audio samples read
volatile int samplesRead;
void setup() {
Serial.begin(9600);
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_S, OUTPUT);
//while (!Serial);
Serial.println("***************************************************************");
// 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 &lt; samplesRead; i++) {
      if (channels == 2) {
      Serial.print("L:");
      Serial.print(sampleBuffer);
      Serial.print(" R:");
      i++;
      }
      Serial.println(sampleBuffer);
      if (sampleBuffer &gt; 10000 || sampleBuffer &lt;= -10000) {
      LED_SWITCH = !LED_SWITCH;
      if (LED_SWITCH) {
          Serial.println();
          digitalWrite(PIN_LED, HIGH);
          digitalWrite(PIN_S, HIGH);
          Serial.println("ON!");
          Serial.println();
          delay(500);
      } else {
          Serial.println();
          digitalWrite(PIN_LED, LOW);
          digitalWrite(PIN_S, LOW);
          Serial.println("OFF!");
          Serial.println();
          delay(500);
      }
      }
    }
    // 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;
}
</code></pre>

<p>&nbsp;</p>
</div>

<div><strong>演示:</strong></div>

<div><strong></strong></div>

<div><strong>心得体会:</strong></div>

<div>通过这次活动,我第一次接触到了Arduino系列的板子,集成度非常高,而且很多功能都封装好了,很适合刚刚入门的小白,在易上手的情况下还具备了很强大的功能,这很大程度的激发了我对这个板子深度探索的兴趣。最后,再次感谢EEWorld和得捷电子能提供这么个机会还有平台能让我们进行沟通和学习。谢谢大家!</div>

<p><!--importdoc--></p>
页: [1]
查看完整版本: 【Follow me第二季第4期】汇总提交帖:全部任务