Hello all,

I am in a seriously strange situation. I have designed a temperature logging PCB with an ATMega328-AU chip to interface to the temp ICs.

I have uploaded the Atmega328P bootloader, so that I can use the arduino IDE and framework and libraries.
This was done by changing the ID for 328 to the ID of 328p in the avrdude.conf file.

According to the datasheet and pinout images found online, the pinout should be identical for the 328 and 328P chips.

I have had problems communicating to the ICs on the board via software SPI, so I have written a basic pin on/off program to check that everything works as expected.
But when I define 2 pins, PB0 (SDO, Arduino pin 8) and PB2 (SCK, Arduino pin 11) as outputs and flip them with a 1 s delay, it is not those pins that flip, according the pinout above.
Instead it is PD2 (pin 2) and PD0 (pin 0) which flips!

This is my code:

int sdo = PB0;
int sck = PB2;

void setup() {
pinMode(sdo, OUTPUT);
void loop() {
digitalWrite(sdo, HIGH);
digitalWrite(sck, HIGH);
digitalWrite(sdo, LOW);
digitalWrite(sck, LOW);

Can someone explain what is going on here? I have attached the schematic for the MCU.

Arduino I/O functions like pinMode() and digitalWrite() use Arduino pin numbers. PB0 PB2 are just macros defined as the bit number:

#define PB0 0
#define PB2 2

So when you pass the values of those macros to Arduino I/O functions, of course it's going to control the associated Arduino pins. If you want to use Arduino functions you need to use Arduino pin numbers, which are in brown in your diagram. If you want to write to the AVR port/bit registers then you will not be able to use Arduino I/O functions. Take your pick, but don't try to mix them.