- 2024-12-05
-
加入了学习《DigiKey 应用说:大模型时代的智能汽车》,观看 DigiKey 应用说:大模型时代的智能汽车
- 2024-11-01
-
发表了主题帖:
【Follow me第二季第2期】--任务汇总
本帖最后由 upc_arm 于 2024-11-2 11:14 编辑
## 感谢
感谢论坛,通过这次活动,让我对Arduino UNO R4 WiFi的使用有了深入全面的了解,为后面的开发打开基础。
## 我的任务汇总
### 第一部分:演示视频
所有任务的视频如下:
[localvideo]cfd26ae22e86ac69b3f61feeb830bb97[/localvideo]
### 第二部分:任务实现详情
### 任务简介
总共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
主要代码片段
```c
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("LED ON\r\n");
delay(3000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.print("LED OFF\r\n");
delay(1000); // wait for a second
}
```
分帖链接:
[任务1帖子链接](https://bbs.eeworld.com.cn/thread-1295359-1-1.html "任务1帖子链接")
任务2
主要代码片段
```c
// 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();
if(false)
{
// activate OPAMP, default channel 0
if (!OPAMP.begin(OPAMP_SPEED_HIGHSPEED)) {
Serial.println("Failed to start OPAMP!");
}
bool const isRunning = OPAMP.isRunning(0);
if (isRunning) {
Serial.println("OPAMP running on channel 0!");
} else {
Serial.println("OPAMP channel 0 is not running!");
}
}
}
void set_matrix(int idx, int num)
{
for(int i=0; i
- 2024-10-10
-
回复了主题帖:
【Follow me第二季第2期】--入门任务--UNO R4 ADC--OPAMP--DAC--LED Matrix--串口采集
LED点阵动态显示正弦波。
- 2024-10-07
-
发表了主题帖:
【Follow me第二季第2期】--进阶扩展任务--UNO R4 温湿度传感器--HA显示--MQTTX显示
演示视频:[localvideo]c5dd7db13856fe7cefbe4d5a2cf16ace[/localvideo]
UNO R4的温湿度传感器,HA显示:
1、任务目标
(1)UNO R4读取温湿度传感器数据。
(2)搭建HA服务器,采用docker方式。
(3)通过ESP32-S3模块发送,HA服务端显示当前温湿度。
2、参考文档
(1)https://docs.arduino.cc/tutorials/uno-r4-wifi/qwiic/
(2)https://docs.arduino.cc/tutorials/uno-r4-wifi/wifi-examples/
(3)https://zhuanlan.zhihu.com/p/421109780
(4)https://www.emqx.com/zh/blog/the-easiest-guide-to-getting-started-with-mqtt
3、分析
(1)MQTT是一种轻量级、基于发布-订阅模式的消息传输协议。
一个典型的MQTT示意图如下图所示。图中涉及以下几个关键概念:
MQTT客户端:发送或接受消息的设备,如图,左侧有1个客户端,右侧有3个客户端。
MQTT broker:如图中绿色六边形,可以理解为消息传输的中心或者消息传输的中转站。所有消息都先到MQTT broker,在到客户端。
主题:发送或者接受消息时,为了区分消息内容所设置的主题。如图中 Temperature 就是一个主题,用于传输温度数据。
4、代码
#include <WiFiS3.h>
#include <UnoWiFiDevEd.h>
#include "Adafruit_SHT4x.h"
#include <Arduino_JSON.h>
#include <ArduinoMqttClient.h>
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2)
#include <WiFiNINA.h>
#elif defined(ARDUINO_SAMD_MKR1000)
#include <WiFi101.h>
#elif defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA)
#include <WiFi.h>
#elif defined(ARDUINO_PORTENTA_C33)
#include <WiFiC3.h>
#elif defined(ARDUINO_UNOR4_WIFI)
#include <WiFiS3.h>
#endif
Adafruit_SHT4x sht4 = Adafruit_SHT4x();
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = "wifi_name"; // your network SSID (name)
char pass[] = "wifi_password"; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the WiFi radio's status
WiFiClient wifiClient;
MqttClient mqttClient(wifiClient);
const char broker[] = "broker.emqx.io";
int port = 1883;
const char topic[] = "homeassistant/sensor/room111/sht40";
const long interval = 1000;
unsigned long previousMillis = 0;
JSONVar jsonDat;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the data:
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
Serial.println("Find WIFI");
Serial.println("Adafruit SHT4x test");
if (! sht4.begin(&Wire1)) {
Serial.println("Couldn't find SHT4x");
while (1) delay(1);
}
Serial.println("Found SHT4x sensor");
Serial.print("Serial number 0x");
Serial.println(sht4.readSerial(), HEX);
// You can have 3 different precisions, higher precision takes longer
sht4.setPrecision(SHT4X_HIGH_PRECISION);
switch (sht4.getPrecision()) {
case SHT4X_HIGH_PRECISION:
Serial.println("High precision");
break;
case SHT4X_MED_PRECISION:
Serial.println("Med precision");
break;
case SHT4X_LOW_PRECISION:
Serial.println("Low precision");
break;
}
// You can have 6 different heater settings
// higher heat and longer times uses more power
// and reads will take longer too!
sht4.setHeater(SHT4X_NO_HEATER);
switch (sht4.getHeater()) {
case SHT4X_NO_HEATER:
Serial.println("No heater");
break;
case SHT4X_HIGH_HEATER_1S:
Serial.println("High heat for 1 second");
break;
case SHT4X_HIGH_HEATER_100MS:
Serial.println("High heat for 0.1 second");
break;
case SHT4X_MED_HEATER_1S:
Serial.println("Medium heat for 1 second");
break;
case SHT4X_MED_HEATER_100MS:
Serial.println("Medium heat for 0.1 second");
break;
case SHT4X_LOW_HEATER_1S:
Serial.println("Low heat for 1 second");
break;
case SHT4X_LOW_HEATER_100MS:
Serial.println("Low heat for 0.1 second");
break;
}
// set name
mqttClient.setUsernamePassword("test_sht40", "test_sht40");
Serial.print("Attempting to connect to the MQTT broker: ");
Serial.println(broker);
if (!mqttClient.connect(broker, port)) {
Serial.print("MQTT connection failed! Error code = ");
Serial.println(mqttClient.connectError());
while (1);
}
Serial.println("You're connected to the MQTT broker!");
Serial.println();
}
void loop() {
// to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay
// see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info
unsigned long currentMillis = millis();
mqttClient.poll();
if (currentMillis - previousMillis >= interval) {
// save the last time a message was sent
previousMillis = currentMillis;
sensors_event_t humidity, temp;
uint32_t timestamp = millis();
sht4.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" degrees C");
Serial.print("Humidity: ");
Serial.print(humidity.relative_humidity);
Serial.println("% rH");
printCurrentNet();
int tempeture = temp.temperature;
int humi = humidity.relative_humidity;
jsonDat["tempeture"] = tempeture;
jsonDat["humidity"] = humi;
String strData = JSON.stringify(jsonDat);
// send message, the Print interface can be used to set the message contents
mqttClient.beginMessage(topic);
mqttClient.print(strData);
mqttClient.endMessage();
}
}
void printWifiData() {
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
printMacAddress(mac);
}
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type:");
Serial.println(encryption, HEX);
Serial.println();
}
void printMacAddress(byte mac[]) {
for (int i = 0; i < 6; i++) {
if (i > 0) {
Serial.print(":");
}
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
}
Serial.println();
}
-
发表了主题帖:
【Follow me第二季第2期】--入门任务--UNO R4 ADC--OPAMP--DAC--LED Matrix--串口采集
UNO R4任务2:
视频:[localvideo]85a3dfe1ff445d5d475bbc1117c96e98[/localvideo]
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;
}
- 2024-10-05
-
发表了主题帖:
【Follow me第二季第2期】--入门任务--UNO R4 Hello World
本帖最后由 upc_arm 于 2024-10-7 08:49 编辑
视频链接:[localvideo]eb748ed4b0f2deb6283eb6003b5a93bb[/localvideo]
UNO R4的Hello World程序步骤:
1、UNO R4 简单介绍
UNO R4是在R3基础上进行升级,主要升级点:
(1)R4分为minima版本和wifi版本,本次实验用的wifi版本。
(2)主芯片进行了升级,时钟速度、SARM、FLASH都进行了升级,芯片采用瑞萨电子的 RA4M1 微控制器,配备了 32 kB 的SRAM,256K Flash,48 MHz 的时钟速度。WiFi版还有一个ESP32-S3模块。开发板的接口升级为 USB-C接口。 开发板自带 12x8的LED点阵,可以显示丰富的内容。
(3)R4原理图地址:https://edm.eeworld.com.cn/Arduino_UNO_R4_WiFi-schematics.pdf
2、环境设置
(1)下载 安装arduino程序 https://www.arduino.cc/en/software。强烈建议使用Windows系统,其他系统的细节没有Windows系统方便。
(2)程序安装后,通过数据线连接电脑和R4,确认端口号。
(3)打开Arduino IDE,选择开发板型号,设置串口号。
3、程序
程序比较简单,这里设置的LED灯亮3S,亮的同时通过串口发送字符串"LED ON",灭1S,亮的同时通过串口发送字符串"LED OFF"。
// the setup function runs once when you press reset or power the board
void setup() {
// Set LED
pinMode(LED_BUILTIN, OUTPUT);
// Set Serial
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("LED ON\r\n");
delay(3000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.print("LED OFF\r\n");
delay(1000); // wait for a second
}
4、演示结果
开发板上灯按照程序设置,亮3S,灭1S。
Arduino IDE中,打开串口监视器,可以收到消息:
- 2024-04-23
-
回复了主题帖:
【AI挑战营第一站】模型训练:在PC上完成手写数字模型训练,免费申请RV1106开发板
1、模型训练的本质是就是拟合模型中的参数,找到模型的较优解。训练最终结果就是模型参数。
2、PyTorch是支持自动微分的,支持并行计算的库。目前主要支持Windows、Linux、MacOS操作系统,支持Nvidia和AMD。
3、Mnist训练过程比较简单,主要用的LeNet非常简单,主要就是卷积,非常容易转成onnx。
4、如果算力支持,计划部署YOLO算法。