Compiles on UNO, not on 101?

Hi everyone,

I’ve just ordered an Arduino 101 and installed the intel boards on the Arduino ide.

Out of curiosity i went to compile a sketch i’ve written that works fine on the UNO and the mega 2560 but returns an error when compiling for the 101.

‘int y1’ redeclared as different kind of symbol

Any ideas?

Thanks

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define input A0

const byte  numPins = 4;
const byte numReadings = 5;

int readings[numPins][numReadings];
int total[numPins];
int average[numPins];
int nullZone[2] = {484, 532};

int x1;
int y1;
int x2;
int y2;

int stickVal;

void setup() {

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

  display.display();
  delay(500);
  display.clearDisplay();
  display.display();

  for (byte i = 0; i < numPins; i ++) {
    pinMode(input + i, INPUT);
  }
  Serial.begin(9600);
}

void loop() {

  for (byte i = 0; i < numPins; i ++) {

    read_Thumb_Sticks(i);
  }
  writeDisplay();
}

void writeDisplay() {

  display.clearDisplay();

  display.drawCircle(display.width() / 4, display.height() / 2, 31, WHITE);
  display.drawCircle(display.width() - display.width() / 4, display.height() / 2, 31, WHITE);

  if (average[0] > nullZone[0] && average[0] < nullZone[1]) {
    x1 = 31;
  } else {
    x1 = map(average[0], 140, 914, 2, 63);
  }
  
  if (average[2] > nullZone[0] && average[2] < nullZone[1]) {
    y1 = 31;
  } else {
    y1 = map(average[2], 140, 914, 62, 2);
  }
  
  if (average[1] > nullZone[0] && average[1] < nullZone[1]) {
    x2 = 96;
  } else {
    x2 = map(average[1], 914, 140, 66, 126);
  }

  if (average[3] > nullZone[0] && average[3] < nullZone[1]) {
    y2 = 31;
  } else {
    y2 = map(average[3], 140, 914, 2, 62);
  }
  
  display.drawLine(x1-2, y1, x1+2, y1, WHITE);
  display.drawLine(x1, y1-2, x1, y1+2, WHITE);
  display.drawLine(x2-2, y2, x2+2, y2, WHITE);
  display.drawLine(x2, y2-2, x2, y2+2, WHITE);

  display.drawLine(31, 31, x1, y1, WHITE);
  display.drawLine(96, 31, x2, y2, WHITE);

  display.display();
}

void read_Thumb_Sticks(byte i) {

  for (byte j = 0; j < numReadings; j ++) {

    total[i] = total[i] - readings[i][j];
    readings[i][j] = analogRead(input + i);
    total[i] = total[i] + readings[i][j];
  }

  average[i] = total[i] / numReadings;
  
  return average[i];
}

Got the full text of any and all errors? Often with errors about redefinition, if you look closely it will tell you where it was first defined, gives you some information about what's going on.

Somehow y1 seems to be declared aa a double during compile instead of an int. Is this due to being mapped?

error: previous declaration of ‘double y1(double)’ extern double y1 _PARAMS((double));

Build options changed, rebuilding all
PS3_thumb_sticks:18: error: ‘int y1’ redeclared as different kind of symbol
 int y1;
     ^
In file included from /Users/Spleen/Library/Arduino15/packages/Intel/hardware/arc32/2.0.2/cores/arduino/Arduino.h:27:0,
                 from sketch/PS3_thumb_sticks.ino.cpp:1:
/Users/Spleen/Library/Arduino15/packages/Intel/tools/arc-elf32/1.6.9+1.0.1/arc-elf32/sys-include/math.h:481:15: error: previous declaration of ‘double y1(double)’
 extern double y1 _PARAMS((double));
               ^
/var/folders/0l/3yg4jh1901j5xd527cgpzj7c0000gn/T/arduino_modified_sketch_64317/PS3_thumb_sticks.ino: In function ‘void writeDisplay()’:
PS3_thumb_sticks:62: error: assignment of function ‘double y1(double)’
     y1 = 31;
        ^
PS3_thumb_sticks:62: error: cannot convert ‘int’ to ‘double(double)’ in assignment
PS3_thumb_sticks:64: error: assignment of function ‘double y1(double)’
     y1 = map(average[2], 140, 914, 62, 2);
        ^
PS3_thumb_sticks:64: error: cannot convert ‘long int’ to ‘double(double)’ in assignment
PS3_thumb_sticks:79: error: invalid conversion from ‘double (*)(double)’ to ‘int16_t {aka short int}’ [-fpermissive]
   display.drawLine(x1-2, y1, x1+2, y1, WHITE);
                                             ^
In file included from /Users/Spleen/Documents/Arduino/libraries/Adafruit_SSD1306/Adafruit_SSD1306.h:49:0,
                 from /var/folders/0l/3yg4jh1901j5xd527cgpzj7c0000gn/T/arduino_modified_sketch_64317/PS3_thumb_sticks.ino:2:
/Users/Spleen/Documents/Arduino/libraries/Adafruit_GFX/Adafruit_GFX.h:25:5: error:   initializing argument 2 of ‘virtual void Adafruit_GFX::drawLine(int16_t, int16_t, int16_t, int16_t, uint16_t)’ [-fpermissive]
     drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
     ^
PS3_thumb_sticks:79: error: invalid conversion from ‘double (*)(double)’ to ‘int16_t {aka short int}’ [-fpermissive]
   display.drawLine(x1-2, y1, x1+2, y1, WHITE);
                                             ^
