For some weird reason, the following code doesn't compile. I get a "stray '\302' in program" error around volatile unsigned int encoderPos = 0;, and I have no idea what the issue is. I've been trying to figure this out for over 40min, and nothing works. It doesn't make any sense 😭

#include <U8g2lib.h>
#include <SPI.h>

//Pin definitions:

const int control_PWM = A3; //PWM output for the delay 

const int btn_1 = 1; //Button for mode 1
const int btn_2 = 4; //Button for mode 2
const int btn_3 = 5; //Button for mode 3

const int r_A = 2; //Rotary encoder A's data
const int r_B = 3; //Rotary encoder A's data
const int r_SW = 0; //Rotary encoder's button data

const int oled_CLK = 9; //SPI cloack
const int oled_MOSI = 8; //MOSI pin
const int oled_CS = 7; //Chip Select pin
const int oled_DC = 6; //OLED's D/C pin
U8G2_SH1106_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);

int mode = 1; //1: RGB, 2: HSL, 3: Distance control
int value_selection = 1; //Actual value selectrion
int value1 = 0; //red in mode 1; tint in mode 2
int value2 = 0; ////green in mode 1; saturation in mode 2
int value3 = 0; //blue in mode 1; luminosity in mode 2

volatile unsigned int encoderPos = 0;  // rotary encoder's current position
unsigned int lastReportedPos = 1;   // rotary encoder's previous position
static boolean rotating=false;      // is the encoder activity status

// interrupter variables
boolean A_set = false;              
boolean B_set = false;
boolean A_change = false;
boolean B_change= false;
void setup() {


void loop() {
  • What IDE version? – Majenko Oct 27 '16 at 13:48
  • Could you please edit your question to include the exact error message. – sa_leinad Oct 27 '16 at 14:10
  • @canadiancyborg: Your edit obscured the problem. – Ignacio Vazquez-Abrams Oct 27 '16 at 17:10
  • @IgnacioVazquez-Abrams I just translated the french comments to english, how did it change anything? – Dat Ha Oct 27 '16 at 17:25
  • @canadiancyborg: You removed the non-ASCII characters in the source, which were the cause of the error. – Ignacio Vazquez-Abrams Oct 27 '16 at 17:29

0302 is 0xc2. Somewhere in your source you have one or more non-breaking spaces (0xa0) encoded in UTF-8 (0xc2 0xa0). Use od or a similar tool to find them, and then replace them with normal spaces. Since you have non-ASCII Latin-1 characters in your source, those characters are encoded as two bytes with the first being 0xc2 or 0xc3. Remove all non-ASCII characters before proceeding.

  • You can probably just copy the code from your post and past it over the original code in the IDE. As I can't detect any weird characters in the text above (I think browser replace NBSPs with regular spaces). Invisible characters can be quite a pain for some compilers. – Gerben Oct 27 '16 at 16:12

One cause of the /(302) error is copy and paste code from a word processor. You have ASCII codes copied that add spaces, etc to your code. Go through each identified line and remove any extra spaces at the beginning and end of any identified line. Then, (Arduino IDE) go to TOOLS, Auto Format. At least, this cleared up the problem for me.

protected by Community Jan 7 '18 at 7:47

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.