完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
我正在使用一个 Wemos D1 Mini、一个 DFPlayer MP3 模块和一个 HC-SR501 pir 模块来创建一个电池供电的动作激活发声器。运动感应导致播放命令被发送到 MP3 播放器,并且 LED 闪烁。很简单。所有“5V”的东西都由电池供电,实际上是 ~6v。3.3v 仅用于上拉。
我正在使用 Light Sleep 模式来尽量减少空闲电流消耗。在一段时间没有运动后,它会像预期的那样进入睡眠状态,随后的运动感会使它恢复活力。一切正常,直到从睡眠中醒来。一旦它醒来,随后的运动感觉不会导致与睡眠事件之前相同的行为。它没有闪烁 LED 和播放 MP3,而是似乎什么也没做。然而,看着串口监视器它似乎暂停然后重新开始。串口监视器上的倒数计时器将显示(例如)“...10、9、8,{在我挥手的那一刻暂停} 3、2、1)。这几乎就像微处理器停止工作一样别的东西。奇怪的是,只有当我在睡眠结束后包含重新启动 SoftwareSerial 的代码时,它才会这样做。 谁能提供我可以探索的想法?我会很感激!! 代码:全选 #include #include #include #include extern "C" { #include "gpio.h" } extern "C" { #include "user_interface.h" } #define WIFI_SSID "****" #define WIFI_PASS "****" // PINS const byte ledPin = 15; //D8 const byte pirPin = 5; //D1 const byte standbyPin = 4; //D2 const byte rxPin = 12; //D6 const byte txPin = 14; //D5 //tiMING const byte sleepDelay = 20; //length of idle time (s) to wait before going to sleep const byte standbyDelay = 30; // initial delay (s) from power-up w/ standby button pressed boolean justAwoke = false; long triggerBaseline = 0; const byte WiFiTimeout = 30; // WiFi connect timeout (s) const byte mp3Volume = 10; // 0 to 30 const int numTracks = 4; int TriggerCount = 0; SoftwareSerial mySoftwareSerial(rxPin, txPin); //RX, TX DFRobotDFPlayerMini myDFPlayer; void setup() { gpio_init(); pinMode(pirPin, INPUT); pinMode(standbyPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); startSerial(); // start Serial and MySoftwareSerial startMP3(); // start DFPlayer Mini MP3 triggerBaseline = millis(); if (digitalRead(standbyPin) == LOW) { standbyMode(); } triggerBaseline = millis(); } void loop() { Serial.print("Time to sleep: " ); Serial.print(sleepDelay - ((millis() - triggerBaseline) / 1000)); Serial.println("s"); Serial.print("PIR state: " ); Serial.println(digitalRead(pirPin)); Serial.print("justAwoke state:" ); Serial.println(justAwoke); Serial.println(); while (digitalRead(pirPin) == HIGH || justAwoke == true) { Serial.println("Checkpoint A"); justAwoke = false; TriggerCount++; Serial.println(""); Serial.println("Motion triggered"); int Track = random(1, numTracks); Serial.print("Track: "); Serial.println(Track); myDFPlayer.play(Track); for (int i = 0; i <= 5; i++) { long OnTime = random(100, 1500); long OffTime = random(100, 1500); digitalWrite(ledPin, HIGH); delay(OnTime); digitalWrite(ledPin, LOW); delay(OffTime); } digitalWrite(ledPin, HIGH); triggerBaseline = millis(); } // **** SLEEP TIMER *** if ((millis() - triggerBaseline) / 1000 >= sleepDelay && digitalRead(pirPin) == LOW) { for (int i = 0; i <= 5; i++) { // rapdid pulse led digitalWrite(ledPin, LOW); delay(300); digitalWrite(ledPin, HIGH); delay(300); } sendReport(); stopMP3(); //stopSerial(); digitalWrite(ledPin, LOW); Serial.println("Entering Light Sleep."); delay(2000); lightSleep(); // put esp8266 in Light Sleep Mode delay(2000); wakeUp(); } delay(1000); } void stopSerial () { Serial.println("Stopping serial and entering Light Sleep..."); delay(500); Serial.flush(); delay(500); Serial.end(); } void startSerial() { Serial.begin(115200); while (!Serial) { } Serial.println(""); Serial.println("Serial started."); } void stopMP3 () { Serial.println("Stopping MP3..."); //mySoftwareSerial.flush(); delay(1000); mySoftwareSerial.end(); //digitalWrite(miniFETpin, LOW); // cut MP3 power Serial.println("MP3 stopped."); } void startMP3() { Serial.println("Starting MP3..."); mySoftwareSerial.begin(9600); //Initialize DLPlayer on software serial connection Serial.println("Checkpoint 1"); if (!myDFPlayer.begin(mySoftwareSerial, false)) { Serial.println("Unable to begin:"); Serial.println("1.Please recheck the connection!"); Serial.println("2.Please insert the SD card!"); while (true) { Serial.println("Starting MP3 Module..."); delay(0); // Code to compatible with ESP8266 watch dog. } } Serial.println("MP3 started."); myDFPlayer.volume(mp3Volume); Serial.println("MP3 volume set."); } void lightSleep() { wifi_station_disconnect(); wifi_set_opmode_current(NULL_MODE); wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); wifi_set_sleep_type() wifi_fpm_open(); gpio_pin_wakeup_enable(GPIO_ID_PIN(5), GPIO_PIN_INTR_HILEVEL); GPIO_PIN_INTR_HILEVEL delay(200); wifi_fpm_do_sleep(0xFFFFFFF); delay(200); } void wakeUp() { //startSerial(); digitalWrite(ledPin, HIGH); Serial.println(""); Serial.println("Just woke up!"); startMP3(); justAwoke = true; // Trigger alarm upon wake up triggerBaseline = millis(); //reset awake timer } void sendReport() { Serial.println(""); Serial.println("Sending report..."); WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASS); Serial.println(""); Serial.print("Connecting to WiFi"); long WiFiBaseline = millis(); while (WiFi.status() != WL_CONNECTED && (millis() - WiFiBaseline) / 1000 < WiFiTimeout) { delay(500); Serial.print("."); } if (WiFi.status() == WL_CONNECTED) { Serial.println(""); Serial.print("WiFi connected"); // *** Reserved for Connect and send to Adafruit IO } else { Serial.println(""); Serial.print("WiFi connection failed"); } Serial.println(""); Serial.println("Report sent."); } void standbyMode() { Serial.println("Checkpoint 3"); long standbyBaseline = millis(); while ((millis() - standbyBaseline) / 1000 < standbyDelay) { digitalWrite(ledPin, HIGH); delay(500); digitalWrite(ledPin, LOW); delay(1000); } } |
|
相关推荐
1个回答
|
|
这可能是因为在睡眠模式中,某些组件被关闭以节省电源,例如DFPlayer模块或LED。在重新唤醒后,这些组件可能需要重新初始化或启用才能正常工作。您可以尝试在唤醒后手动重新初始化这些组件并检查它们是否起作用。另外,如果睡眠期间的电流过高,可能会导致电池电量不足,因此在唤醒后检查电池电量也是一个好主意。
|
|
|
|
只有小组成员才能发言,加入小组>>
598 浏览 1 评论
552浏览 6评论
461浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
443浏览 5评论
445浏览 4评论
415浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 06:11 , Processed in 0.844387 second(s), Total 77, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号