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.