【Follow me第二季第2期】Arduino UNO R4 WiFi全部任务汇总学习+Labview+自己扩展项目
[复制链接]
活动链接资料:https://www.eeworld.com.cn/huodong/digikey_follow_me_2024_02/
写在前面的:
很幸运能够在最后一批空余名额能够入围,很珍惜此次活动,下面学习将认真完成各项指标(多关注群里信息还是非常重要的)
下单也响应很快,很快物料都到齐了
自己给Arduino UNO R4 WiFi加了个外置电源,也非常适配,这不得不得益于其DC电源最新设计
关于Arduino UNO R4 WiFi是最新Arduino开发板,主控芯片为日本瑞萨电子的RA4M1芯片(因为使用“钞”能力了),WiFi芯片为中国的ESP32,个人觉得一个ESP32其实足以,非要说这样组合有什么优点,其实也是有点优势的:
1.系统电压兼容5V,适配Arduino UNO R3的扩展板接口,便于通用及产品迭代
2.冗余设计,联网WiFi功能与主控控制功能隔离提高产品安全性与产品开发维护
Arduino UNO R3与Arduino UNO R4 WiFi对比:可以看出集成度确实提高很多,功能更丰富
入门任务(必做):搭建环境并开启第一步Blink / 串口打印Hello EEWorld!
▄▄▄▄▄▄▄▄▄▄▄▄▄
搭配器件:Arduino UNO R4 WiFi
搭建环境:
1.下载Arduino IDE 2.3.2链接:https://www.arduino.cc/en/software
2.打开IDE获取Arduino UNO R4 WiFi开发板相关扩展包
3.安装最新扩展包
4.选择Arduino UNO R4 WiFi开发板
搭建环境流程图:
5.打开默认案例库:点开启第一步Blink
6.通过USB连接Arduino UNO R4 WiFi开发板
7.编译代码,程序烧写到Arduino UNO R4 WiFi开发板
8.程序代码
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
9.显示效果
程序流程图:
10.串口打印Hello EEWorld!
打开案例库,在此基础进行修改代码
11.程序代码:
void loop() {
// read the input on analog pin 0:
//int sensorValue = analogRead(A0);
// print out the value you read:
//Serial.println(sensorValue);
Serial.println("Hello EEWorld!");
delay(100);
//delay(1); // delay in between reads for stability
}
12.打开电脑串口接收器:
13.电脑虚拟串口接收到数据
14.显示效果:
程序流程图:
基础任务(必做):驱动12x8点阵LED;用DAC生成正弦波;用OPAMP放大DAC信号;用ADC采集并且打印数据到串口等其他接口可上传到上位机显示曲线
▄▄▄▄▄▄▄▄▄▄▄▄▄
搭配器件:Arduino UNO R4 WiFi
1.驱动12x8点阵LED
原理和一般点阵屏有点不一样,传统点阵屏只用单片机I/O的输出高、低电平两种状态,而Arduino UNO R4 WiFi 点阵屏使用I/O的输出高、低、高阻态电平三种种状态,理论上n个I/O可以实现n*(n-1)个LED控制,Arduino UNO R4 WiFi 点阵屏使用I/O原理可具体解读:IO口多路查理复用:三个单片机IO口控制六个LED:https://blog.csdn.net/zhuoqingjoking97298/article/details/116725947
具体控制方法可参考官网:https://docs.arduino.cc/tutorials/uno-r4-wifi/led-matrix/
当然可直接打开IDE中的案例库
代码:
/*
Single Frame
Displays single frames using matrix.loadFrame
See the full documentation here:
https://docs.arduino.cc/tutorials/uno-r4-wifi/led-matrix
*/
#include "Arduino_LED_Matrix.h" // Include the LED_Matrix library
#include "frames.h" // Include a header file containing some custom icons
ArduinoLEDMatrix matrix; // Create an instance of the ArduinoLEDMatrix class
void setup() {
Serial.begin(115200); // Initialize serial communication at a baud rate of 115200
matrix.begin(); // Initialize the LED matrix
}
void loop() {
// Load and display the "chip" frame on the LED matrix
matrix.loadFrame(chip);
delay(500); // Pause for 500 milliseconds (half a second)
// Load and display the "danger" frame on the LED matrix
matrix.loadFrame(danger);
delay(500);
// Load and display the "happy" frame on the LED matrix
matrix.loadFrame(happy);
delay(500);
// Load and display the "big heart" frame provided by the library
matrix.loadFrame(LEDMATRIX_HEART_BIG);
delay(500);
// Print the current value of millis() to the serial monitor
Serial.println(millis());
}
效果演示:
程序流程图:
扩展应用:参考内容:https://blog.csdn.net/blueskyspace/article/details/138769310
效果展示:
2.用DAC生成正弦波
打开案例库
修改代码;利用A5接口采集DAC的波形信号
硬件接法:
实物接法:
软件修改代码如下:
#include "analogWave.h" // Include the library for analog waveform generation
analogWave wave(DAC); // Create an instance of the analogWave class, using the DAC pin
int freq = 10; // in hertz, change accordingly
void setup() {
Serial.begin(115200); // Initialize serial communication at a baud rate of 115200
wave.sine(freq); // Generate a sine wave with the initial frequency
wave.amplitude(0.5);//幅值倍数
}
void loop() {
Serial.println(analogRead(A5));
delay(10);
}
调试效果:
程序流程图:
3.用OPAMP放大DAC信号
没有插件电阻,自己DIY一个插件电阻
其实很简洁,连接好也很方便
为什么选择10K电阻的原因;
实验效果:
程序代码:
#include "analogWave.h" // Include the library for analog waveform generation
#include <OPAMP.h>
analogWave wave(DAC); // Create an instance of the analogWave class, using the DAC pin
int freq = 200; // in hertz, change accordingly
void setup() {
Serial.begin(2000000); // Initialize serial communication at a baud rate of 115200
analogReadResolution(14);
wave.sine(freq); // Generate a sine wave with the initial frequency
wave.amplitude(0.5);//幅值倍数
OPAMP.begin(OPAMP_SPEED_HIGHSPEED);
}
void loop() {
Serial.print(analogRead(A4));
Serial.print(" ");
Serial.println(analogRead(A5));
delayMicroseconds(100);
}
测试波形
为了完成任务,搞了台示波器,真实为了完成任务蛮拼的
测试波形周期200hz
DAC输出幅值为:2.29V
运放输出幅值为:4.6V
程序流程图:
4.用ADC采集并且打印数据到串口等其他接口可上传到上位机显示曲线
实际上该部分和上部分基本重复了,为了更好展示波形数据,采用Labview上位机显示更多波形数据
Arduino UNO R4 WiFi下位机硬件图
程序代码:
#include "analogWave.h" // Include the library for analog waveform generation
#include <OPAMP.h>
analogWave wave(DAC); // Create an instance of the analogWave class, using the DAC pin
int freq = 200; // in hertz, change accordingly
void setup() {
Serial.begin(2000000); // Initialize serial communication at a baud rate of 115200
analogReadResolution(14);
wave.sine(freq); // Generate a sine wave with the initial frequency
wave.amplitude(0.5);//幅值倍数
OPAMP.begin(OPAMP_SPEED_HIGHSPEED);
}
void loop() {
Serial.print(analogRead(A4));
Serial.print(",");
Serial.println(analogRead(A5));
delayMicroseconds(100);
}
通过Arduino IDE自带串口也可串口波形数据
连接方式:通过USB连接,labview上位机通过串口获取Arduino UNO R4 WiFi采集数据
打开labview案例库
在此基础修改增加波形显示插件
程序代码:
运行效果:波形正常显示无异常
labview程序附件:2015版本
|