Compilation error with Arduino mega board

Hello,
I'm using ADS1115 with Arduino Mega 250 board everything was going good till yesterday. From morning i'm getting this error when i am trying to compile. can anyone please help me in this ? i'm not getting proper solution for below error.

'''
c:\users\abc\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\util\delay.h: In function 'Adafruit_ADS1115::readADC_SingleEnded(unsigned char) [clone .part.1] [clone .constprop]':
c:\users\abc\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\util\delay.h:276:28: error: __builtin_avr_delay_cycles expects a compile time integer constant
__builtin_avr_delay_cycles(__ticks_dc);
^
lto-wrapper.exe: fatal error: C:\Users\abc\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc returned 1 exit status
compilation terminated.
c:/users/abc/appdata/local/arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed
collect2.exe: error: ld returned 1 exit status
Using library Adafruit_ADS1115-master in folder: C:\Users\abc\Documents\Arduino\libraries\Adafruit_ADS1115-master (legacy)
Using library Wire at version 1.0 in folder: C:\Users\abc\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire
Using library Arduino-LiquidCrystal-I2C-library-master in folder: C:\Users\abc\Documents\Arduino\libraries\Arduino-LiquidCrystal-I2C-library-master (legacy)
Using library MCP_DAC at version 0.1.8 in folder: C:\Users\abc\Documents\Arduino\libraries\MCP_DAC
Using library SPI at version 1.0 in folder: C:\Users\abc\AppData\Local\ArduiPreformatted textno15\packages\arduino\hardware\avr\1.8.6\libraries\SPI
exit status 1
Error compiling for board Arduino Mega or Mega 2560.
'''

Post the code using code tags and links to the library you chose

im not an expert here but have you tried:

  • restarting your application
    *checking errors in your code
    *making sure you have proper connection with your monitor and boards

its also better if you upload your sketch to help the experts diagnose the problem

The issue is at compilation stage, so it’s a code error.

This is my sketch please let me know if i have done any mistake in my sketch.
I am using ADS1115 , TWO DAC MCP4921 .

#include <MCP_DAC.h>
#include <Wire.h>
#include <Adafruit_ADS1115.h>
#include <LiquidCrystal_I2C.h>
MCP4921 myDAC;
MCP4921 myDAC_2;

LiquidCrystal_I2C lcd(0x27, 16, 2);
Adafruit_ADS1115 ads(0x48);
float Voltage1 = 0.0;
float Voltage2 = 0.0;
float Voltage3 = 0.0;
int sw2 = 18,totalColumns = 16,totalRows = 2;
float dac1,dac2;

String scrollingMessage = "ASG CONTROL UNIT SYSTEM ....! ";
String scrollingMessage1 = "16 BIT MODE OPERATION ";
void scrollMessage(int row, String message, int delayTime, int totalColumns)
{
  for (int i = 0; i < totalColumns; i++) {
    message = " " + message;
  }
  message = message + " ";
  for (int position = 0; position < message.length(); position++) {
    lcd.setCursor(1, 0);
    lcd.print(message.substring(position, position + totalColumns));
    delay(100);
    lcd.clear();
  }
}
void setup()
{
  Serial.begin(9600);
  lcd.begin();
  ads.begin();
  myDAC.begin(53);
  myDAC_2.begin(40);
  lcd.backlight();
  lcd.clear();
  pinMode(sw2, INPUT);
  lcd.setCursor(0, 0);
  scrollMessage(1, scrollingMessage, 250, totalColumns);
  scrollMessage(1, scrollingMessage1, 250, totalColumns);
  lcd.clear();
}

void loop(void)
{

  int16_t adc1; // POTENTIAL input A0
  adc1 = ads.readADC_SingleEnded(0);
  Voltage1 = (adc1 * 0.1875) / 1000;

  int16_t adc2; // SHAFT VOLTAGE input A1
  adc2 = ads.readADC_SingleEnded(1);
  Voltage2 = (adc2 * 0.1875) / 1000;
  
  int16_t adc3; // HULL VOLTAGE input A2
  adc3 = ads.readADC_SingleEnded(2);
  Voltage3 = (adc3 * 0.1875) / 1000;
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(Voltage1, 5);
  lcd.print(" V");
  lcd.setCursor(0, 6);
  lcd.print(Voltage2, 5);
  lcd.print(" V");

  delay(1000);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(Voltage3, 5);
  lcd.print(" V");

  delay(1000);
  myDAC.analogWrite(adc1);
  myDAC_2.analogWrite(adc2);
  
}

