301|1

384

帖子

2

TA的资源

纯净的硅(初级)

楼主
 

【Follow me第二季第2期】--入门任务--UNO R4 ADC--OPAMP--DAC--LED Matrix--串口采集 [复制链接]

 

UNO R4任务2:

视频:

播放器加载失败: 未检测到Flash Player,请到安装
task2

1、任务分析

本次任务主要有以下模块:

(1)ADC产生正弦波。

(2)OPAMP放大。

(3)ADC采集。

(4)LED 显示。

(5)串口显示。

 

参考的官方文档资料:

https://docs.arduino.cc/tutorials/uno-r4-wifi/led-matrix/

https://docs.arduino.cc/tutorials/uno-r4-wifi/adc-resolution/

https://docs.arduino.cc/tutorials/uno-r4-wifi/dac/

https://docs.arduino.cc/tutorials/uno-r4-wifi/opamp/

 

2、电路说明

外接电路图:

 

 

由于在老家,没找到合适的电阻,暂时不进行放大。

3、程序设计系思路

为了便于调试,采取从后往前实现并调试各个模块。

(1)代码模拟一个正弦波,并通过串口打印出来。Arduino IDE非常好用,不仅有串口的监视器,还有串口的画图窗口,可以将打印的数据以图形形式显示出来。

(2)真正生成正弦波,用ADC采集,替代模拟产生的正弦波,调试。

(3)LED 点阵显示波形,由于LED点阵有8行12列,以12列为时间轴,每一列显示一个时刻的正弦波形。将ADC采集到的数据映射到0--8内,并以实体形式显示波形。

4、代码

  • #include "Arduino_LED_Matrix.h"
  • #include "analogWave.h"
  • #include <OPAMP.h>
  • // Create an instance of the analogWave class, using the DAC pin
  • analogWave wave(DAC);
  • // LEDMatrix
  • ArduinoLEDMatrix matrix;
  • byte frame[8][12] = {
  • { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  • { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  • { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  • { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  • { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  • { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  • { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  • { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  • };
  • // These constants won't change. They're used to give names to the pins used:
  • const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
  • const int analogOutPin = 9; // Analog output pin that the LED is attached to
  • int freq = 1;
  • int time_idx = 0;
  • int sensorValue = 0; // value read from the pot
  • int outputValue = 0; // value output to the PWM (analog out)
  • void setup() {
  • // initialize serial communications at 9600 bps:
  • Serial.begin(19200);
  • //change to 14-bit resolution
  • analogReadResolution(10);
  • // Generate a sine wave with the initial frequency
  • wave.sine(freq);
  • wave.amplitude(0.5);
  • // LED
  • matrix.begin();
  • }
  • void set_matrix(int idx, int num)
  • {
  • for(int i=0; i<8; i++)
  • {
  • for(int j=0;j<11;j++)
  • {frame[i][j] = frame[i][j+1];}
  • }
  • num = num / 16;
  • for(int i=0; i<num; i++)
  • {frame[i][idx] = 1;}
  • }
  • void loop()
  • {
  • int reading = analogRead(A3);
  • int serial_num = map(reading, 0, 1023, 0, 255);
  • Serial.println(String(serial_num));
  • if(time_idx>=12)
  • {time_idx=0;}
  • set_matrix(10, serial_num);
  • matrix.renderBitmap(frame, 8, 12);
  • delay(50);
  • time_idx = time_idx + 1;
  • }

 


 

点赞 关注
个人签名

I-Love-MCU

 
 

回复
举报

384

帖子

2

TA的资源

纯净的硅(初级)

沙发
 

LED点阵动态显示正弦波。

个人签名

I-Love-MCU

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
有奖直播:当AI遇见仿真,会有什么样的电子行业革新之路?
首场直播:Simcenter AI 赋能电子行业研发创新
直播时间:04月15日14:00-14:50

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网 2

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表