Sketch compiles to Mega1280 but not to Mega2560

Thanks!

Got it working. It was me who forgot to copy the OneWire lib when upgrading the IDE to 1.0.4

shame on me :blush:

Thank you for pointing out the obvious to me! :slight_smile:

I have read it somewhere, but i cant find it.
I would like to edit the dash link to point to the new updated arduino ide 1.0.4

Got it working. It was me who forgot to copy the OneWire lib when upgrading the IDE to 1.0.4

shame on me

Of course, if you downloaded libraries to the right place, that wouldn't have happened.

User-downloaded libraries do NOT go in the core library folder.

I had a very similar error and behavior. The same sketch could compile for Uno, but not Mega!

When i try to compile the sketch for Mega, i get the following error:

/home/kuruki/MyPrograms/arduino-1.0.5/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../avr/lib/avr6/crtm2560.o: In function __bad_interrupt': ../../../../crt1/gcrt1.S:193: relocation truncated to fit: R_AVR_13_PCREL against symbol __vector_25' defined in .text.__vector_25 section in core.a(HardwareSerial.cpp.o)

When changing the board to "Uno", there's no problem and the sketch works as it should... Any ideas?

#include <OneWire.h>
 
const int DS18S20_Pin = 7; //DS18S20 Signal pin on digital 7
const int DS18S20_Pin_2 = 6; //DS18S20 Signal pin on digital 6

//Temperature chip i/o
OneWire ds(DS18S20_Pin);  // on digital pin 7
OneWire ds2(DS18S20_Pin_2);  // on digital pin 6

 
void setup(void) {
  Serial.begin(9600);
}
 
void loop(void) {
  float temperature = getTemp(ds);
  Serial.print("A: ");
  Serial.println(temperature);
  temperature = getTemp(ds2);
  Serial.print("B: ");
  Serial.println(temperature);  
  delay(1000); //just here to slow down the output so it is easier to read
   
}
 
 float getTemp(OneWire sensor){
  //returns the temperature from one DS18S20 in DEG Celsius
 
  byte data[12];
  byte addr[8];
 
  if ( !sensor.search(addr)) {
      //no more sensors on chain, reset search
      sensor.reset_search();
      return -1000;
  }
 
  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return -1000;
  }
 
  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      return -1000;
  }
 
  sensor.reset();
  sensor.select(addr);
  sensor.write(0x44,1); // start conversion, with parasite power on at the end
 
  byte present = sensor.reset();
  sensor.select(addr);    
  sensor.write(0xBE); // Read Scratchpad
 
   
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = sensor.read();
  }
   
  sensor.reset_search();
   
  byte MSB = data[1];
  byte LSB = data[0];
 
  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
   
  return TemperatureSum;
   
}

It's just a sample code from the internet, for some waterproof sensors, modified a little bit. (Basically added the OneWire sensor argument into the float getTemp, in order to use one method for all of the different sensors)

Compiles for me with board set to Mega2560 and Mega1280. Did you modify any source code in your IDE?