|
我使用sht31温湿度探头 oled屏幕SH1106 显示温湿度
- #include <ss_oled.h>
- #include <Wire.h> // For IIC
- #include <Arduino.h>
- #include <ArduinoJson.h>
- #include <Adafruit_SHT31.h> //For SHT31
- #include <Adafruit_GFX.h>
- #include <Adafruit_SH1106.h> //For SH1106
- #include <ESP8266WiFi.h>
- #include <PubSubClient.h>
- #include "mqtt.h"
- #include "images.h" // images
- Adafruit_SH1106 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
- Adafruit_SHT31 sht31 = Adafruit_SHT31();
- WiFiClient esp8266Client;
- PubSubClient client(esp8266Client);
- void initWiFi() {
- WiFi.mode(WIFI_STA);
- WiFi.begin(WiFi_SSID, WiFi_Password);
- Serial.println("");
- // Wait for connection
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.print("Connected to ");
- Serial.println(WiFi_SSID);
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- }
- void initMQTT() {
- client.setServer(mqtt_server, 1883);
- while (!client.connected()) {
- client.connect(ClientId, Username, Password);
- }
- Serial.println("MQTT Connected OK!");
- }
- void MQTT_Post(float Msg1, float Msg2, String deviceID) {
- StaticJsonDocument<256> JsonSHT31_data;
- JsonSHT31_data["Ctemp"] = Msg1;
- JsonSHT31_data["Humid"] = Msg2;
- JsonSHT31_data["deviceID"] = deviceID;
- String JsonSHT31;
- serializeJson(JsonSHT31_data, JsonSHT31);
- client.publish(report_Topic, JsonSHT31.c_str());
- Serial.print(report_Topic); Serial.print("MSG:"); Serial.println(JsonSHT31);
- Serial.println("\n");
- Serial.println("MQTT Publish OK!");
- }
- void firstPage() {
- display.drawBitmap(0, 16, E_LOGO, 32, 32, 1);
- display.drawBitmap(32, 16, ES_LOGO, 32, 32 , 1);
- display.drawBitmap(64, 16, Q_LOGO, 32, 32, 1);
- display.drawBitmap(96, 16, QS_LOGO, 32, 32, 1);
- }
- void initDisp_TR() {
- if (!display.begin(SH1106_SWITCHCAPVCC, 0x3C)) {
- Serial.println(F("SH1106 allocation failed"));
- }
- if (! sht31.begin(0x44)) {
- Serial.println("Couldn't find SHT31");
- } // check
- display.begin(SH1106_SWITCHCAPVCC, 0x3C);
- display.clearDisplay();
- display.setTextColor(SH1106_WHITE);
- display.setTextSize(2);
- firstPage();
- display.display();
- delay(1000);
- display.clearDisplay();
- }
- void OLED(float Temp, float humid) {
- display.drawBitmap(2, 8, wen, 20, 20, 1);
- display.drawBitmap(22, 8, du, 20, 20, 1);
- display.drawBitmap(40, 8, maohao, 20, 20, 1);
- display.setCursor(50, 15);
- // display.println("24.73");
- display.println(String(Temp));
- display.drawBitmap(108, 8, sheshidu, 20, 20, 1);
- display.drawBitmap(2, 38, shi, 20, 20, 1);
- display.drawBitmap(22, 38, du, 20, 20, 1);
- display.drawBitmap(40, 38, maohao, 20, 20, 1);
- display.setCursor(50, 45);
- // display.println("88.88");
- display.println(String(humid));
- display.drawBitmap(108, 38, baifenhao, 20, 20, 1);
- // display.drawBitmap(32,0,manman,64,64,1); //Show 馒馒
- display.display();
- }
- void setup()
- {
- Serial.begin(115200);
- initDisp_TR();
- Serial.print("Display");
- initWiFi();
- Serial.print("WIFI");
- initMQTT();
- Serial.print("MQTT");
- }
- void loop() {
- display.clearDisplay();
- float cTemp = sht31.readTemperature();
- float humidity = sht31.readHumidity();
- OLED(cTemp, humidity);
- MQTT_Post(cTemp, humidity, devID);
- delay(10000);
- }
复制代码 显示错误的提示- In file included from C:\Users\Administrator\Desktop\温湿度计\ssd1306\ssd1306.ino:11:
- C:\Program Files (x86)\Arduino\libraries\Adafruit_SH1106/Adafruit_SH1106.h:458:75: error: extended character ↵ is not valid in an identifier
- 458 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
- | ^
- C:\Program Files (x86)\Arduino\libraries\Adafruit_SH1106/Adafruit_SH1106.h:463:56: error: extended character ↵ is not valid in an identifier
- 463 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
- | ^
- C:\Program Files (x86)\Arduino\libraries\Adafruit_SH1106/Adafruit_SH1106.h:505:75: error: extended character ↵ is not valid in an identifier
- 505 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
- | ^
- C:\Program Files (x86)\Arduino\libraries\Adafruit_SH1106/Adafruit_SH1106.h:510:56: error: extended character ↵ is not valid in an identifier
- 510 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
- | ^
- C:\Program Files (x86)\Arduino\libraries\Adafruit_SH1106/Adafruit_SH1106.h:543:75: error: extended character ↵ is not valid in an identifier
- 543 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
- | ^
- C:\Program Files (x86)\Arduino\libraries\Adafruit_SH1106/Adafruit_SH1106.h:548:56: error: extended character ↵ is not valid in an identifier
- 548 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
- | ^
- C:\Program Files (x86)\Arduino\libraries\Adafruit_SH1106/Adafruit_SH1106.h:581:75: error: extended character ↵ is not valid in an identifier
- 581 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
- | ^
- C:\Program Files (x86)\Arduino\libraries\Adafruit_SH1106/Adafruit_SH1106.h:586:56: error: extended character ↵ is not valid in an identifier
- 586 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
- | ^
- In file included from C:\Users\Administrator\Desktop\温湿度计\ssd1306\ssd1306.ino:11:
- C:\Program Files (x86)\Arduino\libraries\Adafruit_SH1106/Adafruit_SH1106.h:2217:9: error: extended character ’ is not valid in an identifier
- 2217 | You can’t perform that action at this time.
- | ^
- exit status 1
- 为开发板 NodeMCU 1.0 (ESP-12E Module) 编译时出错。
复制代码 请教大神怎么破 谢谢大家 |
|