Difference in code between two arduinos

I would like to know what is the difference in code between Arduino pro mini and Arduino mega 1280? If i have a code written for Arduino pro mini how to change it to work on the Arduino mega 1280..

Thank you for the help!

Your question is impossible to answer. Does your code use something specific to the '168 processor? Does your code assume the EEPROM is a certain size? Does your code rely on precise timing that may change slightly on the '1280 processor?

If you want an answer, you’re going to have to provide more detail. If you post your Sketch (which is the best way to get an answer), please use code tags.

I can post you the link to the code if that would be ok?

Basically if you are using Standard Arduino statements and libraries your code should work for either one as the IDE board selection tells the compiler which processor type to use when compiling and building the code. This should hold true for going from the pro-mini to the mega. The other way around depends on what pin numbers you are using, size of the sketch, what special extra hardware features you are using or not etc.

Lefty

So if I understand correctly everything would work without any modification to the code? The code is from one member from another forum but he doesnt have experience with the mega so he cant modify it. I hope its fine if i post the link to the sketch…

Here is the link to the code: http://radio-commande.com/wp-content/uploads/2010/09/MultiWii1_3.zip

Link to the project: http://radio-commande.com/international/triwiicopter-design/

The code is riddled with direct hardware manipulation…

void i2c_init(void) {
  [glow]PORTC[/glow] |= 1<<4; // activate internal pull-ups PIN A4 for twi
  [glow]PORTC[/glow] |= 1<<5; // activate internal pull-ups PIN A5 for twi
  TWSR = 0;        // no prescaler => prescaler = 1
  TWBR = ((16000000L / I2C_SPEED) - 16) / 2; // change the I2C clock rate
  TWCR = 1<<TWEN;  // enable twi module, no interrupt
}

ISR(TIMER0_COMPA_vect) {
  static uint8_t state = 0;
  static uint8_t count;

  if (state == 0) {
    [glow]PORTB[/glow] |= 1<<3; //digital PIN 11
    [glow]OCR0A[/glow]+= 250;
    state++ ;
  } else if (state == 1) {
    [glow]OCR0A[/glow]+= atomicServoYaw; 
    state++;
  } else if (state == 2) {
    [glow]PORTB[/glow] &= ~(1<<3); //digital PIN 11
    count = 16;
    state++;
    [glow]OCR0A[/glow]+= 255;
  } else if (state == 3) {
    if (count > 0) count--;
    else state = 0;
    [glow]OCR0A[/glow]+= 255;
  }
}

The two processors are similar but not identical. The code will very likely need to be modified but probably not too dramatically.

I guess it's then too advanced for me at this stage.... :( ....Because I don't have a clue how to change it...thought it was more simple to change.... I'll probably buy the pro mini which will work out of the box with this code...

@Coding Badly:

What would be the proper way to generalise that code not to use direct hardware manipulation?

What would be the proper way to generalise that code not to use direct hardware manipulation?

Under the covers, analogRead, analogWrite, digitalRead, digitalWrite, and pinMode all use direct hardware manipulation. These functions are provided to allow you to write code that does not care what platform it is running on.

The compiler cares, which is why you have to select the appropriate board at compile time, but the code doesn't care.

The issues with analogRead, analogWrite, digitalRead, digitalWrite, and pinMode is that they are written in a way that allows them to map, at run time, pin numbers to ports for the specific hardware the code is running on, which makes them slow.

Direct port manipulation is used to improve performance of the code, on a specific piece of hardware. The tradeoff is that the code is then specific to that piece of hardware (or another piece just like it).

If performance is not an issue, don't use direct port manipulation.