Using A6/A7

The EtherTen combines an Uno-equivalent Arduino-compatible board and Wiznet-based Ethernet support, along with a microSD card slot and Power-over-Ethernet support. [Product page]
Post Reply
JollyJohn
Posts: 10
Joined: Sun Dec 04, 2011 6:00 am

Using A6/A7

Post by JollyJohn » Sun Dec 04, 2011 6:22 am

Hi,
I have a project that is using a high number of digital output pins. Due to a last minute need for two more I've brought A6 and A7 up to the proto board I'm using and used the appropriate pinMode to set them as output pins - but to no avail. Is there a trick to using these pins I'm missing? I can't seem to get them to switch.

Thanks,
John

JollyJohn
Posts: 10
Joined: Sun Dec 04, 2011 6:00 am

Re: Using A6/A7

Post by JollyJohn » Sun Dec 04, 2011 7:52 am

Thinking more about it this may be due to the board definition in the Arduino software system thinking the board I have doesn't have A6/A7 and quietly refusing to work with them. Any other ideas?

LukeW
Posts: 91
Joined: Tue Nov 01, 2011 10:14 am

Re: Using A6/A7

Post by LukeW » Thu Jan 05, 2012 12:39 pm

I wrote a simple test program, as follows.

I tested this on an Arduino Duemilanove (DIP ATmega328 w/ FTDI) and a Freetronics Eleven (DIP ATmega328 w/ ATmega8U2) and it compiled and uploaded successfully in both cases. It of course generates "nonsense" ADC readings with the pins floating, though.

However, I don't have an EtherTen board (or a USBDroid, which is the same for the purposes of this discussion) so I can't test this in actual operation on the hardware.

I'm pretty sure that the actual ATmega328/168 silicon ICs incorporate all 8 of the analog input channels, and they're all the same in all the IC packages, except that when they're packaging them in the DIP packages they don't have enough pins in the package so they don't install the wire bonds to the ADC6 and ADC7 pins and they just leave them floating.

You're right in what you're saying. The Freetronics EtherTen (and the USBDroid which is the same in this context) use SMD ATmega328 chips with the A6 and A7 pins broken out and connected to useable pins. The Arduino Mini hardware is the same in this respect, but they are designed for use with an FTDI cable and they are not used in conjunction with an ATmega8U2-based USB-to-serial interface. This means that the EtherTen/are completely unique Arduino hardware which is slightly different from any official Arduino hardware product in regards to potential software support for using these pins.

So, yes, maybe it will require a modification to boards.txt or the other files within the Arduino IDE that control the hardware definitions, but I'm not 100% sure.

If all else fails, maybe you can try editing boards.txt. I have included a portion of what your edited boards.txt file might look like, for example, below.

Code: Select all


    int i = 0, j = 0;

void setup()
{
    pinMode(A6, OUTPUT);
    pinMode(A7, OUTPUT);
    Serial.begin(38400);
}

void loop()
{
    digitalWrite(A6, HIGH);
    digitalWrite(A7, HIGH);
    delay(100);
    pinMode(A6, INPUT);
    pinMode(A7, INPUT);
    i = analogRead(A6);
    j = analogRead(A7);
    Serial.println(i);
    Serial.println(j);
}

Code: Select all

##############################################################

uno.name=Arduino Uno 
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.speed=115200
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
uno.bootloader.path=optiboot
uno.bootloader.file=optiboot_atmega328.hex
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.core=arduino
uno.build.variant=standard

##############################################################

# This entry corresponds to Arduino Uno compatible hardware which
# uses a surface-mount ATmega328 chip and has the A6 and A7 pins
# connected, for example the Freetronics EtherTen or USBDroid.
# This should allow analog input pins 6 and 7 to be used.
# This is basically just a copy of the above entries for the Arduino
# Uno, renamed of course.

etherten.name=Freetronics EtherTen or USBDroid etc. w/ A6 and A7
etherten.upload.protocol=arduino
etherten.upload.maximum_size=32256
etherten.upload.speed=115200
etherten.bootloader.low_fuses=0xff
etherten.bootloader.high_fuses=0xde
etherten.bootloader.extended_fuses=0x05
etherten.bootloader.path=optiboot
etherten.bootloader.file=optiboot_atmega328.hex
etherten.bootloader.unlock_bits=0x3F
etherten.bootloader.lock_bits=0x0F
etherten.build.mcu=atmega328p
etherten.build.f_cpu=16000000L
etherten.build.core=arduino
# uno.build.variant=standard # This line is commented out
etherten.build.variant=eightanaloginputs # This line is added

##############################################################

User avatar
jonoxer
Freetronics Staff
Freetronics Staff
Posts: 298
Joined: Sat Oct 15, 2011 11:31 am
Location: Melbourne, Australia
Contact:

Re: Using A6/A7

Post by jonoxer » Thu Apr 12, 2012 11:45 pm

A6 and A7 are rather oddball, and I don't think you'll be able to use them in the way you want to.

According to the ATmega328P datasheet, ADC0 through ADC5 are on port C, which is also a regular digital I/O port. However, ADC6 and ADC7 are orphans that can be addressed directly but aren't part of a digital I/O port. I have no idea why the MCU was designed that way, but that's the way it is.

So you should be able to use A6 and A7 as analog inputs, but you can't use them as digital outputs. Sorry. It's not a specific limitation of our boards as opposed to any other Arduino-compatible board, it's just a limitation of the MCU itself.

Could you gain yourself some digital outputs using a shift register or switching some of your other I/O to another method? Perhaps have a look at http://www.freetronics.com/expand
--
Jon

Post Reply