完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在尝试组装带有日志记录和 LCD 显示屏的简单气压计,但看起来使用相同的引脚来完成某些不允许或至少在某些范围内不允许的任务。我正在使用带有板载 ESP8266 的 NodeMCUv3,用于检索数据的 bmp280 传感器,ds3231 时钟能够不断使用时钟而不会中断 SD 卡模块将数据和时间写入文件,LCD 16x2 显示屏显示当前时间和传感器数据,另外我我正在使用电报机器人来访问需要一些中断的当前传感器数据。
我确实使用随 Arduino IDE 一起提供的标准代码单独测试了所有模块,并且一切正常,直到我将许多草图合并为一个。经过多次尝试,我发现除了 SD 卡模块外,每个模块都可以在草图中工作,并且看起来与 LCD 冲突。不幸的是,我没有找到如何解决问题的信息,也没有剩余的可用引脚来避免重叠。奇怪的是,连接到 BMP280 和 DS3231 的相同重叠引脚彼此不冲突并且可以一起工作。另一方面,LCD 和 SD 卡没有。任何想法如何解决它?谢谢。 如果代码的“SD”部分取消注释 LCD 显示屏开始显示垃圾 代码: 代码:全选#include #include // Include the BMP280_DEV.h library The .cpp file was modified by changing altitude measuring value #include #include #include #include #include \"RTClib.h\" #include #include #include #include // SD File myFile; // SD // LCD LiquidCrystal lcd(D6, D5, D0, D7, D3, D4); // LCD // BME280 float temperature, pressure, altitude; // Create the temperature, pressure and altitude variables BMP280_DEV bmp280; // Instantiate (create) a BMP280_DEV object and set-up for I2C operation BME280I2C bme; // BME280 /* // DS3231 RTC_DS3231 rtc; char daysOfTheWeek[7][12] = {\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"}; // DS3231 */ unsigned long previousmillis = 0; const long interval = 1000; float temp(NAN), hum(NAN), pres(NAN); //TELEGRAM // Wifi network station credentials #define WIFI_SSID \"Untitled\" #define WIFI_PASSWORD \"Untitled\" // Telegram BOT Token (Get from Botfather) #define BOT_TOKEN \"1804515083:AAE_pQS0Hf911B_VG5Tty4STfuBOG8z2fsc\" const unsigned long BOT_MTBS = 1000; // mean time between scan messages X509List cert(TELEGRAM_CERTIFICATE_ROOT); WiFiClientSecure secured_client; UniversalTelegramBot bot(BOT_TOKEN, secured_client); unsigned long bot_lasttime; // last time messages\' scan has been done void handleNewMessages(int numNewMessages) { Serial.print(\"handleNewMessages \"); Serial.println(numNewMessages); for (int i = 0; i < numNewMessages; i++) { String chat_id = bot.messages.chat_id; String text = bot.messages.text; String from_name = bot.messages.from_name; if (from_name == \"\") from_name = \"Guest\"; if (text) { String PresText; String TempText; String Temp2Text; char pressureBuffer[32]; char temperatureBuffer[32]; char temperature2Buffer[32]; //float rtcTemp = rtc.getTemperature(); PresText += \" hPa\"; dtostrf(pres / 100, 16, 2, pressureBuffer); bot.sendMessage(chat_id, pressureBuffer + PresText, \"\"); delay(200); TempText = \" *C\"; dtostrf(temp, 16, 2, temperatureBuffer); bot.sendMessage(chat_id, temperatureBuffer + TempText, \"\"); //Temp2Text = \" *C\"; //dtostrf(rtcTemp, 16, 2, temperature2Buffer); //bot.sendMessage(chat_id, temperature2Buffer + Temp2Text, \"\"); } if (text == \"/start\") { String welcome = \"Welcome to Universal Arduino Telegram Bot library, \" + from_name + \".\\n\"; welcome += \"This is Flash Led Bot example.\\n\\n\"; welcome += \"/ledon : to switch the Led ON\\n\"; welcome += \"/ledoff : to switch the Led OFF\\n\"; welcome += \"/status : Returns current status of LED\\n\"; bot.sendMessage(chat_id, welcome, \"Markdown\"); } } } // TELEGRAM void printBME280Data ( Stream* client ) { BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); BME280::PresUnit presUnit(BME280::PresUnit_Pa); bme.read(pres, temp, hum, tempUnit, presUnit); client->print(\"Temp: \"); client->print(temp); client->print(\"°\"+ String(tempUnit == BME280::TempUnit_Celsius ? \'C\' :\'F\')); client->print(\"\\t\\tHumidity: \"); client->print(hum); client->print(\"% RH\"); client->print(\"\\t\\tPressure: \"); client->print(pres); client->println(\"Pa\"); lcd.clear(); lcd.setCursor(0,1); lcd.print (pres / 100); lcd.print (F(\"hPa \")); lcd.print(temp); delay(1000); } void setup() { Serial.begin(115200); // LCD lcd.begin(16, 2); // LCD Wire.begin(); while(!bme.begin()) { Serial.println(\"Could not find BME280 sensor!\"); delay(1000); } switch(bme.chipModel()) { case BME280::ChipModel_BME280: Serial.println(\"Found BME280 sensor! Success.\"); break; case BME280::ChipModel_BMP280: Serial.println(\"Found BMP280 sensor! No Humidity available.\"); break; default: Serial.println(\"Found UNKNOWN sensor! Error!\"); } /* // BME280 if(bmp280.begin(BMP280_I2C_ALT_ADDR)) { // Default initialisation with alternative I2C address (0x76), place the BMP280 into SLEEP_MODE Serial.println(\"bmp280.began\"); //bmp280.setPresOversampling(OVERSAMPLING_X4); // Set the pressure oversampling to X4 //bmp280.setTempOversampling(OVERSAMPLING_X1); // Set the temperature oversampling to X1 //bmp280.setIIRFilter(IIR_FILTER_4); // Set the IIR filter to setting 4 bmp280.setTimeStandby(TIME_STANDBY_2000MS); // Set the standby time to 2 seconds Serial.println(\"enter standby mode\"); bmp280.startNormalConversion(); // Start BMP280 continuous conversion in NORMAL_MODE Serial.println(\"enter normal mode\"); } // BME280 */ /* // SD Serial.print(\"Initializing SD card...\"); if (!SD.begin(D8)) { Serial.println(\"initialization failed!\"); return; } Serial.println(\"initialization done.\"); // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. myFile = SD.open(\"test.txt\", FILE_WRITE); // if the file opened okay, write to it: if (myFile) { String Comma = \",\"; Comma = \", \"; Serial.print(\"Writing to test.txt...\"); myFile.println(Comma + press + Comma + temp); // close the file: myFile.close(); Serial.println(\"done.\"); } else { // if the file didn\'t open, print an error: Serial.println(\"error opening test.txt\"); } // re-open the file for reading: myFile = SD.open(\"test.txt\"); if (myFile) { Serial.println(\"test.txt:\"); // read from the file until there\'s nothing else in it: while (myFile.available()) { Serial.write(myFile.read()); } // close the file: myFile.close(); } else { // if the file didn\'t open, print an error: Serial.println(\"error opening test.txt\"); } // SD */ // TELEGRAM Serial.println(); // attempt to connect to Wifi network: Serial.print(\"Connecting to Wifi SSID \"); Serial.print(WIFI_SSID); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); secured_client.setTrustAnchors(&cert); // Add root certificate for api.telegram.org while (WiFi.status() != WL_CONNECTED) { Serial.print(\".\"); delay(400); } Serial.print(\"\\nWiFi connected. IP address: \"); Serial.println(WiFi.localIP()); Serial.print(\"Retrieving time: \"); configTime(0, 0, \"pool.ntp.org\"); // get UTC time via NTP time_t now = time(nullptr); while (now < 24 * 3600) { Serial.print(\".\"); delay(200); now = time(nullptr); } Serial.println(now); // TELEGRAM /* if (! rtc.begin()) { Serial.println(\"Couldn\'t find RTC\"); Serial.flush(); abort(); } if (rtc.lostPower()) { Serial.println(\"RTC lost power, let\'s set the time!\"); // When time needs to be set on a new device, or after a power loss, the // following line sets the RTC to the date & time this sketch was compiled // rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // This line sets the RTC with an explicit date & time, for example to set // January 21, 2014 at 3am you would call: // rtc.adjust(DateTime(2021, 6, 19, 17, 19, 0)); } // When time needs to be re-set on a previously configured device, the // following line sets the RTC to the date & time this sketch was compiled // rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // This line sets the RTC with an explicit date & time, for example to set // January 21, 2014 at 3am you would call: // rtc.adjust(DateTime(2021, 7, 31, 16, 12, 0)); // DS3231 */ } void loop(){ Serial.println(\"enter loop\"); /* BME280I2C bme; Stream* client float temp(NAN), hum(NAN), pres(NAN); BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); BME280::PresUnit presUnit(BME280::PresUnit_Pa); bme.read(pres, temp, hum, tempUnit, presUnit); // LCD //DateTime now = rtc.now(); lcd.clear(); //lcd.print(now.day(), DEC); //lcd.print(\'/\'); //lcd.print(now.month(), DEC); //lcd.print(\" \"); //lcd.print(now.hour(), DEC); //lcd.print(\':\'); //lcd.print(now.minute(), DEC); //lcd.print(\':\'); //lcd.print(now.second(), DEC); // lcd.print(rtc.getTemperature()); // lcd.print(F(\"*C\")); // go to row 1 column 0, note that this is indexed at 0 lcd.setCursor(0,1); client->lcd.print (pres); lcd.print (F(\"hPa \")); lcd.print(temp); // lcd.print(F(\"*C \")); */ printBME280Data(&Serial); delay(500); /* String Comma = \", \"; Comma = \", \"; char pressureBuffer[32]; char temperatureBuffer[32]; char temperature2Buffer[32]; //float rtcTemp = rtc.getTemperature(); //uint8_t ifBuffer = now.minute(); //uint8_t ifBuffer2 = now.second(); if (ifBuffer == 0 && ifBuffer2 == 0) { for (int i = 0; i = 1; i++) { myFile = SD.open(\"DATA.txt\", FILE_WRITE); // if the file opened okay, write to it: if (myFile) { myFile.println(now.day() + Comma + now.month() + Comma + now.year() + Comma + now.hour() + Comma + now.minute() + Comma + now.second() + Comma + pressure + Comma + temperature + Comma + rtc.getTemperature() + Comma + altitude); // close the file: myFile.close(); } else { // if the file didn\'t open, print an error: Serial.println(\"error opening DATA.txt\"); }}} */ // LCD // TELEGRAM if (millis() - bot_lasttime > BOT_MTBS) { int numNewMessages = bot.getUpdates(bot.last_message_received + 1); while (numNewMessages) { Serial.println(\"got response\"); handleNewMessages(numNewMessages); numNewMessages = bot.getUpdates(bot.last_message_received + 1); } bot_lasttime = millis(); } // TELEGRAM Serial.println(\"exit loop\"); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
968 浏览 1 评论
553浏览 6评论
462浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
447浏览 5评论
448浏览 4评论
418浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 00:50 , Processed in 0.673356 second(s), Total 75, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号