首页
留言板
友链
统计
Search
1
树莓派换源最新教程及注意事项(更换为清华源)
1,516 阅读
2
Alist上传大文件报错Request failed with status code 413
637 阅读
3
google colab打包下载文件夹
609 阅读
4
Luat Air780E/Air700E使用MQTT协议接入巴法云物联网平台
369 阅读
5
Luat Air780E/Air700E获取设备经纬度后使用MQTT协议发送至巴法云
339 阅读
嵌入式笔记
stm32
esp8266
raspberry-pi
esp32
机器视觉笔记
opencv
yolo
typecho笔记
vps
typecho美化
悄悄话
登录
Search
标签搜索
esp8266
air700e
typecho
onenet
mediapipe
悄悄话
星星
累计撰写
34
篇文章
累计收到
24
条评论
首页
栏目
嵌入式笔记
stm32
esp8266
raspberry-pi
esp32
机器视觉笔记
opencv
yolo
typecho笔记
vps
typecho美化
悄悄话
页面
留言板
友链
统计
搜索到
9
篇与
的结果
2023-02-25
ESP8266通过MQTT(旧版)连接onenet平台
#include <ESP8266WiFi.h> #include <PubSubClient.h> #include <ArduinoJson.h> #include <Ticker.h> #include <SimpleDHT.h> #define WIFI_DEBUG 0 //1:使用一键配网,其它值则使用默认无线账号密码 #define ONENET_DISCONNECTED 1 //已经断开 #define ONENET_CONNECTED 2 //已经连接上 #define ONENET_RECONNECT 3 //重连成功 int pinDHT11 = 2; //设置DHT11的引脚 SimpleDHT11 dht11(pinDHT11); #define VER "ESP8266_MQTT_V1.0" //版本号 const char* ssid = "########";//wifi账号 const char* password = "########";//wifi密码 /*OneNet*/ PubSubClient mqttClient; const char* mqttServer = "183.230.40.39";//mqtt服务器 const uint16_t mqttPort = 6002; //端口号 #define onenet_productId "########" //产品ID #define onenet_deviceId "########" //设备ID #define onenet_apiKey "########" //API_KEY int state; Ticker delayTimer; WiFiClient espClient; /* 延时N秒 */ void delayNs(uint8_t m){ for(uint8_t index = 0;index<m;index ++){ delay(1000); ESP.wdtFeed(); } } /* 延时重启 */ void delayRestart(float t) { Serial.print("Restart after "); Serial.print(t); Serial.println("s"); delayTimer.attach(t, []() { Serial.println("\r\nRestart now!"); ESP.restart(); }); } /* 自动连接 */ bool autoConfig() { WiFi.begin(); for (int i = 0; i < 20; i++) { if (WiFi.status() == WL_CONNECTED) { Serial.println("AutoConfig Success"); Serial.printf("SSID:%s\r\n", WiFi.SSID().c_str()); Serial.printf("PSW:%s\r\n", WiFi.psk().c_str()); WiFi.printDiag(Serial); return true; } else { Serial.print("AutoConfig Waiting......"); Serial.println(WiFi.status()); delay(1000); } } Serial.println("AutoConfig Faild!" ); return false; } /* 一键配网 */ void smartConfig() { WiFi.mode(WIFI_STA); Serial.println("\r\nWait for Smartconfig"); WiFi.beginSmartConfig(); while (1) { Serial.print("."); digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); if (WiFi.smartConfigDone()) { Serial.println("SmartConfig Success"); Serial.printf("SSID:%s\r\n", WiFi.SSID().c_str()); Serial.printf("PSW:%s\r\n", WiFi.psk().c_str()); WiFi.setAutoConnect(true); // 设置自动连接 break; } delay(1000); // 这个地方一定要加延时,否则极易崩溃重启 } } /* 连接OneNet */ int connectToOneNetMqtt(){ int cnt = 0; while(!mqttClient.connected()){ ESP.wdtFeed(); cnt++; Serial.println("Connect to OneNet MQTT..."); if (mqttClient.connect(onenet_deviceId,onenet_productId,onenet_apiKey)) { Serial.println("connect success!"); return ONENET_RECONNECT; } else { Serial.print("connect fail!"); Serial.println(" try again in 5 seconds"); delayNs(5); } if(cnt >=10){ //只做10次连接到OneNet,连接不上重启8266 cnt = 0; delayRestart(1); } } return ONENET_CONNECTED; } /* 云端下发 */ void callback(char* topic, byte* payload, unsigned int length) { Serial.print("Message arrived ["); Serial.print(topic); Serial.print("] "); for (int i = 0; i < length; i++) { Serial.print((char)payload[i]); } Serial.println(); if ((char)payload[0] == '1') { digitalWrite(LED_BUILTIN, LOW); } else { digitalWrite(LED_BUILTIN, HIGH); } } /* 发布温度信息 */ void Temp_pubMQTTmsg(uint32_t data){ long lastMsg = 0; char msg[50]; char tmp[28]; char d[3]; snprintf(tmp,sizeof(tmp),"{\"Temp\":%d}",data); uint16_t streamLen= strlen(tmp); d[0]='\x03'; d[1] = (streamLen >> 8); d[2] = (streamLen & 0xFF); snprintf(msg,sizeof(msg),"%c%c%c%s",d[0],d[1],d[2],tmp); mqttClient.publish("$dp", (uint8_t*)msg,streamLen+3,false); } /* 发布湿度信息 */ void Humi_pubMQTTmsg(uint32_t data){ long lastMsg = 0; char msg[50]; char tmp[28]; char d[3]; snprintf(tmp,sizeof(tmp),"{\"Humi\":%d}",data); uint16_t streamLen= strlen(tmp); d[0]='\x03'; d[1] = (streamLen >> 8); d[2] = (streamLen & 0xFF); snprintf(msg,sizeof(msg),"%c%c%c%s",d[0],d[1],d[2],tmp); mqttClient.publish("$dp", (uint8_t*)msg,streamLen+3,false); } /* 初始化系统 */ void initSystem(){ int cnt = 0; Serial.begin (115200); Serial.println("\r\n\r\nStart ESP8266 MQTT"); Serial.print("Firmware Version:"); Serial.println(VER); Serial.print("SDK Version:"); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); Serial.println(ESP.getSdkVersion()); ESP.wdtEnable(5000); if(WIFI_DEBUG==1)//开启一键配网模式 { if (!autoConfig()) { Serial.println("Start smartConfig"); smartConfig(); } } else { WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); cnt++; Serial.print("."); if(cnt>=40){ cnt = 0; //重启系统 delayRestart(1); } } } Serial.print("WIFI Connect \r\n"); } /* 初始化ONENET通信 */ void initOneNetMqtt(){ mqttClient.setServer(mqttServer,mqttPort); mqttClient.setClient(espClient); mqttClient.setCallback(callback); } /* 初始化 */ void setup() { initSystem(); initOneNetMqtt(); } /* 主函数 */ void loop() { ESP.wdtFeed(); state = connectToOneNetMqtt(); Serial.println(WiFi.status()); if(state == ONENET_RECONNECT){ mqttClient.loop(); } else if(state == ONENET_CONNECTED){ // read without samples. byte temperature = 0; byte humidity = 0; int err = SimpleDHTErrSuccess; if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err)); Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); return; } Serial.print("Sample OK: "); Serial.print((float)temperature); Serial.print(" *C, "); Serial.print((float)humidity); Serial.println(" H"); Temp_pubMQTTmsg((float)temperature); Humi_pubMQTTmsg((float)humidity); mqttClient.loop(); } delay(2000); }
2023年02月25日
75 阅读
0 评论
0 点赞
2023-02-03
ESP8266延时函数与定时器对比及注意事项
delay()PKmillis()delay()函数 delay()函数的输入参数为int整型值。这个数字表示程序在进入下一行代码之前必须等待的时间,单位是毫秒。当调用 delay(1000) 时,程序在这一行停止1秒。{message type="warning" content=" 注意:delay()函数是一个阻塞函数。阻塞函数阻止程序运行其他函数,直到该任务完成。如果需要多个任务同时发生则不能使用delay()函数。对于大多数项目,应避免使用延迟函数,而使用定时器。"/}millis()函数 millis()函数可以返回自程序首次启动以来所经过的毫秒数,最长可记录接近50天左右的时间。如果超出记录时间上限,记录将从0重新开始。{message type="warning" content="注意:millis()函数的返回值为无符号长整型数据(unsigned long time), 如果将该数值与整型数据或其它数据类型进行运算,运行结果将产生错误。"/}millis()函数的优点 为什么这个函数是有用的?因为通过使用一些简单的数学运算就可以在不阻塞程序的情况下验证已经过去了多少时间。 :@(得意) 下方是使用millis()函数控制LED灯闪烁的示例程序。const int ledPin = 2; // 设置LED的引脚为GPIO2 int ledState = LOW; // 设置初始化LED状态 unsigned long previousMillis = 0; // 设置初始化时间,为无符号长整型数据 const long interval = 1000; // 设置闪烁间隔,为无符号长整型数据 void setup() { // 初始化LED引脚 pinMode(ledPin, OUTPUT); } void loop() { unsigned long currentMillis = millis();//获取当前时间,为无符号长整形数据 if (currentMillis - previousMillis >= interval) { //当与初始时间差大于设定值时就闪烁 // 复位初始时间为该时刻的时间 previousMillis = currentMillis; // LED翻转程序 if (ledState == LOW) { ledState = HIGH; } else { ledState = LOW; } digitalWrite(ledPin, ledState); } }{music id="1896892542" color="#1989fa" /}
2023年02月03日
139 阅读
0 评论
0 点赞
2023-01-24
常用ESP8266/ESP32 GPIO引脚图
NodeMCU GPIO引脚图{lamp/} ESP-01S GPIO引脚图{lamp/} {lamp/}ESP32开发板 GPIO引脚图
2023年01月24日
338 阅读
0 评论
0 点赞
2023-01-24
ESP8266连接PCF8591外设的部分问题及解决方法
第一步: 在Arduino IDE中点击 工具>管理库>搜索PCF8591,安装Adafruit PCF8591的库包。第二步: 连接好PCF8591和ESP8266的IIC通信线。第三步: 在Arduino IDE中点击 文件>示例>Adafruit PCF8591 打开PCF8591的示例文件,上传运行即可。PCF8591示例文件:#include <Adafruit_PCF8591.h> // 设置VCC电压为5V,可更改为3.3V #define ADC_REFERENCE_VOLTAGE 5.0 Adafruit_PCF8591 pcf = Adafruit_PCF8591(); void setup() { Serial.begin(115200); while (!Serial) delay(10); Serial.println("# Adafruit PCF8591 demo"); if (!pcf.begin()) { Serial.println("# Adafruit PCF8591 not found!"); while (1) delay(10); } Serial.println("# Adafruit PCF8591 found"); pcf.enableDAC(true); Serial.println("AIN0, AIN1, AIN2, AIN3"); } uint8_t dac_counter = 0; void loop() { // Make a triangle wave on the DAC output pcf.analogWrite(dac_counter++); Serial.print(int_to_volts(pcf.analogRead(0), 8, ADC_REFERENCE_VOLTAGE)); Serial.print("V, "); Serial.print(int_to_volts(pcf.analogRead(1), 8, ADC_REFERENCE_VOLTAGE)); Serial.print("V, "); Serial.print(int_to_volts(pcf.analogRead(2), 8, ADC_REFERENCE_VOLTAGE)); Serial.print("V, "); Serial.print(int_to_volts(pcf.analogRead(3), 8, ADC_REFERENCE_VOLTAGE)); Serial.print("V"); Serial.println(""); delay(1000); } float int_to_volts(uint16_t dac_value, uint8_t bits, float logic_level) { return (((float)dac_value / ((1 << bits) - 1)) * logic_level); }{alert type="warning"}常见问题 上传程序后串口输出 Adafruit PCF8591 not found!解决:检查IIC总线和供电线是否连接正确使用该链接中的程序 ESP8266获取外设IIC地址 检查PCF8591的IIC地址,并把if (!pcf.begin()) { Serial.println("# Adafruit PCF8591 not found!");替换成: if (!pcf.begin(0x48)) { Serial.println("# Adafruit PCF8591 not found!"); //0x48是通过查询IIC地址的程序查询出的PCF8591IIC地址使用Wire.h库修改ESP8266的模拟IIC串口为其他GPIO#include <Wire.h>//导入Wire.h函数库 void setup() { //在上述程序的setup函数中添加Wire.begin(0,2);使用GPIO0和GPIO2作为IIC通信串口 Serial.begin(115200); while (!Serial) delay(10); Wire.begin(0,2);{/alert}
2023年01月24日
175 阅读
0 评论
3 点赞
2023-01-24
ESP8266连接SSD1306 OLED显示屏
SSD1306安装驱动库Arduino IDE安装SSD1306驱动库文件 管理库中搜索并安装 Adafruit_SSD1306 库,如下图所示。 SSD1306像素排列OLED屏幕,最终都可以抽象为像素点阵,想显示什么内容就把具体位置的像素点亮起来。比如SSD1306就是一个128X64像素点阵。在坐标系中,左上角是原点,向右是X轴,向下是Y轴。ESP8266与SSD1306接线图SSD1306ESP8266VDD3.3VGNDGNDSCLSCLSDASDA{message type="warning" content="注:NodeMCU默认IIC通信串口SDA为GPIO4,SDA为GPIO5,如需切换其他模拟IIC串口,需调用Wire库进行切换。SSD1306的IIC地址可能与程序中默认IIC地址不同,需先扫描出SSD1306的IIC地址再进行修改。"/} 搜索IIC地址程序 Adafruit_SSD1306示例程序#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) // The pins for I2C are defined by the Wire-library. // On an arduino UNO: A4(SDA), A5(SCL) // On an arduino MEGA 2560: 20(SDA), 21(SCL) // On an arduino LEONARDO: 2(SDA), 3(SCL), ... #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///<修改为自己用IIC搜索程序搜索的IIC地址 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define NUMFLAKES 10 // Number of snowflakes in the animation example #define LOGO_HEIGHT 16 #define LOGO_WIDTH 16 static const unsigned char PROGMEM logo_bmp[] = { 0b00000000, 0b11000000, 0b00000001, 0b11000000, 0b00000001, 0b11000000, 0b00000011, 0b11100000, 0b11110011, 0b11100000, 0b11111110, 0b11111000, 0b01111110, 0b11111111, 0b00110011, 0b10011111, 0b00011111, 0b11111100, 0b00001101, 0b01110000, 0b00011011, 0b10100000, 0b00111111, 0b11100000, 0b00111111, 0b11110000, 0b01111100, 0b11110000, 0b01110000, 0b01110000, 0b00000000, 0b00110000 }; void setup() { Serial.begin(9600); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever } // Show initial display buffer contents on the screen -- // the library initializes this with an Adafruit splash screen. display.display(); delay(2000); // Pause for 2 seconds // Clear the buffer display.clearDisplay(); // Draw a single pixel in white display.drawPixel(10, 10, SSD1306_WHITE); // Show the display buffer on the screen. You MUST call display() after // drawing commands to make them visible on screen! display.display(); delay(2000); // display.display() is NOT necessary after every single drawing command, // unless that's what you want...rather, you can batch up a bunch of // drawing operations and then update the screen all at once by calling // display.display(). These examples demonstrate both approaches... testdrawline(); // Draw many lines testdrawrect(); // Draw rectangles (outlines) testfillrect(); // Draw rectangles (filled) testdrawcircle(); // Draw circles (outlines) testfillcircle(); // Draw circles (filled) testdrawroundrect(); // Draw rounded rectangles (outlines) testfillroundrect(); // Draw rounded rectangles (filled) testdrawtriangle(); // Draw triangles (outlines) testfilltriangle(); // Draw triangles (filled) testdrawchar(); // Draw characters of the default font testdrawstyles(); // Draw 'stylized' characters testscrolltext(); // Draw scrolling text testdrawbitmap(); // Draw a small bitmap image // Invert and restore display, pausing in-between display.invertDisplay(true); delay(1000); display.invertDisplay(false); delay(1000); testanimate(logo_bmp, LOGO_WIDTH, LOGO_HEIGHT); // Animate bitmaps } void loop() { } void testdrawline() { int16_t i; display.clearDisplay(); // Clear display buffer for(i=0; i<display.width(); i+=4) { display.drawLine(0, 0, i, display.height()-1, SSD1306_WHITE); display.display(); // Update screen with each newly-drawn line delay(1); } for(i=0; i<display.height(); i+=4) { display.drawLine(0, 0, display.width()-1, i, SSD1306_WHITE); display.display(); delay(1); } delay(250); display.clearDisplay(); for(i=0; i<display.width(); i+=4) { display.drawLine(0, display.height()-1, i, 0, SSD1306_WHITE); display.display(); delay(1); } for(i=display.height()-1; i>=0; i-=4) { display.drawLine(0, display.height()-1, display.width()-1, i, SSD1306_WHITE); display.display(); delay(1); } delay(250); display.clearDisplay(); for(i=display.width()-1; i>=0; i-=4) { display.drawLine(display.width()-1, display.height()-1, i, 0, SSD1306_WHITE); display.display(); delay(1); } for(i=display.height()-1; i>=0; i-=4) { display.drawLine(display.width()-1, display.height()-1, 0, i, SSD1306_WHITE); display.display(); delay(1); } delay(250); display.clearDisplay(); for(i=0; i<display.height(); i+=4) { display.drawLine(display.width()-1, 0, 0, i, SSD1306_WHITE); display.display(); delay(1); } for(i=0; i<display.width(); i+=4) { display.drawLine(display.width()-1, 0, i, display.height()-1, SSD1306_WHITE); display.display(); delay(1); } delay(2000); // Pause for 2 seconds } void testdrawrect(void) { display.clearDisplay(); for(int16_t i=0; i<display.height()/2; i+=2) { display.drawRect(i, i, display.width()-2*i, display.height()-2*i, SSD1306_WHITE); display.display(); // Update screen with each newly-drawn rectangle delay(1); } delay(2000); } void testfillrect(void) { display.clearDisplay(); for(int16_t i=0; i<display.height()/2; i+=3) { // The INVERSE color is used so rectangles alternate white/black display.fillRect(i, i, display.width()-i*2, display.height()-i*2, SSD1306_INVERSE); display.display(); // Update screen with each newly-drawn rectangle delay(1); } delay(2000); } void testdrawcircle(void) { display.clearDisplay(); for(int16_t i=0; i<max(display.width(),display.height())/2; i+=2) { display.drawCircle(display.width()/2, display.height()/2, i, SSD1306_WHITE); display.display(); delay(1); } delay(2000); } void testfillcircle(void) { display.clearDisplay(); for(int16_t i=max(display.width(),display.height())/2; i>0; i-=3) { // The INVERSE color is used so circles alternate white/black display.fillCircle(display.width() / 2, display.height() / 2, i, SSD1306_INVERSE); display.display(); // Update screen with each newly-drawn circle delay(1); } delay(2000); } void testdrawroundrect(void) { display.clearDisplay(); for(int16_t i=0; i<display.height()/2-2; i+=2) { display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, SSD1306_WHITE); display.display(); delay(1); } delay(2000); } void testfillroundrect(void) { display.clearDisplay(); for(int16_t i=0; i<display.height()/2-2; i+=2) { // The INVERSE color is used so round-rects alternate white/black display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, SSD1306_INVERSE); display.display(); delay(1); } delay(2000); } void testdrawtriangle(void) { display.clearDisplay(); for(int16_t i=0; i<max(display.width(),display.height())/2; i+=5) { display.drawTriangle( display.width()/2 , display.height()/2-i, display.width()/2-i, display.height()/2+i, display.width()/2+i, display.height()/2+i, SSD1306_WHITE); display.display(); delay(1); } delay(2000); } void testfilltriangle(void) { display.clearDisplay(); for(int16_t i=max(display.width(),display.height())/2; i>0; i-=5) { // The INVERSE color is used so triangles alternate white/black display.fillTriangle( display.width()/2 , display.height()/2-i, display.width()/2-i, display.height()/2+i, display.width()/2+i, display.height()/2+i, SSD1306_INVERSE); display.display(); delay(1); } delay(2000); } void testdrawchar(void) { display.clearDisplay(); display.setTextSize(1); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw white text display.setCursor(0, 0); // Start at top-left corner display.cp437(true); // Use full 256 char 'Code Page 437' font // Not all the characters will fit on the display. This is normal. // Library will draw what it can and the rest will be clipped. for(int16_t i=0; i<256; i++) { if(i == '\n') display.write(' '); else display.write(i); } display.display(); delay(2000); } void testdrawstyles(void) { display.clearDisplay(); display.setTextSize(1); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw white text display.setCursor(0,0); // Start at top-left corner display.println(F("Hello, world!")); display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text display.println(3.141592); display.setTextSize(2); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.print(F("0x")); display.println(0xDEADBEEF, HEX); display.display(); delay(2000); } void testscrolltext(void) { display.clearDisplay(); display.setTextSize(2); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.setCursor(10, 0); display.println(F("scroll")); display.display(); // Show initial text delay(100); // Scroll in various directions, pausing in-between: display.startscrollright(0x00, 0x0F); delay(2000); display.stopscroll(); delay(1000); display.startscrollleft(0x00, 0x0F); delay(2000); display.stopscroll(); delay(1000); display.startscrolldiagright(0x00, 0x07); delay(2000); display.startscrolldiagleft(0x00, 0x07); delay(2000); display.stopscroll(); delay(1000); } void testdrawbitmap(void) { display.clearDisplay(); display.drawBitmap( (display.width() - LOGO_WIDTH ) / 2, (display.height() - LOGO_HEIGHT) / 2, logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1); display.display(); delay(1000); } #define XPOS 0 // Indexes into the 'icons' array in function below #define YPOS 1 #define DELTAY 2 void testanimate(const uint8_t *bitmap, uint8_t w, uint8_t h) { int8_t f, icons[NUMFLAKES][3]; // Initialize 'snowflake' positions for(f=0; f< NUMFLAKES; f++) { icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width()); icons[f][YPOS] = -LOGO_HEIGHT; icons[f][DELTAY] = random(1, 6); Serial.print(F("x: ")); Serial.print(icons[f][XPOS], DEC); Serial.print(F(" y: ")); Serial.print(icons[f][YPOS], DEC); Serial.print(F(" dy: ")); Serial.println(icons[f][DELTAY], DEC); } for(;;) { // Loop forever... display.clearDisplay(); // Clear the display buffer // Draw each snowflake: for(f=0; f< NUMFLAKES; f++) { display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, SSD1306_WHITE); } display.display(); // Show the display buffer on the screen delay(200); // Pause for 1/10 second // Then update coordinates of each flake... for(f=0; f< NUMFLAKES; f++) { icons[f][YPOS] += icons[f][DELTAY]; // If snowflake is off the bottom of the screen... if (icons[f][YPOS] >= display.height()) { // Reinitialize to a random position, just off the top icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width()); icons[f][YPOS] = -LOGO_HEIGHT; icons[f][DELTAY] = random(1, 6); } } } }
2023年01月24日
174 阅读
0 评论
0 点赞
2023-01-24
ESP8266使用DHT11传感器读取温湿度数据
esp8266和温湿度传感器接线引脚图:DHT11ESP8266VCC3.3VGNDGNDDATAGPIO2准备工作: 在 Arduino IDE上方选项处-> 工具—>管理库,然后搜索dht11,安装如图所示库: 示例程序:#include <SimpleDHT.h> // for DHT11, // VCC: 5V or 3V // GND: GND // DATA: 2 int pinDHT11 = 2; SimpleDHT11 dht11(pinDHT11); void setup() { Serial.begin(115200); } void loop() { // start working... Serial.println("================================="); Serial.println("Sample DHT11..."); // read without samples. byte temperature = 0; byte humidity = 0; int err = SimpleDHTErrSuccess; if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err)); Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(1000); return; } Serial.print("Sample OK: "); Serial.print((int)temperature); Serial.print(" *C, "); Serial.print((int)humidity); Serial.println(" H"); // DHT11 sampling rate is 1HZ. delay(1500); }串口输出如图所示:
2023年01月24日
139 阅读
0 评论
0 点赞
2023-01-24
ESP8266恢复原厂固件工具
该压缩包集成ESP8266使用方法、原厂固件、烧录工具和恢复教程,整理不易,留下脚印可见 ::(捂嘴笑) {lamp/}隐藏内容,请前往内页查看详情
2023年01月24日
306 阅读
4 评论
0 点赞
1
2