remove usage of SoftwareSerial and update docs

fixes #1
This commit is contained in:
Julian Leyh 2023-03-06 20:25:14 +01:00
parent f6b2900c1a
commit ba88dd934b
Signed by: rommudoh
GPG Key ID: AD274957DE232771
5 changed files with 38 additions and 7 deletions

View File

@ -1,12 +1,9 @@
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
// pins
const int soilPin = A0;
const int motionPin = 15;
const int serialTxPin = 4;
const int serialRxPin = 5;
// calibration values
const int airValue = 800;
@ -16,7 +13,6 @@ const int waterValue = 320;
const int minimumMoisture = 60; // When below this percentage => Alarm!
const int messageInterval = 10; // Seconds between Sound alerts
SoftwareSerial serialPlayer(serialTxPin, serialRxPin);
DFRobotDFPlayerMini player;
// use calibration values to determine the percentage
@ -29,14 +25,13 @@ int getMoisturePercent() {
void setup() {
Serial.begin(115200);
Serial.println("Hello!");
serialPlayer.begin(9600);
Serial1.begin(9600);
pinMode(motionPin, INPUT);
Serial.println("ESP8266 is ready!");
if (!player.begin(serialPlayer))
{
if (!player.begin(Serial1)) {
Serial.println("Failed initializing DFPlayerMini!");
return;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -94,3 +94,21 @@ Ansonsten wird noch die bei ESP8266 enthaltene SoftwareSerial-Schnittstelle zur
### Arduino IDE Einstellungen
Als Board sollte im Untermenü ESP8266 der Eintrag "NodeMCU 1.0 (ESP-12E Module)" ausgewählt werden. Als Schnittstelle muss die entsprechende Serielle Schnittstelle ausgewählt werden. Bei mir war es "/dev/ttyUSB0".
## Verbesserungen
### Kein SoftwareSerial benutzen
Nachdem ich mir den ESP8266 nochmal genauer angesehen habe, habe ich festgestellt, dass der Controller einen zweiten seriellen Port hat, der allerdings nur senden kann (TX1, Pin D2).
Dadurch kann ich auf die SoftwareSerial-Bibliothek verzichten und den Controller entlasten.
Hier der modifizierte Schaltplan:
![Plantmonitor_schematic_v2.jpg](Plantmonitor_schematic_v2.jpg)
Und hier die aktualisierte Breadboard-Verkabelung:
![Plantmonitor_breadboard_cables_v2.jpg](Plantmonitor_breadboard_cables_v2.jpg)
Den Quellcode habe ich mit diesem Commit ebenfalls angepasst.

View File

@ -96,3 +96,21 @@ Otherwise, I use the SoftwareSerial interface that is included with the ESP8266
### Arduino IDE Settings
As board I had to choose the entry "NodeMCU 1.0 (ESP-12E Module)" in the submenu ESP8266. As serial interface you have to choose the according serial interface. Mine was "/dev/ttyUSB0".
## Improvements
### No more SoftwareSerial
After studying the ESP8266 closely, I noticed that the controller has a second serial port, that can only send data (TX1, Pin D2).
Using this I can remove the SoftwareSerial library and take off load from the controller.
Here the modified schematic:
![Plantmonitor_schematic_v2.jpg](Plantmonitor_schematic_v2.jpg)
And here the updated Breadboard cables:
![Plantmonitor_breadboard_cables_v2.jpg](Plantmonitor_breadboard_cables_v2.jpg)
I also modified the source code with this commit.