955| 6
|
[ESP8266/ESP32] 基于FireBeetle 2 ESP32-C6的迷你气象监测仪 |
FireBeetle 2 ESP32-C6是一款基于ESP32-C6芯片设计的低功耗物联网开发板,搭载了CN3165锂电池充电管理芯片,配合太阳能板可实现不间断供电功能。还支持电池电压检测,可实时了解电池剩余电量。 此次测试是用FireBeetle 2 ESP32-C6制作了一个可以持续供电的迷你气象站。显示模块使用了一块2.0" 320x240 IPS广视角TFT显示屏,传感器使用了五合一环境传感器这是一个集成了SHTC3温湿度传感器、BMP280大气压强传感器、VEML7700光照传感器、紫外线传感器共五种环境参数的五合一传感器。每一种环境参数都使用了专业传感器芯片,电路设计上也精心考虑了核芯片的合理布局和热传导,有效的保证了数据的准确性。产品板载了MCU处理芯片,将传感器的原始数据经过换算,得到的值就是标准单位值。 首先测试了充电功能,将太阳能板的正极焊接在ESP32-C6的VIN串口,将负极焊接在ESP32-C6的GND串口。接一个3.7V锂电池到ESP32-C主板,完成后上代码在屏幕显示环境数据和锂电池电量查看效果,在室内阳光不是很充足的情况下居然可以正常充电。 程序测试很顺利,剩下的就是结构部分了。由于最近很忙就不用3D打印和激光雕刻了,家里还有点乐高件就简单搭建了一下。 代码如下 /* * 源启 * 使用ESP32-C6制作迷你气象监测仪 * 传感器:五合一环境传感器 * 屏幕:TFT彩屏 * 持续供电:5V太阳能电池板搭配板载太阳能充电模块 * 电池:3.7V锂电池 */ #include "DFRobot_GDL.h" #include "DFRobot_EnvironmentalSensor.h" #define MODESWITCH 0 DFRobot_EnvironmentalSensor environment(/*addr = */SEN050X_DEFAULT_DEVICE_ADDRESS, /*pWire = */&Wire); //自定义通信引脚 //ESP32_C6 #define TFT_DC 8 #define TFT_CS 1 #define TFT_RST 14 #define TFT_BL 15 /** * @brief Constructor 硬件SPI通信的构造函数 * @param dc SPI通信的命令/数据线引脚 * @param cs SPI通信的片选引脚 * @param rst 屏的复位引脚 */ //DFRobot_ST7789_240x240_HW_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST); DFRobot_ST7789_240x320_HW_SPI screen(/*dc=*/TFT_DC,/*cs=*/TFT_CS,/*rst=*/TFT_RST); void setup() { analogReadResolution(12); #if MODESWITCH //初始化MCU通信串口 #if defined(Arduino_AVR_UNO)||defined(ESP8266) mySerial.begin(9600); #elif defined(ESP32) Serial1.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2); #else Serial1.begin(9600); #endif #endif Serial.begin(115200); while(environment.begin() != 0){ Serial.println(" Sensor initialize failed!!"); delay(1000); } Serial.println(" Sensor initialize success!!"); screen.begin(); screen.fillScreen(COLOR_RGB565_BLACK); screen.fillRect(0,0,240,70,0xa348); screen.fillRect(0,290,240,30,0xa348); //设置标题 screen.setTextSize(3); screen.setCursor(0, 25); screen.setTextColor(0XFFBC); screen.println("Micro Weather"); //设置温度标题 screen.setTextSize(2); screen.setCursor(0, 90); screen.setTextColor(0X50B); screen.println("Temperature"); //设置湿度标题 screen.setTextSize(2); screen.setCursor(0, 120); screen.setTextColor(0X50B); screen.println("Humidity"); //设置紫外线标题 screen.setTextSize(2); screen.setCursor(0, 150); screen.setTextColor(0X50B); screen.println("Ultraviolet"); //设置环境光标题 screen.setTextSize(2); screen.setCursor(0, 180); screen.setTextColor(0X50B); screen.println("Luminous"); //设置大气压强标题 screen.setTextSize(2); screen.setCursor(0, 210); screen.setTextColor(0X50B); screen.println("AtmPressure"); //设置海拔高度标题 screen.setTextSize(2); screen.setCursor(0, 240); screen.setTextColor(0X50B); screen.println("Elevation"); //设置锂电池电量标题 screen.setTextSize(2); screen.setCursor(0, 270); screen.setTextColor(0X50B); screen.println("BatteryPower"); } void loop() { int analogValue = analogRead(0); int analogVolts = analogReadMilliVolts(0); screen.fillRect(145,78,90,210, COLOR_RGB565_BLACK); //设置温度数据 screen.setTextSize(2); screen.setCursor(150, 90); screen.setTextColor(0X451); screen.println(environment.getTemperature(TEMP_C)); //设置湿度数据 screen.setTextSize(2); screen.setCursor(150, 120); screen.setTextColor(0X451); screen.println(environment.getHumidity()); //设置紫外线数据 screen.setTextSize(2); screen.setCursor(150, 150); screen.setTextColor(0X451); screen.println(environment.getUltravioletIntensity()); //设置环境光线数据 screen.setTextSize(2); screen.setCursor(150, 180); screen.setTextColor(0X451); screen.println(environment.getLuminousIntensity()); //设置大气压强数据 screen.setTextSize(2); screen.setCursor(150, 210); screen.setTextColor(0X451); screen.println(environment.getAtmospherePressure(HPA)); //设置海拔高度 screen.setTextSize(2); screen.setCursor(150, 240); screen.setTextColor(0X451); screen.println(environment.getElevation()); //设置电量 screen.setTextSize(2); screen.setCursor(150, 270); screen.setTextColor(0X451); screen.println((analogVolts* 2.1218 + 1000)/1000); //刷新时间 delay(3000); } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed