327|0

384

帖子

2

TA的资源

纯净的硅(初级)

楼主
 

【Follow me第二季第2期】--任务汇总 [复制链接]

 

本帖最后由 upc_arm 于 2024-11-2 11:14 编辑

感谢

  1. 感谢论坛,通过这次活动,让我对Arduino UNO R4 WiFi的使用有了深入全面的了解,为后面的开发打开基础。

我的任务汇总

第一部分:演示视频

所有任务的视频如下:

鎾斁鍣ㄥ姞杞藉け璐�: 鏈娴嬪埌Flash Player锛岃鍒�瀹夎
演示汇总

第二部分:任务实现详情

任务简介

总共3个任务,分别是:

  • (1) 入门程序Hello World
  • (2) DAC生成波形图,MPAMP放大后ADC采集,再在点阵和串口显示波形
  • (3) 用温湿度传感器采集数据,通过MQTT协议,在HA和MQTT工具上显示数据

物料清单

  • (1) Arduino UNO R4 WiFi
  • (2) SHT40温湿度传感器扩展板
  • (3) Qwiic连接线

实物图

设计思路

3个任务设计思路基本类似:第一步设置各种外设;第二步初始化全局变量、WiFI、外设等;第三步大循环,读取温湿度传感器数据,处理,显示,通过MQTT发送到远端。

软件流程图

程序设计流程图如下图所示:

任务介绍

任务1
主要代码片段

  1. // the loop function runs over and over again forever
  2. void loop() {
  3. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  4. Serial.println("LED ON\r\n");
  5. delay(3000); // wait for a second
  6. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  7. Serial.print("LED OFF\r\n");
  8. delay(1000); // wait for a second
  9. }

分帖链接:
任务1帖子链接

任务2

主要代码片段

  1. // Create an instance of the analogWave class, using the DAC pin
  2. analogWave wave(DAC);
  3. // LEDMatrix
  4. ArduinoLEDMatrix matrix;
  5. byte frame[8][12] = {
  6. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  7. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  8. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  9. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  10. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  11. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  12. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  13. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  14. };
  15. // These constants won't change. They're used to give names to the pins used:
  16. const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
  17. const int analogOutPin = 9; // Analog output pin that the LED is attached to
  18. int freq = 1;
  19. int time_idx = 0;
  20. int sensorValue = 0; // value read from the pot
  21. int outputValue = 0; // value output to the PWM (analog out)
  22. void setup() {
  23. // initialize serial communications at 9600 bps:
  24. Serial.begin(19200);
  25. //change to 14-bit resolution
  26. analogReadResolution(10);
  27. // Generate a sine wave with the initial frequency
  28. wave.sine(freq);
  29. wave.amplitude(0.5);
  30. // LED
  31. matrix.begin();
  32. if(false)
  33. {
  34. // activate OPAMP, default channel 0
  35. if (!OPAMP.begin(OPAMP_SPEED_HIGHSPEED)) {
  36. Serial.println("Failed to start OPAMP!");
  37. }
  38. bool const isRunning = OPAMP.isRunning(0);
  39. if (isRunning) {
  40. Serial.println("OPAMP running on channel 0!");
  41. } else {
  42. Serial.println("OPAMP channel 0 is not running!");
  43. }
  44. }
  45. }
  46. void set_matrix(int idx, int num)
  47. {
  48. for(int i=0; i<8; i++)
  49. {
  50. for(int j=0;j<11;j++)
  51. {frame<i>[j] = frame<i>[j+1];}
  52. }
  53. num = num / 16;
  54. for(int i=0; i<num; i++)
  55. {frame<i>[idx] = 1;}
  56. }
  57. void loop()
  58. {
  59. int reading = analogRead(A3);
  60. //int serial_num = reading / 64;
  61. int serial_num = map(reading, 0, 1023, 0, 255);
  62. Serial.println(String(serial_num));
  63. if(time_idx>=12)
  64. {time_idx=0;}
  65. //Serial.println("time_idx");
  66. //Serial.println(String(time_idx));
  67. //Serial.println("serial_num");
  68. //Serial.println(String(serial_num));
  69. set_matrix(10, serial_num);
  70. matrix.renderBitmap(frame, 8, 12);
  71. delay(50);
  72. time_idx = time_idx + 1;
  73. }

分帖链接:
任务2帖子链接

任务3

主要代码片段

  1. Adafruit_SHT4x sht4 = Adafruit_SHT4x();
  2. //arduino_secrets.h header file
  3. #define SECRET_SSID "yournetwork"
  4. #define SECRET_PASS "yourpassword"
  5. ///////please enter your sensitive data in the Secret tab/arduino_secrets.h
  6. char ssid[] = SECRET_SSID; // your network SSID (name)
  7. char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
  8. int keyIndex = 0; // your network key index number (needed only for WEP)
  9. int led = LED_BUILTIN;
  10. int status = WL_IDLE_STATUS;
  11. WiFiServer server(80);
  12. void setup() {
  13. Serial.begin(9600);
  14. while (!Serial)
  15. delay(10); // will pause Zero, Leonardo, etc until serial console opens
  16. Serial.println("Adafruit SHT4x test");
  17. if (! sht4.begin()) {
  18. Serial.println("Couldn't find SHT4x");
  19. while (1) delay(1);
  20. }
  21. Serial.println("Found SHT4x sensor");
  22. Serial.print("Serial number 0x");
  23. Serial.println(sht4.readSerial(), HEX);
  24. // You can have 3 different precisions, higher precision takes longer
  25. sht4.setPrecision(SHT4X_HIGH_PRECISION);
  26. switch (sht4.getPrecision()) {
  27. case SHT4X_HIGH_PRECISION:
  28. Serial.println("High precision");
  29. break;
  30. case SHT4X_MED_PRECISION:
  31. Serial.println("Med precision");
  32. break;
  33. case SHT4X_LOW_PRECISION:
  34. Serial.println("Low precision");
  35. break;
  36. }
  37. // You can have 6 different heater settings
  38. // higher heat and longer times uses more power
  39. // and reads will take longer too!
  40. sht4.setHeater(SHT4X_NO_HEATER);
  41. switch (sht4.getHeater()) {
  42. case SHT4X_NO_HEATER:
  43. Serial.println("No heater");
  44. break;
  45. case SHT4X_HIGH_HEATER_1S:
  46. Serial.println("High heat for 1 second");
  47. break;
  48. case SHT4X_HIGH_HEATER_100MS:
  49. Serial.println("High heat for 0.1 second");
  50. break;
  51. case SHT4X_MED_HEATER_1S:
  52. Serial.println("Medium heat for 1 second");
  53. break;
  54. case SHT4X_MED_HEATER_100MS:
  55. Serial.println("Medium heat for 0.1 second");
  56. break;
  57. case SHT4X_LOW_HEATER_1S:
  58. Serial.println("Low heat for 1 second");
  59. break;
  60. case SHT4X_LOW_HEATER_100MS:
  61. Serial.println("Low heat for 0.1 second");
  62. break;
  63. }
  64. }
  65. void loop() {
  66. sensors_event_t humidity, temp;
  67. uint32_t timestamp = millis();
  68. sht4.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
  69. timestamp = millis() - timestamp;
  70. Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
  71. Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");
  72. Serial.print("Read duration (ms): ");
  73. Serial.println(timestamp);
  74. delay(1000);
  75. }
  76. void printWiFiStatus() {
  77. // print the SSID of the network you're attached to:
  78. Serial.print("SSID: ");
  79. Serial.println(WiFi.SSID());
  80. // print your WiFi shield's IP address:
  81. IPAddress ip = WiFi.localIP();
  82. Serial.print("IP Address: ");
  83. Serial.println(ip);
  84. // print where to go in a browser:
  85. Serial.print("To see this page in action, open a browser to http://");
  86. Serial.println(ip);
  87. }

分帖链接:
任务3帖子链接

本次活动心得体会

  1. 通过这次活动,让我对Arduino UNO R4 WiFi的ADC、DAC、串口、点阵、WIFI等模块的使用有了深入的学习,后面开发的话,可以直接基于这些项目进行。最后感谢论坛组织的这次活动!

第三部分:可以编译下载的代码:

点赞 关注
个人签名

I-Love-MCU

 
 

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

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

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

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

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

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

北京市海淀区中关村大街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
快速回复 返回顶部 返回列表