[HELP] Compile sketch, working in Arduino Mega, in AtMega1284p-pu

Hi Guys,

I developed a scketch to work on Arduino Mega and I need to compile in an AtMega1284p-pu - Can I compile the same scketch in Atmega1284p-pu? - Is it necessary to change anything on the scketh? pins for example? - The AtMega1284p-pu is still a "virgin", which Arduino's bootloader is better to burn in?

Thanks

Angelo Ventura

  • yes, you will need to add/create a variant with ATmega1284P because it is not included in Arduino SW natively
  • yes, different MCU but similar, pins for example - it is defined in variant pins_arduino.h
  • optiboot

I used the Mighty core to bootload Atmega32 and 16 https://github.com/MCUdude/MightyCore, look at the install section to see how to install it with Arduino IDE.

It has the board for 1284 as well.

Look at the pins_arduino.h in variants folder and compare it with your Mega pins.

Optiboot bootloader, I think it's included with MightyCore.

You can compile a sketch for the mega on the 1284 with some considerations: * The pin numbers will obviously need to be different, since the 1284p doesn't have the same number of pins, and the PWM pins (and other peripherals) are on different pin numbers. * If you are using Serial2 or Serial3, that won't work on the 1284, since it only has 2 serial ports, not 4. There are a few other features that the mega2560 has that the 1284 doesnt (most of these aren't things people typically use though) * If you are doing any direct register manipulation (or using libraries that do), you need to review that and make sure the same registers exist on the 1284p. The first test here would be installing the core and seeing if the sketch compiles. If it complains about undefined variableswith cryptic allcaps names (ex TCCR4A, or UCSRA2), it's probably referring to registers that don't exist on the 1284. Some libraries that directly manipulate registers are smart enough to work with the 1284p without modification (and some will just work without any special measures being taken), while others are not. * The 1284p has less flash memory - your sketch must fit in 128k instead of 256k.

My project has a module enc28j60, Real Time Clock RTC DS1307 and lcd 20x4 i2c . I want to show , in atmega1284p , until the end of June :fearful: .

  • I'm using only one serial, for enc28j60;
  • How can I modify the pins???

Thanks for all the contributions,

Angelo Ventura

You need not to modify I2C, Serial0,1 also ISP. It is the same. Your code will probably work (without seeing it), maybe it will need some cosmetic changes. To modify the pins? Well, take a datasheet of 1284P or schematics of choosen variant. Both RTC and LCD uses I2C bus so find the SCL, SDA pins etc., etc.

You should work little and after this to show some setup in case of problems.

Take into consideration the librarys, i used to work with this on Arduino Mega:

#include <TimerOne.h>
#include <SPI.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include “RTClib.h”
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <EtherCard.h>

Is it necessary to change anything in the librarys or not? Only changes in the Arduino pins file is enought?

Thanks for the answers!!!