I use a Robotdyn, uno+wifi r3 atmega328p+esp8266.It was functioning fine. I had got the esp and the uno to communicate, and anything I wanted logs for, I got them over the web server, both for uno and esp. Strangely, the serial communication with esp has stopped. So, I changed the setting to check esp's serial communication separately. What ever I tried to put to esp using serial monitor does not seem to reach it and vice versa. I tired the same exercise with uno, and it seems to work perfect.
I've verified the switch connectivity in the board, it does not seem to have a problem. Most of the posts online seems to explain the basics of serial connectivity based on the table provided for serial communication by robotdyn.
I do not have an idea, how to debug this further. Any leads would be very helpful.
Yes, I have my custom code both in uno and in esp.
basic protocol is;
get mtr speed on esp web server.
send "MtrSpeed:0-255" on serial to arduino
Arduino responds when speed is set to pin.
esp webserver responds.
I got a new device, to verify, and even there, I face the same issue.
When I have sw 5 and 6 on, and reset the device, my serial.println stuff comes to serial monitor, but what I give as input in serial monitor does not reach esp.
void serialEvent() {
static int cmd=0;
static String lstr="";
static String subCmd="";
while(Serial.available() > 0) {
char inChar=(char)Serial.read();
if (cmdIsSet) {
if ((inChar == '\n') || (inChar == '\r')) {
// cmd is set and subCmd is populated fully.
} else
subCmd+=inChar;
} else
lstr+=inChar;
if (inChar == ':') {
Serial.print("Received from esp - ");
if (lstr.equalsIgnoreCase("MtrSpeed:"))
cmd=CMD_MtrSpeed;
if(cmd != 0)
cmdIsSet=true;
} else if ((inChar == '\n') || (inChar == '\r')) {
if(cmdIsSet) {
switch(cmd) {
case CMD_MtrSpeed:
{
int sped=subCmd.toInt();
analogWrite(mtrPin, sped);
String resp=" MtrSpeed:"+subCmd;
Serial.println(resp);
loopSpeedSent=0;
lstr="";
subCmd="";
cmdIsSet=0;
cmd=0;
break;
}
}
}
In esp
void findConfInSerial() {
static String subCmd="";
static int cmd=0;
bool cmdIsSet=false;
static String lstr="";
while(Serial.available() > 0) {
char inChar=(char)Serial.read();
if (cmdIsSet) {
if ((inChar == '\n') || (inChar == '\r')) {
Log+=lstr+" : "+subCmd;
} else
subCmd+=inChar;
if (inChar == ':') {
Serial.print(" Received colon ");
Serial.println(lstr);
if (lstr.equalsIgnoreCase( "MtrSpeed:")) {
String spd=Serial.readStringUntil('\n');
respondSpeedReq(spd);
}
}
The snippet is stripped out of my original code, since this is the section I am trying to unit test. Other wise the combined code runs to few hundreds of lines.