Issues communicating with Arduino Nano Every vs Mega

Hello All,

I am trying to interface a Nano Every board via serial communication with the same sketch that I used and works with Mega, but it doesnt receive any commands for some reason.

Here is my sketch, I stripped out a lot just to see if it works at all with minimal sketch (no issues with Mega)

// Define User Types below here or use a .h file
#include <LiquidCrystal.h>

#define TogglePin 14
String inputString = "";      // String to hold incoming serial data
String inputCommand = "";
String outputPrint = "";
byte inCharCount = 0;
bool stringComplete = false;  // whether the incoming serial1 string is complete
byte ToggleByte = 0x00;

//  LiquidCrystal(rs, en, d4, d5, d6, d7).
LiquidCrystal lcd(8,9,4,5,6,7); 

// The setup() function runs once each time the micro-controller starts
void setup()
{

  pinMode(TogglePin, OUTPUT);
  digitalWrite(TogglePin, LOW);
  // Initiate serial communication
  Serial.begin(9600);
  //For debugging only
  lcd.begin(16, 2);
  lcd.print("Ready to connect");
}

// Add the main program code into the continuous loop() function
void loop()
{
  if(stringComplete)
  {
    stringComplete = false;
    
    if (inputCommand.equals("TOGL")) {
      if ((ToggleByte >> (1 - 1)) & 1) 
      {
        digitalWrite(TogglePin, HIGH);
        lcd.clear();
        lcd.setCursor(0,0);      
        lcd.print("TOGL#1#On"); 
      }
      else
      {
        digitalWrite(TogglePin, LOW);        
        lcd.clear();
        lcd.setCursor(0,0);      
        lcd.print("TOGL#1#Off"); 
      }
      
    }
    
    //Serial.print(outputPrint);  
    inputString = "";
    
    outputPrint = "";  
  }
}

void serialEvent() {
  while (Serial.available() > 0) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == ';')
    {
      switch(inCharCount)
      {
        case 0:
          inputCommand = inputString;
        break;
        case 1:
          if (inputCommand.equals("TOGL"))
            ToggleByte = inputString.toInt();
        break;        
      }  
      inputString = "";
      ++inCharCount;    
    }
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
   else if (inChar == '\n') {
      stringComplete = true;
      inCharCount = 0;
    } 
    else {
      inputString += (char)inChar;
    }
  }
}

The command strings from my C# program are in the format of "Command;value;\n" which has always been that way for my Mega projects as well. Tried using the suggestion from another post by adding delay(1) after Serial.read() with no success. Probably I am doing something silly mistake, but I thought the sketches should work fine interchangeably among arduino boards making sure the pins are in right order for a given board.

I see 'Ready to connect' message on my LCD display and nothing else. If I keep sending commands from my C# program, eventually it hangs and the Every doesnt even work with Arduino IDE until I unplug and replug it.

Anyone with input on this please? I was held up at this stage for a while now.

Hi Kris -

Are you testing from a Windows PC? I am having a similar problem with and Arduino Nano and a Nano Every. I have found that after I open and close the IDE serial monitor - then my PC program communicates correctly, but if I just connect the Arduino the PC program behaves as yours does - it sends - but Serial.available() always returns 0.

I setup a stupid simple "echo test" - even simpler than your code and it exhibits the same behavior. Interesting - if I run putty on the PC it works fine - everything gets echoed back. But the C programs that I am testing with all report a communication error - unless I have already opened and closed the serial debugger window - or run putty and jump-started communication. It seems to be something odd with the way Windows handles the USB port 0 - strange that running and exiting one program can cause the next program to behave differently.

Very curious to know what you have learned.

Dean

/*
  Serial echo 
*/

void setup() {
  Serial.begin(38400);
  Serial.flush();
}

void loop() {
  byte b;
  if (Serial.available()) {      // If anything comes in Serial (USB),
     b = Serial.read();
     Serial.write(b);
     }
}