LiquidCrystal_I2C compile issue with Nano

I have the Windows version of Arduino 1.8.33.

The sketch drives a stepper motor with an A4988 driver. Momentary buttons activate the Stepper motor either CW or CCW respectively and when in the CW direction a valve is also operated. A 16x2 LCD with I2C backpack is to record Stepper Speed (calculated as ml/sec). Speed is modified with the use of a potentiometer.

After correcting the sketch for minor issues the error code is:

Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino Nano, ATmega328P"
exit status 1
Error compiling for board Arduino Nano.

I have:

Shutdown and restarted the computer.
I have uninstalled and reinstalled the Arduino IDE.
I have deleted all LiquidCrystal-I2C libraries and reinstalled a single version.
I have tried all that i am capable off and no change.

The sketch will compile when i delete all activities associated with the LCD.

I see on the internet that this problem has existed before, but i cannot find a solution. Anyone out there with a suggestion. I include the code.

#include <Stepper.h>
#include<Wire.h>
#include <LiquidCrystal_I2C.h>

#define LCD_COLS 16
#define LCD_ROWS 2
const int I2CAddr = 0x26;

LiquidCrystal_I2C lcd(I2CAddr, LCD_COLS, LCD_ROWS); // set the LCD address to 0x26 for a 16 chars and 2 line display


//Pins
//Buttons
const int CW = 8;
const int CCW = 9;
//Flush Stepper Motor
const int stp = 3;
const int dir = 2;
const int En = 4;
int stepdelay;
//Pinch Valve
const int Valve = 5;
//Pot
const int Pot = A0;
int val1;
int val2;



void setup() {

  //Buttons
  pinMode(CW, INPUT_PULLUP);
  pinMode(CCW, INPUT_PULLUP);
  //Stepper Motor via A4988
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
  pinMode(En, OUTPUT);
  digitalWrite(En, HIGH);
  digitalWrite(dir, LOW);
  //Solenoid Valve
  pinMode(Valve, OUTPUT);
  digitalWrite(Valve, LOW);

  lcd.init();                  // initialize the lcd
  lcd.setCursor(0, 1);// Print a message to the LCD.
  lcd.print("CW  ml/sec");

  
}

void loop()
{
  int val1 = analogRead(Pot);
  val1 = map(val1, 0, 1023, 0, 20);
  lcd.setCursor(1, 7);
  lcd.print(val1);

  if (digitalRead(CW) == LOW) {
    digitalWrite(En, LOW);
    digitalWrite(dir, HIGH);
    digitalWrite(Valve, HIGH);
    val2 = map (val1, 0, 20, 1, 4000);
    stepdelay = val2;
    digitalWrite(stp, HIGH);
    delayMicroseconds(stepdelay);
    digitalWrite(stp, LOW);
    delayMicroseconds(stepdelay);
  }
  else if (digitalRead(CCW) == LOW) {
    digitalWrite(En, LOW);
    digitalWrite(dir, LOW);
    int val2 = map(val1, 0, 20, 1, 4000);
    stepdelay = val2;
    digitalWrite(stp, HIGH);
    delayMicroseconds(stepdelay);
    digitalWrite(stp, LOW);
    delayMicroseconds(stepdelay);
  }
  else {
    digitalWrite(En, HIGH);
    digitalWrite(dir, LOW);
    digitalWrite(Valve, LOW);
  }
}

Better to post everything the compiler told you. That final error message is just "Something went wrong". If you scroll up, you'll see that it doesn't like your variable En - it's apparently defined as a macro in one of your libraries. Call it something else.

Note though that you will need to change everywhere you use En to use the new variable. If you just rename the variable, it will compile, but it will very likely not function correctly.

Dear wildbill,

You are correct on both fronts. It loads now, but doesn't function.

Any suggestions?

Cheers
Hrvat

but doesn't function.

What does that mean? There is no information in that statement that will help us to help you.

Does the motor work?

Does the LCD work? If not, may I suggest that you try the hd44780 library?

Have you tried the contrast adjustment?

For an I2C LCD display to work, the I2C address and the I2C backpack to LCD pin mapping must be correct. If the library default settings for either or both are not correct the LCD will not work. You can try to figure out the right pin mapping and use an I2C scanner to find the address, but if you install and use the hd44780 library that is done automatically by the library.

Install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE menus, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.

The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping.

In the examples, there is a diagnostic sketch that will help us to help you if you still have trouble with the display. Run the diagnostic sketch and post the results.

The version of LiquidCrystal_I2C you are using isn't compiatable with the nano. You better find other versions of it on GitHub.

ArnavPawarAA:
The version of LiquidCrystal_I2C you are using isn't compiatable with the nano.

There's no evidence presented to suggest that, but even if it's true, the best solution available has already been presented "Install the hd44780 library" rather than a pretty meaningless " find other versions of it on GitHub".

Wild bill and Friends,

I managed to get the program to function as i wrote it albeit it with a couple of minor changes. Stupidly i had the pin out numbers incorrect. I am aware of the brightness and I2C address requirements and thank you for your suggestions. I will try the HD44780 library in future.

Kind Regards
Hrvat