@stryxter Hello , yes i have tried all of above points that you have mentioned. i have attched my sketch kindly refer that might help us to resolve issue.

Looks like there are issues with the Adafruit_ADS1115.h library you are using.

Is this an offical Adafruit library ?

In particular the call to _delay_us does not pass the correct parameter.

As a workaround, you could manually edit Adafruit_ADS1125.cpp (in the libraries folder) and change this line...

  	        _delay_us(m_conversionDelay);

to this...

         for (uint32_t x = 0; x < m_conversionDelay; x++)
  	        _delay_us(1);

But to be honest you are probably better to find a better library.

@red_car Hello Sir , I tried to compile by changing cpp file as you told but still giving same error .

Post the error messages from the compiler.

Also show details of the code you changed.

As you told i had done same changes in ADS1115.cpp and tried to compile code but still same errors i got .please find attachment with this post.
I got below errors while compile.

change in cpp

"C:\\Users\\abc\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega2560 -o "C:\\Users\\abc\\AppData\\Local\\Temp\\arduino_build_76972/sketch_jan07a.ino.elf" "C:\\Users\\abc\\AppData\\Local\\Temp\\arduino_build_76972\\sketch\\sketch_jan07a.ino.cpp.o" "C:\\Users\\abc\\AppData\\Local\\Temp\\arduino_build_76972\\libraries\\Adafruit_ADS1115-master\\Adafruit_ADS1115.cpp.o" "C:\\Users\\abc\\AppData\\Local\\Temp\\arduino_build_76972\\libraries\\Wire\\Wire.cpp.o" "C:\\Users\\abc\\AppData\\Local\\Temp\\arduino_build_76972\\libraries\\Wire\\utility\\twi.c.o" "C:\\Users\\abc\\AppData\\Local\\Temp\\arduino_build_76972\\libraries\\MCP_DAC\\MCP_DAC.cpp.o" "C:\\Users\\abc\\AppData\\Local\\Temp\\arduino_build_76972\\libraries\\SPI\\SPI.cpp.o" "C:\\Users\\abc\\AppData\\Local\\Temp\\arduino_build_76972\\libraries\\Arduino-LiquidCrystal-I2C-library-master\\LiquidCrystal_I2C.cpp.o" "C:\\Users\\abc\\AppData\\Local\\Temp\\arduino_build_76972/core\\core.a" "-LC:\\Users\\abc\\AppData\\Local\\Temp\\arduino_build_76972" -lm
c:\users\abc\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\util\delay.h: In function 'Adafruit_ADS1115::readADC_SingleEnded(unsigned char) [clone .part.1] [clone .constprop]':
c:\users\abc\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\util\delay.h:276:28: error: __builtin_avr_delay_cycles expects a compile time integer constant
  __builtin_avr_delay_cycles(__ticks_dc);
                            ^
lto-wrapper.exe: fatal error: C:\Users\abc\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc returned 1 exit status
compilation terminated.
c:/users/abc/appdata/local/arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed
collect2.exe: error: ld returned 1 exit status
Using library Adafruit_ADS1115-master in folder: C:\Users\abc\Documents\Arduino\libraries\Adafruit_ADS1115-master (legacy)
Using library Wire at version 1.0 in folder: C:\Users\abc\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\Wire 
Using library MCP_DAC at version 0.1.8 in folder: C:\Users\abc\Documents\Arduino\libraries\MCP_DAC 
Using library SPI at version 1.0 in folder: C:\Users\abc\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\SPI 
Using library Arduino-LiquidCrystal-I2C-library-master in folder: C:\Users\abc\Documents\Arduino\libraries\Arduino-LiquidCrystal-I2C-library-master (legacy)
exit status 1
Error compiling for board Arduino Mega or Mega 2560.

please, please never ever again post pictures of text... Not only they are not readable nor usable directly for copy&paste but they use up lots of storage and internet bandwidth which contributes to polluting the planet.

➜ do your part and do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

@red_car Hello sir , thank you so much it works . :+1:
actually in ads1115.cpp i had forget to change in one place . now its compile and run Successfully.

Instead of
_delay_us(m_conversionDelay);

I Just replace all the above lines in ADS1115.cpp file by

for (uint32_t x = 0; x < m_conversionDelay; x++)
  	        _delay_us(1);

It works Thank you So Much @red_car .

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