# Simple way to add ATmega328PB (to ArduinoCore)

**URL:** <https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450>\
**Category:** Programming\
**Created:** [May 18, 2023, 4:53pm UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450 "2023-05-18T16:53:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![amazed](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/amazed/32/743023_2.png) [@amazed](https://forum.arduino.cc/u/amazed)\
**Post date:** [May 18, 2023, 4:53pm UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/1 "2023-05-18T16:53:14Z")

</div>

Continuing the discussion from [Trying to get ATmega328PB to work with Arduino IDE](https://forum.arduino.cc/t/trying-to-get-atmega328pb-to-work-with-arduino-ide/946071/4):

> [@Trying to get ATmega328PB to work with Arduino IDE](https://forum.arduino.cc/t/trying-to-get-atmega328pb-to-work-with-arduino-ide/946071/4):
>
> Truthfully, you should be able to use a 328pb just like a 328p (same bootloader, etc) - there's nothing there that "needs to know" about the extra features of the PB.

I think the signature of the 328PB MCU will not match, so upload is not possible right away. For example, if I try to upload a sketch compiled for 328PB to a 328P equipped board, it fails.

If somebody would like to use the **original** [**ArduinoCore**](https://github.com/arduino/ArduinoCore-avr) **for 328PB** (and not interested in the additional features of PB variant), then here is an easy solution:

1. **Download, and add** [**pb-variant**](https://github.com/MCUdude/MiniCore/tree/master/avr/variants) folder into to the ArduinoCore variants folder  
(`C:\Users\ME\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\`)  
 ![kép](https://europe1.discourse-cdn.com/arduino/original/4X/a/7/4/a7422992885bb302a8570dcf4320a55193f29b7a.png)

2. **Add a custom board** with the following properties `boards.txt` (it can be a copy of UNO)

- build.mcu=atmega328pb --\> signature will match (all register addresses are available for bit banging)
- build.variant=pb-variant --\> backward compatibility is provided

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [May 18, 2023, 6:39pm UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/2 "2023-05-18T18:39:19Z")

</div>

why not use MiniCore?

---

<div class="post-metadata">

**Author:** ![PaulRB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulrb/32/216330_2.png) [@PaulRB](https://forum.arduino.cc/u/PaulRB)\
**Post date:** [May 18, 2023, 6:41pm UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/3 "2023-05-18T18:41:26Z")

</div>

+1 for MiniCore suggestion.

---

<div class="post-metadata">

**Author:** ![amazed](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/amazed/32/743023_2.png) [@amazed](https://forum.arduino.cc/u/amazed)\
**Post date:** [May 19, 2023, 4:46am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/4 "2023-05-19T04:46:10Z")

</div>

> [@Juraj](#):
>
> why not use MiniCore?

If I have a well tested sketch (with ArduinoCore) and I would need to switch to 328PB, then I would consider sticking to the original core. As it is stated in the related [application note:](https://onlinedocs.microchip.com/pr/GUID-CBDC1838-0100-4F26-A45A-134958193C3B-en-US-4/index.html)

> The code that is available for your existing ATmega328 variants will continue to work on the new ATmega328PB device.

You don't need a whole new platform, just a few adjustments stated above.

Starting a new project with 328PB is a different story, especially if it would use the new peripherials of the PB version.

---

<div class="post-metadata">

**Author:** ![westfw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/westfw/32/213443_2.png) [@westfw](https://forum.arduino.cc/u/westfw)\
**Post date:** [May 19, 2023, 5:20am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/5 "2023-05-19T05:20:01Z")

</div>

If you burn the ATmega328p (not PB) bootloader into a PB, it will lie to the IDE thereafter, claiming itself just a 328p, and probably everything will work fine. This requires slight finesse while burning the bootloader, but doesn't require any other boards.txt changes or anything.

(You can do the same thing with an ATmega328 (not P), but that's less surprising since it is essentially identical to a 328P. Whereas the PB has "extra features" that can be ignored.)

---

<div class="post-metadata">

**Author:** ![amazed](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/amazed/32/743023_2.png) [@amazed](https://forum.arduino.cc/u/amazed)\
**Post date:** [May 24, 2023, 6:43am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/6 "2023-05-24T06:43:01Z")

</div>

> [@westfw](#):
>
> If you burn the ATmega328p (not PB) bootloader into a PB..

Does this can be done from the IDE? Isn't the signature checked when you burn a bootloader?  
I'm sure it can be done with an `avrdude` command using [-F option](https://www.nongnu.org/avrdude/user-manual/avrdude_3.html#Option-Descriptions).

---

<div class="post-metadata">

**Author:** ![amazed](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/amazed/32/743023_2.png) [@amazed](https://forum.arduino.cc/u/amazed)\
**Post date:** [May 24, 2023, 7:05am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/7 "2023-05-24T07:05:36Z")

</div>

In summary, there are three options so far:

1. If the ATmega328PB is intended to be programmed via USB, then a ATmega328P bootloader can hide the fact, that the chip is actually a PB variant. The original [**ArduinoCore**](https://github.com/arduino/ArduinoCore-avr) can be used, additional features of PB variant will be unavailable.

2. Add PB variant to the IDE with the method described in [**#1**](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450). The original [**ArduinoCore**](https://github.com/arduino/ArduinoCore-avr) can be used, additional GPIOs, Timers of the PB variant will be available on register level.

3. Use [**MiniCore**](https://github.com/MCUdude/MiniCore) platform for full support.

---

<div class="post-metadata">

**Author:** ![westfw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/westfw/32/213443_2.png) [@westfw](https://forum.arduino.cc/u/westfw)\
**Post date:** [May 24, 2023, 7:58am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/8 "2023-05-24T07:58:42Z")

</div>

> [@amazed](#):
>
> can be done from the IDE?

In general, no. You can modify avrdude's configuration file, but that's generally not a good idea. Best to manually burn the "fake" bootloader, correctly identifying the chip as a 328P at that time.

---

<div class="post-metadata">

**Author:** ![volkerforster](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/volkerforster/32/1204472_2.png) [@volkerforster](https://forum.arduino.cc/u/volkerforster)\
**Post date:** [October 22, 2023, 12:29am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/9 "2023-10-22T00:29:57Z")

</div>

I need to warm this up again because of an experience I made yesterday:  
I received a bunch of used, Chinese NANO's and wanted to put them through a simple test, only to find out which of them are actually dead. At this point I didn't know they were equipped with the PB chip.  
I used Arduino 2.x the latest version and just flashed a Blink on them, and it worked with no compiling or upload issues. Later the day I found out that all of them were PD chips, and I was surprised that I didn't have any issues programming them with the IDE.  
I then tried the same with the Arduino IDE 1.x and programming failed on them.  
Of course, a big question cam up: Did Arduino add "native" support for the PD chips recently?  
Someone else made a similar experience, that IDE 2.x is capable of compiling and programming code for Atmega328PB without modifications and add-ons?  
The Arduino AVR board manager file installed on both IDEs (1.x and 2.x) was the same.

---

<div class="post-metadata">

**Author:** ![westfw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/westfw/32/213443_2.png) [@westfw](https://forum.arduino.cc/u/westfw)\
**Post date:** [October 22, 2023, 12:36am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/10 "2023-10-22T00:36:04Z")

</div>

Normally, the bootloader lies about chip type, and a PB chip is close enough to a P chip that it doesn't matter. In fact, if your "derivative" boards simply used PB chips on a board designed for the P version (which also "works"), it may be better to go on having the IDE think that they are just P chips - one of the differences is that the PB has IO pins where the P has power pins, which is OK as long as you never configure those pins as outputs...

You may have to change the processor to "old bootloader" (or not) to upload.

---

<div class="post-metadata">

**Author:** ![volkerforster](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/volkerforster/32/1204472_2.png) [@volkerforster](https://forum.arduino.cc/u/volkerforster)\
**Post date:** [October 24, 2023, 3:11pm UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/11 "2023-10-24T15:11:53Z")

</div>

I will open a new topic for my question. Doesn't look like anyone is reading here anymore after half a year 😉

---

<div class="post-metadata">

**Author:** ![amazed](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/amazed/32/743023_2.png) [@amazed](https://forum.arduino.cc/u/amazed)\
**Post date:** [October 25, 2023, 4:51am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/12 "2023-10-25T04:51:20Z")

</div>

You can be sure, that there are some people who read it. You already got an answer, didn't you? 🙂

> I then tried the same with the Arduino IDE 1.x and programming failed on them.

Are you sure that both IDE was configured the same way before upload? E.g. the bootloader selection what @westfw mentioned.

---

<div class="post-metadata">

**Author:** ![westfw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/westfw/32/213443_2.png) [@westfw](https://forum.arduino.cc/u/westfw)\
**Post date:** [October 25, 2023, 8:04am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/13 "2023-10-25T08:04:13Z")

</div>

Hmm. See also [Does IDE 2.2 comes with native Atmega328PB support?](https://forum.arduino.cc/t/does-ide-2-2-comes-with-native-atmega328pb-support/1181761)

---

<div class="post-metadata">

**Author:** ![volkerforster](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/volkerforster/32/1204472_2.png) [@volkerforster](https://forum.arduino.cc/u/volkerforster)\
**Post date:** [October 26, 2023, 10:49pm UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/14 "2023-10-26T22:49:11Z")

</div>

Yup, my mistake. I didn't read westfw's reply as an answer to my question. It took me a second look to understand what they meant.

It seems like the PB's on Chinese boards have the standard NANO bootloader installed and don't look any different to the IDE than the P version modules. As long nobody tries to make use of the ports on the pins 3 and 6, they should just work like any NANO or UNO with the P-chip.

---

<div class="post-metadata">

**Author:** ![kleber\_bear](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@kleber\_bear](https://forum.arduino.cc/u/kleber_bear)\
**Post date:** [February 8, 2024, 12:22pm UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/15 "2024-02-08T12:22:25Z")

</div>

Hello everybody,  
I've been trying to use the Atmega328PB for some time and so far it has won the battles. I received some parts from a friend and they are original, I'm using a generic Arduino Uno board as a base (I modified pins 3 and 6), but I have a lot of difficulty using them with the "minicore" the bootloader doesn't work correctly, now after so much time changing several things I will need to re-install the IDE.  
I wanted to know if anyone knows or can provide a step by step guide for idiot, I want to do everything correctly this time.  
Tips, tricks and prayers are welcome.  
Thanks.

---

<div class="post-metadata">

**Author:** ![westfw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/westfw/32/213443_2.png) [@westfw](https://forum.arduino.cc/u/westfw)\
**Post date:** [February 9, 2024, 2:32am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/16 "2024-02-09T02:32:07Z")

</div>

> [@kleber\_bear](#):
>
> step by step guide for idiot

Buy a board that already has the 328PB and its bootloader installed.  
Like: [Pololu - A-Star 328PB Micro](https://www.pololu.com/category/239/a-star-328pb-micro)

How did you install the bootloader once the PB chip was on the board? Or is that the part that is causing problems?

(I don't remotely consider modifying an Uno (SMD?) board and putting a 328PB on it to be an "idiot class" thing to do. Although I guess there are HW gurus that have problems with SW. Why do you want a PB variant, anyway?)

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [February 9, 2024, 2:58am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/17 "2024-02-09T02:58:29Z")

</div>

+1 for Pololu. They write excellent documentation, support their products professionally via their forum, and their board designs just WORK.

---

<div class="post-metadata">

**Author:** ![Klausj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/klausj/32/1102281_2.png) [@Klausj](https://forum.arduino.cc/u/Klausj)\
**Post date:** [June 27, 2024, 2:51pm UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/18 "2024-06-27T14:51:44Z")

</div>

I did not know bootloaders can lie. So I checked it: yes they can.  
Actually, I installed both board types, MiniCore and Pololu (I did not try Elektor) which both work pretty well, only to find out that the pins of PORT E are getting different numbers. My aim was to find out in a sketch which board definition actually was used. It seems there is no #define for board names. At the end of the day, I managed to find that the entry NUM\_DIGITAL\_PINS was 24 for Pololu and 27 for MiniCore. Obviously MiniCore gives access to the crystal pins located at port B.  
See my results below.

```arduino
[code]
/*
  https://joy-it.net/files/files/Produkte/ARD-One-C-MC/ARD-One-C-MC_Manual-EN_2024-04-17.pdf
*/
#include <avr/boot.h>
#define SIGRD 5
void setup() {
  Serial.begin(9600);
  Serial.println("\n" __FILE__ );
  long sig = 0;
  for (int i = 0; i < 3; i++)
    ((byte*)(&sig))[2 - i] = boot_signature_byte_get(2 * i);
  Serial.print("\nIdentified by signature = ");
  Serial.print(sig, HEX);
  Serial.print(" should be ");
  switch (sig) {
    case 0x1E950F: Serial.println("ATmega328P"); break;
    case 0x1E9516: Serial.println("ATmega328PB"); break;
  }
  Serial.print("result given by bootloader: ");
#if defined( __AVR_ATmega328PB__ )
  Serial.println("ATmega328PB");
#else
  Serial.println("no ATmega328PB");
#endif
  int ndp = NUM_DIGITAL_PINS;
  Serial.print("\nNumber of digital pins: ");
  Serial.println(ndp);
  Serial.print("Board type: ");
  switch (ndp) {
    case 20: Serial.println("Arduino Standard"); break;
    case 24: Serial.println("Pololu"); break;
    case 27: Serial.println("MiniCore"); break;
    default: Serial.println("no idea");
  }
  Serial.println("\ni\tport\tbit-nr");
  char prev = ' ';
  for (byte i = 0; i < ndp; i++) {
    char a = pgm_read_byte(&digital_pin_to_port_PGM[i]) + '@';
    byte b = pgm_read_byte(&digital_pin_to_bit_mask_PGM[i]);
    byte c = log(b) / log(2);
    if (a != prev) Serial.println("----------------------");
    Serial.print(i);
    Serial.print("\t");
    Serial.print(a);
    Serial.print("\t");
    Serial.print(c);
    Serial.println();
    prev = a;
  }
}

void loop() {}

/*
  Pololu
  ------
  i port mask
  -------------
  0 D 0
  1 D 1
  2 D 2
  3 D 3
  4 D 4
  5 D 5
  6 D 6
  7 D 7
  -------
  8 B 0
  9 B 1
  10 B 2
  11 B 3
  12 B 4
  13 B 5
  -------
  14 C 0
  15 C 1
  16 C 2
  17 C 3
  18 C 4
  19 C 5
  -------
  20 E 2
  21 E 3
  22 E 0
  23 E 1

  Minicore
  --------
  i port mask
  -------------
  0 D 0
  1 D 1
  2 D 2
  3 D 3
  4 D 4
  5 D 5
  6 D 6
  7 D 7
  -------
  8 B 0
  9 B 1
  10 B 2
  11 B 3
  12 B 4
  13 B 5
  -------
  14 C 0
  15 C 1
  16 C 2
  17 C 3
  18 C 4
  19 C 5
  -------
  20 B 6 = XTAL1
  21 B 7 = XTAL2
  22 C 6
  23 E 0
  24 E 1
  25 E 2
  26 E 3

*/
[/code]

```

---

<div class="post-metadata">

**Author:** ![ptillisch](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptillisch](https://forum.arduino.cc/u/ptillisch)\
**Post date:** [June 30, 2024, 3:29am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/19 "2024-06-30T03:29:14Z")

</div>

Hi @Klausj.

> [@Klausj](#):
>
> It seems there is no #define for board names.

The developer of each [Arduino boards platform](https://arduino.github.io/arduino-cli/latest/platform-specification/) has the freedom to configure the behavior of the platform as they like, but there is a common convention to provide such macros. All the official Arduino boards platforms do so and I think most of the 3rd party platforms do as well.

For example, if you have the "Arduino Uno" board of the " **Arduino AVR Boards**" platform selected, then the macro `ARDUINO_AVR_UNO` will be defined:

> <https://github.com/arduino/ArduinoCore-avr/blob/1.8.6/platform.txt#L54-L61>

(note the `-DARDUINO_{build.board}` [flag](https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#index-D-1) in the compilation command templates)

> <https://github.com/arduino/ArduinoCore-avr/blob/1.8.6/boards.txt#L104-L104>

If you have the "ATmega328" board of the " **MiniCore**" platform selected, then the macro `ARDUINO_AVR_ATmega328` will be defined:

> <https://github.com/MCUdude/MiniCore/blob/v3.0.2/avr/platform.txt#L55-L62>

(note the `-DARDUINO_{build.board}` flag in the compilation command templates)

> <https://github.com/MCUdude/MiniCore/blob/v3.0.2/avr/boards.txt#L31-L31>

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 27, 2024, 3:30am UTC](https://forum.arduino.cc/t/simple-way-to-add-atmega328pb-to-arduinocore/1128450/20 "2024-12-27T03:30:05Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
