![]() |
Source: Arduino.cc |
The Micro and Leonardo boards share the same ATmega32U4 microprocessor and the same board architecture, so this write-up applies equally to both boards.
Starting work with the Arduino I quickly ran into trouble understanding the board pins, particularly in terms of how to work with them within the sketches. First, the board itself has a very tiny silkscreen name by each pin. If you were to, like I did, try to use those pin names in a function call, such as pinMode(D2, INPUT), the sketch will not compile. In the picture to the right, the integers and alias names in red provide the alias or integer to use in your code. From this, the earlier code fragment above would be pinMode(2, INPUT)0 or pinMode(SDA, INPUT).
Before I made the connections in my mind from the data in the board image here, I spent some time poking into the board-specific header files in the Arduino installation. The Leonard board header, which is called by the Micro board header is at Arduino\hardware\arduino\avr\variants\leonardo\pins_arduino.h. Where there are two integers or aliases seperated by a slash (/), the first is the digital reference and the second is the analog reference.
Board Name | PORT | PIN | Alternate Names/Functions | Integer | Alias |
MOSI | B | 2 | D16, PB2, MOSI, PCINT2 | 16 | MOSI |
SS | B | 0 | D17, PB0, RXLED, SS, PCINT0 | 17 | SS |
TX | D | 3 | D1, PD3, TXD1, INT3 | 1 | TX |
RX | D | 2 | D0, PD2, RXD1, INT2 | 0 | RX |
D2 | D | 1 | PD1, SDA , INT1 | 2 | SDA |
D3 | D | 0 | PD0, PWM8, SCL, OC0B, INT0 | 3 | SCL |
D4 | D | 4 | A6, PD4, ADC8 | 4/24 | 4/A6 |
D5 | C | 6 | PC6, OC3A, OC4A | 5 | |
D6 | D | 7 | A7, PD7, FastPWM, OC4D, ADC10 | 6/25 | 6/A7 |
D7 | E | 6 | PE6, INT6, AIN0 | 7 | |
D8 | B | 4 | A8, PB4, ADC11, PCINT4 | 8/26 | 8/A8 |
D9 | B | 5 | A9, PB5, PWM16, OC1A, OC4B, ADC12, PCINT5 | 9/27 | 9/A9 |
D10 | B | 6 | A10, PB6, PWM16, OC1B, 0C4B, ADC13, PCINT6 | 10/28 | 10/A10 |
D11 | B | 7 | PB7, PWM8/16, 0C0A, OC1C, RTS, PCINT7 | 11 | |
D12 | D | 6 | A11, PD6, T1, OC4D, ADC9 | 12/29 | 11/A11 |
D13 | C | 7 | PC7, PWM10, CLK0, OC4A | 13 | |
A0 | F | 7 | D18, PF7, ADC7 | 18 | |
A1 | F | 6 | D19, PF6, ADC6 | 19 | |
A2 | F | 5 | D20, PF5, ADC5 | 20 | |
A3 | F | 4 | D21, PF4, ADC4 | 21 | |
A4 | F | 1 | D22, PF1, ADC1 | 22 | |
A5 | F | 0 | D23, PF0, ADC0 | 23 | |
MISO | B | 3 | D14, PB3, MISO, PCINT3 | 14 | MISO |
SCK | B | 1 | D15, PB1, SCK, PCINT1 | 15 | SCK |
It took a frustratingly long time to figure that out. Also frustrating is that not all of the I/O pins have an alias. I've hacked together a short header file that can be used to give the pins relevant alias that match both the silk screened pin names on the board and the alternate functions I've dug out of the pins_arduino.h header file for the Leonardo boards.
No comments:
Post a Comment