31浏览
查看: 31|回复: 2

[项目] 【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟

[复制链接]
如何制作显示温度、空气湿度和相对大气压以及时间的滚动气象站。

在我以前的一个项目(蓝牙控制的滚动文本)中,我有一个完成的 8x56 LED 矩阵,由 7 个 8x8 MAX7219 Led 矩阵模块组成,位于适当的盒子中。我使用这个现成的矩阵制作了一个滚动气象站,它显示温度、空气湿度和相对大气压力,以及当前时间。

为此,我使用 BME280 传感器和 DS3231 实时时钟模块,因此该器件独立于 Internet 连接工作。BME280 板放置在外壳的外侧以获得更准确的读数,也可以借助四线电缆将其放置在外部。让我提一下,这些矩阵模块是较旧的类型,正如您所看到的(在给定的图片中),正面包含 DIL IC。新模块采用 smd 技术制成,通常由 4 个耦合矩阵组成,顺时针旋转 90 度。

在这个项目中,使用库 “Max72xxPanel” ,每个矩阵的内容位置可以通过命令 “matrix.setRotation” 在代码中旋转,因此我们可以使用任何类型的矩阵。数组中的矩阵数量也可以更改,由以下命令定义:
int numberOfHorizontalDisplays = 7;我们可以根据我们使用的矩阵数量简单地更改这个数字
正如我之前提到的,该设备的构建非常简单,包含以下组件:
- Arduino Nano 微控制器
- 7 个由 MAX7219 芯片驱动的 8x8 Led Matrix 模块
- BME280 传感器模块
- 和 DS3231 实时时钟模块

打开后,滚动文本会立即按顺序显示
- 星期几
- 当前时间
- 温度(摄氏度)
- 空气湿度
- 和相对大气压(百帕斯卡)
由于二极管数量众多,该器件应由外部电源供电,该电源应提供 2 安培或更高的电流。
LED 的强度以及滚动文本的速度可以在代码中轻松调整。
int 等待 = 25;速度
matrix.setIntensity(3);使用介于 0 和 15 之间的值表示亮度
在视频中,您可以观看有关此设备制造过程的简短说明。

最后,将设备内置到由 PVC 板制成的合适外壳中,厚度为 3 毫米和 5 毫米。

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟图2

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟图1

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟图4

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟图6

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟图5

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟图7

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟图3

驴友花雕  中级技神
 楼主|

发表于 5 小时前

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟

