Pages: [1]   Go Down
Author Topic: ATMEGA32U4 Breakout Board Issue - Analog Pins as Digital  (Read 1894 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 96
Why is it so?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey all

i have an interesting issue i can't seem to figure out.
i have an ATMEGA32U4 Breakout Board running the Leonardo bootloader.

When i do:
pinMode([0-17], OUTPUT);
digitalWrite([0-17],[HIGH|LOW]);
everything works as intended.

When i try to address the Analog Pins (A0-A5) on Port F(PF0-PF7) as Digital pins
pinMode([18-23], OUTPUT);
digitalWrite([18-23], [HIGH|LOW]);
no dice

my question is, on the ATMEGA32U4, can the Analog Pins not be used as Digital Pins as they where on the ATMEGA328?
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1328
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


  I don't know but, in the pin.H assignment list it does not show digital 18-23.

 I would try
Code:
pinMode([A0-A5], OUTPUT);
digitalWrite([A0-A5], [HIGH|LOW])

Let us know if that works.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26438
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The position of the pins in the list is was determines their digital #.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26438
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is from the Leonardo pins_arduino.h file,
C:\Arduino-1.0\hardware\arduino\variants\leonardo\pins_arduino.h

So the pins do seem to be defined.

const uint8_t PROGMEM digital_pin_to_port_PGM[30] = {
   PD, // D0 - PD2
   PD,   // D1 - PD3
   PD, // D2 - PD1
   PD,   // D3 - PD0
   PD,   // D4 - PD4
   PC, // D5 - PC6
   PD, // D6 - PD7
   PE, // D7 - PE6
   
   PB, // D8 - PB4
   PB,   // D9 - PB5
   PB, // D10 - PB6
   PB,   // D11 - PB7
   PD, // D12 - PD6
   PC, // D13 - PC7
   
   PB,   // D14 - MISO - PB3
   PB,   // D15 - SCK - PB1
   PB,   // D16 - MOSI - PB2
   PB,   // D17 - SS - PB0
   
   PF,   // D18 - A0 - PF7
   PF, // D19 - A1 - PF6
   PF, // D20 - A2 - PF5
   PF, // D21 - A3 - PF4
   PF, // D22 - A4 - PF1
   PF, // D23 - A5 - PF0
   
   PD, // D24 / D4 - A6 - PD4
   PD, // D25 / D6 - A7 - PD7
   PB, // D26 / D8 - A8 - PB4
   PB, // D27 / D9 - A9 - PB5
   PB, // D28 / D10 - A10 - PB6
   PD, // D29 / D12 - A11 - PD6
};
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 96
Why is it so?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks CrossRoads.
I double checked my pin assignment in the code and it is accurate to my wiring and the pins_arduino.h

Although while double checking my design to the pins_arduino.h i noticed some duplication of port usage for A6 - A11 (see below)

const uint8_t PROGMEM digital_pin_to_port_PGM[30] = {
   PD, // D0 - PD2
   PD,   // D1 - PD3
   PD, // D2 - PD1
   PD,   // D3 - PD0
   PD,   // D4 - PD4
   PC, // D5 - PC6
   PD, // D6 - PD7
   PE, // D7 - PE6
   
   PB, // D8 - PB4
   PB,   // D9 - PB5
   PB, // D10 - PB6
   PB,   // D11 - PB7
   PD, // D12 - PD6
   PC, // D13 - PC7
   
   PB,   // D14 - MISO - PB3
   PB,   // D15 - SCK - PB1
   PB,   // D16 - MOSI - PB2
   PB,   // D17 - SS - PB0
   
   PF,   // D18 - A0 - PF7
   PF, // D19 - A1 - PF6
   PF, // D20 - A2 - PF5
   PF, // D21 - A3 - PF4
   PF, // D22 - A4 - PF1
   PF, // D23 - A5 - PF0
   
   PD, // D24 / D4 - A6 - PD4
   PD, // D25 / D6 - A7 - PD7
   PB, // D26 / D8 - A8 - PB4
   PB, // D27 / D9 - A9 - PB5
   PB, // D28 / D10 - A10 - PB6
   PD, // D29 / D12 - A11 - PD6
};

Does the Leonardo do some kind of multiplexing on those pins?
I did notice in the datasheet that these are ADC8 - ADC13, but as i understand you either would use them as A6-A11 or D4, D6, D8, D9, D10, D12 not both.

Also asked this in the Adafruit forum and got this answer about the lack of Digital support on Analog 0-5
"this is a bug in the leonardo support for Arduino - its still beta so we suspect it will be fixed when its out of beta "
"this is part of the IDE itself, no idea how to fix it."
« Last Edit: December 14, 2011, 06:41:47 am by 32teeth » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26438
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I suspect you as the coder will have to do the multiplexing if the pins are connected to the same header pin.
If using an Analog pin, then the digital pin will have to pinMode'd as an input so as not to interfere, as an example.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: