Exit status 1 stray '\342' in program

Hello, I was messing around with the calc functions at the bottom of my code then I started getting this error. Help please, I cannot see what is wrong.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20, 20, 4);

byte OnOffSw = 4;
byte DirectionSw = 5;
long w; //angular acceleration
long T; //Torque
long P; //Power
int f; //frequency
int N; //mapped RPM
int valN; //rmp before mapping
int valT; // torque be4mapping

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.clear();
  pinMode(OnOffSw, INPUT);
  pinMode(DirectionSw, INPUT_PULLUP);
}​​

void loop() {
  calcSpeed();
  calcFrequency();
  calcTorque();
  calcPw();
  if (digitalRead(OnOffSw) == HIGH) {
    ​​
    lcd.setCursor(0, 0);
    lcd.print("Motor OFF");
    delay(400);
    lcd.clear();
  }​​
  if (digitalRead(OnOffSw) == LOW) {
    ​​
    lcd.clear();
    if (digitalRead(DirectionSw) == HIGH) {
      ​​
      lcd.setCursor(0, 0);
      lcd.print("Anti-Clockwise");
      lcd.setCursor(0, 1);
      lcd.print("Speed:");
      lcd.print(N);
      lcd.print("rpm");
      lcd.setCursor(0, 2);
      lcd.print("Frequency:");
      lcd.print(f);
      lcd.print("Hz");
      lcd.setCursor(0, 3);
      lcd.print("Pwr:");
      lcd.print(P);
      lcd.print("W");
      lcd.setCursor(10, 3);
      lcd.print("Tor:");
      lcd.print(T);
      lcd.print("Nm");
      delay(500);
      lcd.clear();
    }​​
    else if (digitalRead(DirectionSw) == LOW) {
      ​​
      lcd.setCursor(0, 0);
      lcd.print("Clockwise");
      lcd.setCursor(0, 1);
      lcd.print("Speed:");
      lcd.print(N);
      lcd.print("rpm");
      lcd.setCursor(0, 2);
      lcd.print("Frequency:");
      lcd.print(f);
      lcd.print("Hz");
      lcd.setCursor(0, 3);
      lcd.print("Pwr:");
      lcd.print(P);
      lcd.print("W");
      lcd.setCursor(10, 3);
      lcd.print("Tor:");
      lcd.print(T);
      lcd.print("Nm");
      delay(500);
      lcd.clear();
    }​​
  }​​
}

void calcSpeed() {
  // read from pin
  valN = analogRead(A0); //RPM
  N = map(valN, 0, 1023, 0, 15000);
}​​
void calcFrequency() {
  f = N / 180; // rms x number of poles (6)/2
}​​
void calcTorque() {
  valT = analogRead(A1);
  T = map(valT, 0, 1023, 0, 100);
}​​
void calcPw() {
  w = (2 * PI * N) / 60; //angular acceleration (2*pi*rpm)/60 to get per second
  P = T * w; //torque x angular acceleration
}

error message:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

lcdPower:22:2: error: stray '\342' in program

}​​

^

lcdPower:22:3: error: stray '\200' in program

}​​

^

lcdPower:22:4: error: stray '\213' in program

}​​

^

lcdPower:22:5: error: stray '\342' in program

}​​

 ^

lcdPower:22:6: error: stray '\200' in program

}​​

  ^

lcdPower:22:7: error: stray '\213' in program

}​​

   ^

lcdPower:30:5: error: stray '\342' in program

 ​​

 ^

lcdPower:30:6: error: stray '\200' in program

 ​​

  ^

lcdPower:30:7: error: stray '\213' in program

 ​​

   ^

lcdPower:30:8: error: stray '\342' in program

 ​​

    ^

lcdPower:30:9: error: stray '\200' in program

 ​​

     ^

lcdPower:30:10: error: stray '\213' in program

 ​​

      ^

lcdPower:35:4: error: stray '\342' in program

}​​

^

lcdPower:35:5: error: stray '\200' in program

}​​

 ^

lcdPower:35:6: error: stray '\213' in program

}​​

  ^

lcdPower:35:7: error: stray '\342' in program

}​​

   ^

lcdPower:35:8: error: stray '\200' in program

}​​

    ^

lcdPower:35:9: error: stray '\213' in program

}​​

     ^

lcdPower:37:5: error: stray '\342' in program

 ​​

 ^

lcdPower:37:6: error: stray '\200' in program

 ​​

  ^

lcdPower:37:7: error: stray '\213' in program

 ​​

   ^

lcdPower:37:8: error: stray '\342' in program

 ​​

    ^

lcdPower:37:9: error: stray '\200' in program

 ​​

     ^

lcdPower:37:10: error: stray '\213' in program

 ​​

      ^

lcdPower:40:7: error: stray '\342' in program

   ​​

   ^

lcdPower:40:8: error: stray '\200' in program

   ​​

    ^

lcdPower:40:9: error: stray '\213' in program

   ​​

     ^

lcdPower:40:10: error: stray '\342' in program

   ​​

      ^

lcdPower:40:11: error: stray '\200' in program

   ​​

       ^

lcdPower:40:12: error: stray '\213' in program

   ​​

        ^

lcdPower:61:6: error: stray '\342' in program

 }​​

  ^

lcdPower:61:7: error: stray '\200' in program

 }​​

   ^

lcdPower:61:8: error: stray '\213' in program

 }​​

    ^

lcdPower:61:9: error: stray '\342' in program

 }​​

     ^

lcdPower:61:10: error: stray '\200' in program

 }​​

      ^

lcdPower:61:11: error: stray '\213' in program

 }​​

       ^

lcdPower:63:7: error: stray '\342' in program

   ​​

   ^

lcdPower:63:8: error: stray '\200' in program

   ​​

    ^

lcdPower:63:9: error: stray '\213' in program

   ​​

     ^

lcdPower:63:10: error: stray '\342' in program

   ​​

      ^

lcdPower:63:11: error: stray '\200' in program

   ​​

       ^

lcdPower:63:12: error: stray '\213' in program

   ​​

        ^

lcdPower:84:6: error: stray '\342' in program

 }​​

  ^

lcdPower:84:7: error: stray '\200' in program

 }​​

   ^

lcdPower:84:8: error: stray '\213' in program

 }​​

    ^

lcdPower:84:9: error: stray '\342' in program

 }​​

     ^

lcdPower:84:10: error: stray '\200' in program

 }​​

      ^

lcdPower:84:11: error: stray '\213' in program

 }​​

       ^

lcdPower:85:4: error: stray '\342' in program

}​​

^

lcdPower:85:5: error: stray '\200' in program

}​​

 ^

lcdPower:85:6: error: stray '\213' in program

}​​

  ^

lcdPower:85:7: error: stray '\342' in program

}​​

   ^

lcdPower:85:8: error: stray '\200' in program

}​​

    ^

lcdPower:85:9: error: stray '\213' in program

}​​

     ^

lcdPower:92:2: error: stray '\342' in program

}​​

^

lcdPower:92:3: error: stray '\200' in program

}​​

^

lcdPower:92:4: error: stray '\213' in program

}​​

^

lcdPower:92:5: error: stray '\342' in program

}​​

 ^

lcdPower:92:6: error: stray '\200' in program

}​​

  ^

lcdPower:92:7: error: stray '\213' in program

}​​

   ^

lcdPower:95:2: error: stray '\342' in program

}​​

^

lcdPower:95:3: error: stray '\200' in program

}​​

^

lcdPower:95:4: error: stray '\213' in program

}​​

^

lcdPower:95:5: error: stray '\342' in program

}​​

 ^

lcdPower:95:6: error: stray '\200' in program

}​​

  ^

lcdPower:95:7: error: stray '\213' in program

}​​

   ^

lcdPower:99:2: error: stray '\342' in program

}​​

^

lcdPower:99:3: error: stray '\200' in program

}​​

^

lcdPower:99:4: error: stray '\213' in program

}​​

^

lcdPower:99:5: error: stray '\342' in program

}​​

 ^

lcdPower:99:6: error: stray '\200' in program

}​​

  ^

lcdPower:99:7: error: stray '\213' in program

}​​

   ^

exit status 1

stray '\342' in program

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

1 Like

You have an invisible character in the code

2 Likes

Did you copy some stuff in off a web page? I think that can bring invisible characters with it...

yes I did, that is definitely the problem then. Thank you :slight_smile:

Is there anyway to search for them automatically ?

Download and try this version

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20, 20, 4);

byte OnOffSw = 4;
byte DirectionSw = 5;
long w; //angular acceleration
long T; //Torque
long P; //Power
int f; //frequency
int N; //mapped RPM
int valN; //rmp before mapping
int valT; // torque be4mapping

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.clear();
  pinMode(OnOffSw, INPUT);
  pinMode(DirectionSw, INPUT_PULLUP);
}

void loop() {
  calcSpeed();
  calcFrequency();
  calcTorque();
  calcPw();
  if (digitalRead(OnOffSw) == HIGH) {
    
    lcd.setCursor(0, 0);
    lcd.print("Motor OFF");
    delay(400);
    lcd.clear();
  }
  if (digitalRead(OnOffSw) == LOW) {
    
    lcd.clear();
    if (digitalRead(DirectionSw) == HIGH) {
      
      lcd.setCursor(0, 0);
      lcd.print("Anti-Clockwise");
      lcd.setCursor(0, 1);
      lcd.print("Speed:");
      lcd.print(N);
      lcd.print("rpm");
      lcd.setCursor(0, 2);
      lcd.print("Frequency:");
      lcd.print(f);
      lcd.print("Hz");
      lcd.setCursor(0, 3);
      lcd.print("Pwr:");
      lcd.print(P);
      lcd.print("W");
      lcd.setCursor(10, 3);
      lcd.print("Tor:");
      lcd.print(T);
      lcd.print("Nm");
      delay(500);
      lcd.clear();
    }
    else if (digitalRead(DirectionSw) == LOW) {
      
      lcd.setCursor(0, 0);
      lcd.print("Clockwise");
      lcd.setCursor(0, 1);
      lcd.print("Speed:");
      lcd.print(N);
      lcd.print("rpm");
      lcd.setCursor(0, 2);
      lcd.print("Frequency:");
      lcd.print(f);
      lcd.print("Hz");
      lcd.setCursor(0, 3);
      lcd.print("Pwr:");
      lcd.print(P);
      lcd.print("W");
      lcd.setCursor(10, 3);
      lcd.print("Tor:");
      lcd.print(T);
      lcd.print("Nm");
      delay(500);
      lcd.clear();
    }
  }
}

void calcSpeed() {
  // read from pin
  valN = analogRead(A0); //RPM
  N = map(valN, 0, 1023, 0, 15000);
}
void calcFrequency() {
  f = N / 180; // rms x number of poles (6)/2
}
void calcTorque() {
  valT = analogRead(A1);
  T = map(valT, 0, 1023, 0, 100);
}
void calcPw() {
  w = (2 * PI * N) / 60; //angular acceleration (2*pi*rpm)/60 to get per second
  P = T * w; //torque x angular acceleration
}

The 12 extended characters in your sketch have been removed using Notepad++ but I don't have the libraries required to compile it

This is what you actually have
image

I do not know an easy solution. The above was made visible with Notepad++ setting the encoding to ANSI instead of UTF8.

The compiler complains about line 22, the actual error seems to be line; you will need to clean the lines out.

1 Like

May I ask how you did that?

Yes!! it works ! thank you very much

In Notepad++ I used the Regular expression search for [^\x00-\x7F]+ and replaced with an empty string.

I don't know if it works for all extended characters but has always worked when I needed it

I should point out at this point that I know nothing about Regular Expressions and found the technique on line a year or so ago, but I don't know where

I am sure that someone here can explain the nuances of how it works

2 Likes

The regex says: find one or more consecutive characters that are not in the range of \x00 to \x7F

[^\x00-\x7F]+
||         ||
||         |+- one or more
||         +-- end of range
|+------------ not
+------------- beginning of range

Thanks

Regex always looks useful but I don't know enough about it, or need it often enough to be familiar with it

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.