项目代码

  1. #include <SPI.h>
  2. #include <Adafruit_GFX.h>
  3. #include <Max72xxPanel.h>
  4. #include <Adafruit_BME280.h>
  5. #include "RTClib.h"
  6. RTC_DS1307 rtc;
  7. char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  8. Adafruit_BME280 bme280;
  9. int mm;
  10. int pinCS = 10; // Uno or Duemilanove DIN 11 (MOSI) CLK 13 (SCK)
  11. int numberOfHorizontalDisplays = 7;
  12. int numberOfVerticalDisplays = 1;
  13. Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
  14. String tape = "";
  15. int wait = 25; // speed
  16. int spacer = 2; // Character spacing (points)
  17. int width = 5 + spacer; // Font width 5 pixels
  18. String utf8rus(String source)
  19. {
  20.   int i,k;
  21.   String target;
  22.   unsigned char n;
  23.   char m[2] = { '0', '\0' };
  24.   k = source.length(); i = 0;
  25.   while (i < k) {
  26.     n = source[i]; i++;
  27.     if (n >= 0xC0) {
  28.       switch (n) {
  29.         case 0xD0: {
  30.           n = source[i]; i++;
  31.           if (n == 0x81) { n = 0xA8; break; }
  32.           if (n >= 0x90 && n <= 0xBF) n = n + 0x2F;
  33.           break;
  34.         }
  35.         case 0xD1: {
  36.           n = source[i]; i++;
  37.           if (n == 0x91) { n = 0xB7; break; }
  38.           if (n >= 0x80 && n <= 0x8F) n = n + 0x6F;
  39.           break;
  40.         }
  41.       }
  42.     }
  43.     m[0] = n; target = target + String(m);
  44.   }
  45. return target;
  46. }
  47. String Serial_Read() {
  48.   unsigned char c; // variable port for reading series
  49.   String Serial_string = ""; // Forming from a character string
  50.   while (Serial.available() > 0) { // If there are symbols in the series
  51.     c = Serial.read(); // We read a symbol
  52.     //Serial.print(c,HEX); Serial.print(" "); Serial.print(c);
  53.     if (c == '\n') {  //If this is a string of lines
  54.           return Serial_string; // We return the line
  55.     }
  56.     if (c == 0xB8) c = c - 0x01;
  57.     if (c >= 0xBF && c <= 0xFF) c = c - 0x01;
  58.     Serial_string = Serial_string + String(char(c)); //Add symbol to line
  59.   }
  60.   return Serial_string;
  61. }
  62. String chas;
  63. String myn;
  64. //String mesyc = "";
  65. void setup() {
  66.   
  67.   Serial.begin(9600);
  68.   Serial.println(F("bme280"));
  69.   //==================================== hours
  70.   if (! rtc.begin()) {
  71.     Serial.println("Couldn't find RTC");
  72.     Serial.flush();
  73.     abort();
  74.   }
  75.   if (! rtc.isrunning()) {
  76.     Serial.println("RTC is NOT running, let's set the time!");
  77.     // When time needs to be set on a new device, or after a power loss, the
  78.     // following line sets the RTC to the date & time this sketch was compiled
  79.     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  80.     // This line sets the RTC with an explicit date & time, for example to set
  81.     // January 21, 2014 at 3am you would call:
  82.     // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  83.   }
  84. //====================================
  85.   while (!bme280.begin(BME280_ADDRESS - 1)) {
  86.     Serial.println(F("Could not find a valid bme280 sensor, check wiring!"));
  87.     delay(2000);
  88.   }
  89.   
  90.   
  91.   matrix.setIntensity(3); // Use a value between 0 and 15 for brightness
  92.   matrix.setRotation(matrix.getRotation()+0); //1 - 90  2 - 180   3 - 270
  93. //a=a+1;
  94. }
  95. void loop() {
  96.   DateTime now = rtc.now();
  97.   float temperature = bme280.readTemperature();
  98.   float pressure = bme280.readPressure()/100.0F;
  99.   float altitude = bme280.readAltitude(1013.2);
  100.   float humidity = bme280.readHumidity();
  101.   pressure = pressure + 78.5  ;   //Relative pressure for 700m above sea level, comment this row for relative atmospheric pressure
  102. //======================================= correction digit time zero before the number
  103. chas ="";
  104. myn = "";
  105. if (now.hour() < 10) {
  106. chas = '0';
  107. }
  108. if (now.minute() < 10) {
  109. myn = ('0');
  110. }
  111. //=======================================
  112. tape = utf8rus((String)+daysOfTheWeek[now.dayOfTheWeek()]+"     Time  "+chas +now.hour()+":"+myn+now.minute()+" h    Temperature = "+temperature +" degree C   Humidity = " + humidity +  " %    Pressure = "+ pressure +" Hpa");
  113.   if (Serial.available()){
  114.     tape=Serial_Read();
  115.   }
  116.   for ( int i = 0 ; i < width * tape.length() + matrix.width() - 1 - spacer; i++ )
  117.        {
  118.     matrix.fillScreen(LOW);
  119.     int letter = i / width; // number of symbols displayed on a matrix
  120.    
  121.     int y = (matrix.width() - 1) - i % width;  
  122.     int x = (matrix.height() - 8) / 2;
  123.     while ( y + width - spacer >= 0 && letter >= 0 ) {
  124.       if ( letter < tape.length() ) {
  125.         matrix.drawChar(y, x, tape[letter], HIGH, LOW,1);
  126.       }
  127.       letter--;
  128.       y -= width;
  129.     }
  130.     matrix.write(); // Send a picture for display
  131.     delay(wait);
  132.   }
  133. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 5 小时前

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟
项目链接:https://www.hackster.io/mircemk/ ... ock-with-bme-1e8a98
项目作者:米尔科·帕夫莱斯基

项目视频 :https://www.youtube.com/watch?v=OBu0xWGZhzc
项目代码:https://www.hackster.io/code_files/611607/download

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟图2

【Arduino 动手做】Arduino 矩阵滚动气象站和带 BME 的时钟图1

回复

使用道具 举报

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

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail