1746| 0
|
[ESP8266/ESP32] FireBeetle 2 ESP32-S3 测试2--连接透明显示屏、温湿度传感器 |
本帖最后由 Anders项勇 于 2023-9-7 00:03 编辑 本文继续测试FireBeetle 2 ESP32-S3,连接一个DHT20温湿度传感器,用1.51”透明单色OLED显示屏显示数据 1.连接DHT20温湿度传感器: DHT20温湿度传感器是DHT11的全新升级版,在测量精度、供电电压、测量范围、响应时间、稳定性等方面的性能参数相交DHT11都有大幅提升。I2C 接口,正好接FireBeetle 2 ESP32-S3的板载I2C 接口。 在Arduino库里面搜索DFRobot_DHT20库安装 2.连接1.51”透明单色OLED显示屏: 这是一块带转接板的1.51”透明单色屏幕,分辨率为128x64(完全透明的区域分辨率为128*56,在靠近排线侧有一小块区域不能完全透明,但可显示),显示颜色为蓝色,全视角显示。尺寸小巧的转接板提供了GDI接口和SPI排针两种接线方式。刚好连接FireBeetle 2 ESP32-S3的GDI接口。安装U8g2_Arduino库文件。 3.arduino代码: #include <Arduino.h> #include <U8g2lib.h> #include <DFRobot_DHT20.h> #include <SPI.h> /* * Display hardware IIC interface constructor *@param rotation:U8G2_R0 Not rotate, horizontally, draw direction from left to right U8G2_R1 Rotate clockwise 90 degrees, drawing direction from top to bottom U8G2_R2 Rotate 180 degrees clockwise, drawing in right-to-left directions U8G2_R3 Rotate clockwise 270 degrees, drawing direction from bottom to top U8G2_MIRROR Normal display of mirror content (v2.6.x version used above) Note: U8G2_MIRROR need to be used with setFlipMode(). *@param reset:U8x8_PIN_NONE Indicates that the pin is empty and no reset pin is used * Display hardware SPI interface constructor *@param Just connect the CS pin (pins are optional) *@param Just connect the DC pin (pins are optional) * */ #if defined ARDUINO_SAM_ZERO #define OLED_DC 7 #define OLED_CS 5 #define OLED_RST 6 /*ESP32 */ #elif defined(ESP32) #define OLED_DC D2 #define OLED_CS D6 #define OLED_RST D3 /*ESP8266*/ #elif defined(ESP8266) #define OLED_DC D4 #define OLED_CS D6 #define OLED_RST D5 /*AVR series board*/ #else #define OLED_DC 2 #define OLED_CS 3 #define OLED_RST 4 #endif U8G2_SSD1309_128X64_NONAME2_1_4W_HW_SPI u8g2(/* rotation=*/U8G2_R0, /* cs=*/ OLED_CS, /* dc=*/ OLED_DC,/* reset=*/OLED_RST); DFRobot_DHT20 dht20; void setup(void) { u8g2.begin(); //init u8g2.enableUTF8Print(); // Enable UTF8 support for Arduino print()function. Serial.begin(115200); //传感器初始化 while(dht20.begin()){ Serial.println("传感器初始化失败"); delay(1000); } } void loop(void) { //获取环境温度 Serial.print("temperature:"); Serial.print(dht20.getTemperature());Serial.print("C"); //获取相对湿度 Serial.print(" humidity:"); Serial.print(dht20.getHumidity()*100);Serial.println(" %RH"); /*@brief Set font direction of all strings setFontDirection(uint8_t dir) *@param dir=0,rotate 0 degree dir=1,rotate 90 degrees dir=2,rotate 180 degrees dir=3,rotate 270 degrees *@param When completed font setting, re-set the cursor position to display normally. Refer to API description for more details. */ u8g2.setFontDirection(0); /* * firstPage Change the current page number position to 0 * Revise content in firstPage and nextPage, re-render everything every time * This method consumes less ram space than sendBuffer */ u8g2.firstPage(); do { /* *The font takes up a lot of memory, so please use it with caution. Get your own Chinese encode for displaying only several fixed words. *Display by drawXBM or use controller with larger memory *Chinese Font:require a controller with larger memory than Leonardo *Japanese Font:require a controller with larger memory than UNO *Korean Font:Arduino INO files of the current version do not support for displaying Korean, but it can displayed properly on the Screen */ u8g2.setFont(u8g2_font_unifont_t_chinese2); u8g2.setCursor(0, 15); u8g2.print("温度"); u8g2.setFont(u8g2_font_unifont_t_chinese2); u8g2.setCursor(0, 30); u8g2.print(dht20.getTemperature()); u8g2.setFont(u8g2_font_unifont_t_chinese2); u8g2.setCursor(0, 45); u8g2.print("湿度"); u8g2.setFont(u8g2_font_unifont_t_chinese2); u8g2.setCursor(0, 60); u8g2.print(dht20.getHumidity()*100); } while ( u8g2.nextPage() ); delay(1000); } 4.显示: 可以看到温湿度读取出来了,但中文只显示了一个字,不知道哪里设置的有问题,后面再研究下。这个透明屏幕加上摄像头再利用FireBeetle 2 ESP32-S3运行ai,应该可以实现在屏幕显示实景和实景框加文字的ai效果,后面有时间再测试下。 |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed