Bare microcontroller pin outs....

Im struggling to find the answer to this - and i'm sure the question must have been asked before, so apologies if I haven't searched using the correct terms.

I'm starting the move to using a bare microcontroller (in this case a 328p) in a project where I am going to build the pcb myself, and program the 328p in circuit.

What I am struggling with is understanding how to 'map' the pins of, say, a nano board to the 328p when writing the code.

Can someone point me to the working out / understanding which pin arduino thinks is pin 1 on the nano and how it is going to address that on the 328p (its a tqfp package).

Im confusing myself even asking the question.

Thanks in advance

James

If it is a part from an official board, and using the official board definitions, just Google "arduino pinout" and the part number. There are some great diagrams for '328p.

If it is a part not used on an official board, or you are using a third party board package for it (ex, a 328pb with minicore, or an attiny with one of my cores), a pinout diagram will be in the documentation included with the third party board package.

DrAzzy:
If it is a part from an official board, and using the official board definitions, just Google "arduino pinout" and the part number. There are some great diagrams for '328p.

If it is a part not used on an official board, or you are using a third party board package for it (ex, a 328pb with minicore, or an attiny with one of my cores), a pinout diagram will be in the documentation included with the third party board package.

Ah - yes my original question didn't really make clear what I am struggling with, which I thought might be the case.

So say for example I write in the arduino IDE

digitalWrite (4, LOW);

This sends digital pin 4 on the nano board low.

However the bare microcontrollers do not have neatly numbered digital I/O pins, they have a series of ports so for example Port B I/O number 3 (PB3).

So what I guess I am asking, is where abouts I find the conversion table for how the arduino IDE 'looks up' what digital pin 4 is for example when writing to the port on the microcontroller.

I hope that makes more sense?... its still a bit muddled I guess.

The conversion table is in the variants file. For the classic Arduino Nano, the variant used is "eightanaloginputs":

but that pretty much just points to the "standard" variant:

There, you will find several PROGMEM arrays. The Arduino pin number is the index of the array. So if you look at digital_pin_to_port_PGM[4]:

PD,

you can see that Arduino pin 4 is port D
and if you look at digital_pin_to_bit_mask_PGM[4]:

_BV(4),

you can see that Arduino pin 4 is bit 4 of port D (PD4)

If you looked at the pinout charts as suggested, you'd find something like this:

they show the arduino pin number, the port number (eg, PC2), the analog pin number (if applicable), list any special functions, all showing which physical pin that corresponds to

pert:
The conversion table is in the variants file. For the classic Arduino Nano, the variant used is "eightanaloginputs":
ArduinoCore-avr/variants/eightanaloginputs/pins_arduino.h at master · arduino/ArduinoCore-avr · GitHub
but that pretty much just points to the "standard" variant:
ArduinoCore-avr/variants/standard/pins_arduino.h at master · arduino/ArduinoCore-avr · GitHub
There, you will find several PROGMEM arrays. The Arduino pin number is the index of the array. So if you look at digital_pin_to_port_PGM[4]:

PD,

you can see that Arduino pin 4 is port D
and if you look at digital_pin_to_bit_mask_PGM[4]:

_BV(4),

you can see that Arduino pin 4 is bit 4 of port D (PD4)

Thanks thats great - I understand how I can work it out now :slight_smile:

DrAzzy:
If you looked at the pinout charts as suggested, you'd find something like this:

they show the arduino pin number, the port number (eg, PC2), the analog pin number (if applicable), list any special functions, all showing which physical pin that corresponds to

Thanks - the pinouts I have been using / seen have never included the arduino pin reference as per the one you posted, which is why I have been struggling.

Having done another google search (the same one I think I did the first time - 'atmega 328pu tqfp pinout' a few of them have the arduino pins listed, just by chance I must have only clicked on the ones that didn't or I would not have asked the question!

Thanks for your help