Help needed with error messages

Hi all.

I copied and pasted the sketch below into the Arduino IDE, when i try to upload the sketch i get the errors below, i am using a UNO R3, with a UVM30A UV index sensor + NOKIA 5110 LCD.

#include <LCD5110_Graph.h>

LCD5110 lcd(8,9,10,12,11);
extern unsigned char BigNumbers[];
extern uint8_t splash[];
extern uint8_t ui[];

String UV = "0"; 

void setup() {
 
 lcd.InitLCD();
 lcd.setFont(BigNumbers);
 lcd.clrScr();
 lcd.drawBitmap(0, 0, splash, 84, 48);
 lcd.update();  
 delay(3000);
 
}

void loop() {
 
 int stringLength = 0; 
  
 UV = readSensor();
 lcd.clrScr();
 lcd.drawBitmap(0, 0, ui, 84, 48);
 
 stringLength = UV.length();
 printUV(stringLength);
 lcd.update();
 delay(150);
}

void printUV(int length)
{
  switch(length)
  {
    case 1:  lcd.print(UV,38,19); break;
    case 2:  lcd.print(UV,24,19); break;
    default:  lcd.print(UV,0,19); break;
  }
}

String readSensor()
{
  String UVIndex = "0";
  int sensorValue = 0;
  
  sensorValue = analogRead(0);                        //connect UV sensor to Analog 0   
  int voltage = (sensorValue * (5.0 / 1023.0))*1000;  //Voltage in miliVolts
  
  if(voltage<50)
  {
    UVIndex = "0";
  }else if (voltage>50 && voltage<=227)
  {
    UVIndex = "0";
  }else if (voltage>227 && voltage<=318)
  {
    UVIndex = "1";
  }
  else if (voltage>318 && voltage<=408)
  {
    UVIndex = "2";
  }else if (voltage>408 && voltage<=503)
  {
    UVIndex = "3";
  }
  else if (voltage>503 && voltage<=606)
  {
    UVIndex = "4";
  }else if (voltage>606 && voltage<=696)
  {
    UVIndex = "5";
  }else if (voltage>696 && voltage<=795)
  {
    UVIndex = "6";
  }else if (voltage>795 && voltage<=881)
  {
    UVIndex = "7";
  }
  else if (voltage>881 && voltage<=976)
  {
    UVIndex = "8";
  }
  else if (voltage>976 && voltage<=1079)
  {
    UVIndex = "9";
  }
  else if (voltage>1079 && voltage<=1170)
  {
    UVIndex = "10";
  }else if (voltage>1170)
  {
    UVIndex = "11";
  }
  return UVIndex;
}

[codeArduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\dell\AppData\Local\Temp\ccidaCy7.ltrans0.ltrans.o: In function `setup':

C:\Users\dell\Downloads\FBU7AFWISCBNOLH/FBU7AFWISCBNOLH.ino:21: undefined reference to `splash'

C:\Users\dell\Downloads\FBU7AFWISCBNOLH/FBU7AFWISCBNOLH.ino:21: undefined reference to `splash'

C:\Users\dell\AppData\Local\Temp\ccidaCy7.ltrans0.ltrans.o: In function `loop':

C:\Users\dell\Downloads\FBU7AFWISCBNOLH/FBU7AFWISCBNOLH.ino:33: undefined reference to `ui'

C:\Users\dell\Downloads\FBU7AFWISCBNOLH/FBU7AFWISCBNOLH.ino:33: undefined reference to `ui'

collect2.exe: error: ld returned 1 exit status

.[/code]

1 Like

Where did you copy it from?

extern uint8_t splash[];
extern uint8_t ui[];

Looks like you're missing some files

You seem to have some confusion with what the keyword word extern means. Part of the problem is that programmers are a little sloppy using the terms "define" and "declare". When you define a variable, you create an attribute list for that variable: name, data type, scope, etc. More importantly, the compiler allocates space for the variable where it resides in memory (i.e., an lvalue). When you declare a variable, you construct the attribute list, but do NOT allocate memory for it. In essence, your lines:

extern uint8_t splash[];
extern uint8_t ui[];

is saying to the compiler: "These two arrays are defined (i.e., memory allocated for them) somewhere else, but let me use them in this file as an unsigned byte array." NOTE: there is no size given for the arrays. Indeed, you would get an error message if you put one in for a single-dimensioned array. The reason is because this is a data declaration, not a definition. Your error messages are saying that the linker can't find where you actually define these two arrays (i.e., no extern keyword and the element count supplied). The definitions will need to supply the element count for the arrays. So, something is missing from your code that defines the two arrays.

Thank You all.

Problem was missing files.

Regards

Ray

How did you resolve it? I've the same problem

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