In file included from /Users/Spleen/Documents/Arduino/libraries/Adafruit_SSD1306/Adafruit_SSD1306.h:49:0,
                 from /var/folders/0l/3yg4jh1901j5xd527cgpzj7c0000gn/T/arduino_modified_sketch_64317/PS3_thumb_sticks.ino:2:
/Users/Spleen/Documents/Arduino/libraries/Adafruit_GFX/Adafruit_GFX.h:25:5: error:   initializing argument 4 of ‘virtual void Adafruit_GFX::drawLine(int16_t, int16_t, int16_t, int16_t, uint16_t)’ [-fpermissive]
     drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
     ^
/var/folders/0l/3yg4jh1901j5xd527cgpzj7c0000gn/T/arduino_modified_sketch_64317/PS3_thumb_sticks.ino:80:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   display.drawLine(x1, y1-2, x1, y1+2, WHITE);
                           ^
/var/folders/0l/3yg4jh1901j5xd527cgpzj7c0000gn/T/arduino_modified_sketch_64317/PS3_thumb_sticks.ino:80:37: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   display.drawLine(x1, y1-2, x1, y1+2, WHITE);
                                     ^
PS3_thumb_sticks:80: error: invalid conversion from ‘double (*)(double)’ to ‘int16_t {aka short int}’ [-fpermissive]
   display.drawLine(x1, y1-2, x1, y1+2, WHITE);
                          ^
In file included from /Users/Spleen/Documents/Arduino/libraries/Adafruit_SSD1306/Adafruit_SSD1306.h:49:0,
                 from /var/folders/0l/3yg4jh1901j5xd527cgpzj7c0000gn/T/arduino_modified_sketch_64317/PS3_thumb_sticks.ino:2:
/Users/Spleen/Documents/Arduino/libraries/Adafruit_GFX/Adafruit_GFX.h:25:5: error:   initializing argument 2 of ‘virtual void Adafruit_GFX::drawLine(int16_t, int16_t, int16_t, int16_t, uint16_t)’ [-fpermissive]
     drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
     ^
PS3_thumb_sticks:80: error: invalid conversion from ‘double (*)(double)’ to ‘int16_t {aka short int}’ [-fpermissive]
   display.drawLine(x1, y1-2, x1, y1+2, WHITE);
                                    ^
In file included from /Users/Spleen/Documents/Arduino/libraries/Adafruit_SSD1306/Adafruit_SSD1306.h:49:0,
                 from /var/folders/0l/3yg4jh1901j5xd527cgpzj7c0000gn/T/arduino_modified_sketch_64317/PS3_thumb_sticks.ino:2:
/Users/Spleen/Documents/Arduino/libraries/Adafruit_GFX/Adafruit_GFX.h:25:5: error:   initializing argument 4 of ‘virtual void Adafruit_GFX::drawLine(int16_t, int16_t, int16_t, int16_t, uint16_t)’ [-fpermissive]
     drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
     ^
PS3_thumb_sticks:84: error: invalid conversion from ‘double (*)(double)’ to ‘int16_t {aka short int}’ [-fpermissive]
   display.drawLine(31, 31, x1, y1, WHITE);
                                         ^
In file included from /Users/Spleen/Documents/Arduino/libraries/Adafruit_SSD1306/Adafruit_SSD1306.h:49:0,
                 from /var/folders/0l/3yg4jh1901j5xd527cgpzj7c0000gn/T/arduino_modified_sketch_64317/PS3_thumb_sticks.ino:2:
/Users/Spleen/Documents/Arduino/libraries/Adafruit_GFX/Adafruit_GFX.h:25:5: error:   initializing argument 4 of ‘virtual void Adafruit_GFX::drawLine(int16_t, int16_t, int16_t, int16_t, uint16_t)’ [-fpermissive]
     drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
     ^
/var/folders/0l/3yg4jh1901j5xd527cgpzj7c0000gn/T/arduino_modified_sketch_64317/PS3_thumb_sticks.ino: In function ‘void read_Thumb_Sticks(byte)’:
PS3_thumb_sticks:101: error: return-statement with a value, in function returning 'void' [-fpermissive]
   return average[i];
                   ^
exit status 1
‘int y1’ redeclared as different kind of symbol

Work around it; rename your 'y1' to something else that properly reflects what it is; in the worst case, it can be 'yOne'.

That variable name is already used by the Arduino 101 libraries.

It is not available for use in your sketch. Use a different name for that variable.

Thanks for your help. That was the problem. Makes sense that a board with an accelerometer and gyroscope built in would already have variables with x's and y's.

They are all now upper case X's and Y's.

Cheers

spleen: They are all now upper case X's and Y's.

Sorry to say, but it's a silly solution and eventually will bite you one day. One typing mistake (lowercase instead of uppercase) and you will have code that compiles and big problems finding the problem why something does not work.

Apparently y0() and y1() are standard functions for computing Bessel Functions, whatever those are.
IMO, whoever chose to put names like that in a common library like math.h probably ought to be tortured… :frowning:

NAME
j0, j1, jn, y0, y1, yn – bessel functions of first and second kind

SYNOPSIS
#include <math.h>

double j0(double x);
double j1(double x);
double jn(int n, double x);
double y0(double x);
double y1(double x);
double yn(int n, double x);

DESCRIPTION
The functions j0(x) and j1(x) compute the Bessel function of the first kind of the
order 0 and the order 1, respectively; the function jn(n, x) computes the Bessel func-
tion of the first kind of the integer order n.

The functions y0(x) and y1(x) compute the linearly independent Bessel function of the
second kind of the order 0 and the order 1, respectively, for the positive integer
value x (expressed as a double); the function yn(n, x) computes the Bessel function of
the second kind for the integer order n for the positive integer value x (expressed as
a double).