Hi,
I'm using the hardware serial port on a Wemos D1, and have swap()ed it to the alternate pins in order to avoid the reboot-junk from causing problems on the actual device connected to it. So far, that's fine. Now I was going to do some low priority stuff with the original pins 3 & 1 by using the SoftwareSerial library. Output seems fine (I get the output from the program on my USB serial port of the PC), but I can't seem to get any input to the ESP ...
Setup looks something like this:
Serial.swap();
SoftwareSerial sSerial(3,1);
sSerial.begin(9600);
sSerial.write("Welcome\r\n");
and the output appears in my serial monitor ... anyway, I get no input through this routine:
char ssbuf[64];
void handlesSerial()
{
uint8 len;
while (len=sSerial.available()>0) {
sSerial.readBytes(ssbuf,(len>63?63:len));
ssbuf[(len>63?63:len)]=0;
sSerial.write(ssbuf);
}
}
Any idea what I'm missing here?
while (len=sSerial.available()>0)
assignment in condition is always true.
Deva_Rishi:
while (len=sSerial.available()>0)
assignment in condition is always true.
Actually, no, it's not, though the missing brackets result in "1" instead of the actual value in the buffer ... so while technically the code is wrong, it would still result in at least single letter results from the buffer, and terminate once the available() method returns "0" ... anyway, fixed that, but still doesn't read anything ...
Are there any other settings that might mess up the D3 pin on the ESP? Maybe something the swap() leaves in a way that I have to change manually in order for the softSerial to access it correctly?
Garry_G:
Actually, no, it's not, though the missing brackets result in "1" instead of the actual value in the buffer ...
i don't know where you wanted the brackets, but this results in (true>0) which is always true ! (that true==1 is true of course..) But doing more things in one line of code is something i usually leave for the compiler to do. It tends to produce code that is more readable for others that way.
Garry_G:
Are there any other settings that might mess up the D3 pin on the ESP? Maybe something the swap() leaves in a way that I have to change manually in order for the softSerial to access it correctly?
The only thing i have heard of is DMA.. but i doubt it is the case here to rule that out you could use a different pin temporarily, but more than likely it is something in the rest of your code. Are you sure handleSertial() is even called ?
This would fix the intended use:
while ((len=sSerial.available())>0)
(trust me, it's not an endless loop ... when available returns zero, the while loop ends ...)
Yes, handlesSerial is called, it's one of the calls in the main loop() function which does all the other things, too ...