Patching Wire for ATMega328PB

Just went through this exercise. To patch Wire to work properly with the 328PB, add this chunk to Wire/src/util/twi.h:

#ifdef __AVR_ATmega328PB__
#define TWAR TWAR0
#define TWBR TWBR0
#define TWDR TWDR0
#define TWCR TWCR0
#define TWSR TWSR0
#define TWI_vect TWI0_vect
#endif

Doing this will make the 328P include file TWI register and interrupt vectors match up with the "0" instance of the now dual TWI interfaces in the 328PB.

This doesn't give you access to the 2nd TWI interface, but I didn't need that. I just needed the code to compile and upload properly on the 328PB.

Why not use MiniCore instead, where this is done for you (and the second i2c port is available as Wire1)?

From pins_arduino.h

// Make sure the ATmega328PB is backwards compatible with the 328 and 328P
#if defined(__AVR_ATmega328PB__)
// SPI
  #define SPCR SPCR0
  #define SPSR SPSR0
  #define SPDR SPDR0
  #define SPI_STC_vect SPI0_STC_vect
  #define SPI_STC_vect_num SPI0_STC_vect_num
// I2C
  #define TWBR TWBR0
  #define TWSR TWSR0
  #define TWAR TWAR0
  #define TWDR TWDR0
  #define TWCR TWCR0
  #define TWAMR TWAMR0
  #define TWI_vect TWI0_vect
  #define TWI_vect_num TWI0_vect_num
// UART
  #define USART_RX_vect USART0_RX_vect
  #define USART_RX_vect_num USART0_RX_vect_num
  #define USART_UDRE_vect USART0_UDRE_vect
  #define USART_UDRE_vect_num USART0_UDRE_vect_num
  #define USART_TX_vect USART0_TX_vect
  #define USART_TX_vect_num USART0_TX_vect_num
#endif // 328PB defs

+1 to MiniCore