How to access unused pins on an atmega1280?

Hi all,

I've just put together a makeshift 'arduino mega 1280' on a TQFP100 breakout board, bootloaded it, and it's going fine.

There are a number of unused I/O pins on the arduino mega, ie. it has 54 digital I/O + 16 with analog, for a total of 70 possible digital outs, but the chip actually has 86.

So my question is, is there a way to get full access to the 86 pins through the arduino IDE? If not, what kind of alterations might I make to make it possible? Perhaps an addition to the hardware/arduino/variants/mega/pins_arduino.h file?

If anyone could point me in the right direction I'd be greatly appreciated.

"Perhaps an addition to the hardware/arduino/variants/mega/pins_arduino.h file?"
Yes.
There are 3 areas where the ports are listed, where the bit for the port is listed, and whether the bit is on a timer.
So you need to start with adding the pins there.
There are some other places where the numbe of IO is listed, and some other stuff. I can't follow all of it, troublle readig the cryptic undocumemted C code.
I'm also interested in accessing more pins, haven't gotten around to chasing all the changes down.

Perhaps an addition to the hardware/arduino/variants/mega/pins_arduino.h file?

That certainly is one way.

Another would be to use port access available in gcc-avr.

"use port access available in gcc-avr."

Can you explain how to do that and stay within the IDE?

Hi, thanks for your replies.

So for now, I'll try just adding a pin 70, on PJ2, the unused pin 65 on the chip. I've added lines at the end of each of those three areas you mentioned. It compiles and all, but I don't get a blink yet.

Perhaps it has to do with the defines part at the beginning of the file :

#define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 13)) || \
                                  (((p) >= 50) && ((p) <= 53)) || \
                                  (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )

#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
                                ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
                                0 ) )

#define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
                                ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
                                ((uint8_t *)0) ) )

#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
                                ( ((p) == 50) ? 3 : \
                                ( ((p) == 51) ? 2 : \
                                ( ((p) == 52) ? 1 : \
                                ( ((p) == 53) ? 0 : \
                                ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
                                0 ) ) ) ) ) )

#ifdef ARDUINO_MAIN

Does anyone have any idea how to interpret the meaning of this?

You don't need to worry about those lines unless you plan to use PJ2 as a pin change interrupt. However if you do, I have modified them for you:

#define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 13)) || \
                                  (((p) >= 50) && ((p) <= 53)) || \
                                  (((p) >= 62) && ((p) <= 69)) || \
								  ((p) == 70) ? (&PCICR) : ((uint8_t *)0) )

#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
                                ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
                                ( ((p) == 70) ? 1 : 0 ) ) )

#define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
                                ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
                                ( ((p) == 70) ? (&PCMSK1) : ((uint8_t *)0) ) ) )

#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
                                ( (((p) >= 50) && ((p) <= 53)) ? (53 - (p)) : \
                                ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
                                ( ((p) == 70) ? 3 : 0 ) ) ) )

In order to get a new pin to work, you need to do a several steps:
(1) at the end of this:

const uint8_t PROGMEM digital_pin_to_port_PGM[]

add this:

	PJ	, // PJ 2 ** 70 ** D70

This specifies which port the pin is on (in this case J)

(2) at the end of this:

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]

add this:

	_BV( 2 )	, // PJ 2 ** 70 ** D70

This specifies a bit mask for this pin in its port (In this case it is the bitmask for pin 2)

(3) at the end of this:

const uint8_t PROGMEM digital_pin_to_timer_PGM[]

add this:

	NOT_ON_TIMER	, // PJ 2 ** 70 ** D70

This specifies that it is not a PWM output (which it is not)

(4) at the to, change this:

#define NUM_DIGITAL_PINS            70

to this:

#define NUM_DIGITAL_PINS            71

This tells the IDE there are now 71 useable pins not 70.

Then restart the IDE and try to run the code. It should work.

Hi Tom,

Thank you very much for your detailed explanation! By going through those steps I was able to add all the rest of the pins, and I've blink-tested that they all work.

Thanks again

kx,
Can you post that please?

By 'post that' I guess you mean my pins_arduino.h file for the mega?

I'll attach it to this message. It is to be placed in the hardware/arduino/variants/mega directory. You may prefer different placement of the pins, but I just kept the original arduino mega pins, and went around the chip adding the missing pins to the end
from D70 till D85. An 86 pin Arduino for about $15, not bad eh?

Hope it's useful,

cheers

pins_arduino.h (13 KB)

Yes, that's what I mean. Thanks!

I have a couple of schmart boards and 2560 chips, planning to make a "standalone 2560" out of it. Add a crystal, caps, bunch of headers, be good to go!
This will make all the IO pins usable.
Now just need another 40 hours a week free for all my projects!

CR keep us posted on your progress I would likke to use all of a 2560 like you except for a dedicated board rather than your "Open Face" design. This kindergarten project og mine could really grow if I could move part of the GLCD. It would let me save my "Nice" 4D Systems 3.2 SGC for smoething better than this one... or maybe not.

Bob

How would you layout such a dedicated board?
I have several designs in the works, but mostly for the serial ports availability. A lot of the IO is not used.