Hi - I'm using the Wemos D1 mini (esp8266 board) to build a weather recording system using the Arduino IDE, and seem to have run into a strange issue I can't get around:
I've setup a Wemos with SD card reader, I2C sensors (BME280 / BH1750 / DS3231) which publishes its data via Wifi. This all works just fine. So I thought I'd add a serial link to a new sensor using the espSoftwareSerial library and discovered a strange thing: The new serial port can transmit just fine but will not receive data unless the Arduino IDEs 'Serial Monitor' window is open!
If I close the serial monitor window, the softwareSerial port stops receiving data, but can still transmit.
If I open the IDE's Serial Monitor window, the softwareSerial port can transmit AND receive ok.
Have anyone out there ever come across this or similar behavior with SoftwareSerial?
Regards Jppx1967.
.
.
#include <SoftwareSerial.h>
.
.
.
SoftwareSerial swSer(0, 2, false, 64);
.
.
void setup()
{
pinMode(2, OUTPUT);
pinMode(0, INPUT);
.
.
swSer.begin(57600);
}
void loop()
{
.
.
.
String response = runRainGaugeCommand(input);
.
.
}
//Service Calls
void setGaugeCommand(String valx)
{
if(!valx.endsWith("\r\n"))
{
valx+= "\r\n";
}
for(int u=0; u <valx.length();u++)
{
swSer.write((char)valx);
}
}
String runRainGaugeCommand(String tak)
{
tak.replace("HTTP/1.1","");
setGaugeCommand(tak);
for(int t=0;t<6;t++)
{
delay(500);
}
String all = getRainGaugeData(tak);
swSer.flush();
return(all);
}
String getRainGaugeData(String cmd)
{
String output;
int y = 100;
while (y > 0)
{
if(swSer.available() > 0)
{
output.concat((char)swSer.read());
}
delay(4);
y--;
}
output="cmd output..." + cmd +"\r\n" + output;
swSer.flush();
return(output);
}
In the code above, I send a 'command' (runRainGaugeCommand()) to serial rain gauge /anemometer. This is received and a response is sent ok. The Wemos refused to read the serial response, if the Arduino's 'Serial Monitor' is closed. Very bizarre behavior.
Looks like you are using one of the real serial port lines for your softserial. Pin 0.
Couldnt see the wood for the trees - You nailed it! - Thank you nathancamp.
Hi jppx1967, please let me know what pins on your wemos d1 you are using. I used the GIO0 and GIO2 (label at the back of the wemos board) and D7 and D8 on the front of the board.
I'm also using NewSoftwareSerial like this.
SoftwareSerial GPRS(0,2, false, 256);
Please help