COVID-19 impact: We are still operating and shipping all orders! Physical operations are reduced to a skeleton crew, so for critical requirements, including fighting COVID-19, please contact us so we can identify priorities. Click here for more info.

4.4. ATmega328PB support in the Arduino IDE

Since the A-Star’s ATmega328PB microcontroller is backward-compatible with the ATmega328P commonly used on Arduino boards (like the Arduino Uno and Pro Mini), existing programs and libraries written for a standard Arduino can be used on the A-Star 328PB without any changes (except to account for clock speed differences when necessary). However, our Arduino IDE add-on includes support for the new features on the ATmega328PB, making them easier to use from the Arduino environment and allowing the A-Star 328PB to be an upgrade from ATmega328P-based boards.

Our add-on was written for and tested with version 1.8.5 of the Arduino software. Since that version of the IDE does not have official ATmega328PB support, the add-on configures the compiler to target the older ATmega328P, which is very similar to the PB, and provides extra definitions so you can use all of the new features of the ATmega328PB.

Here are some details about what Arduino features work when programming the A-Star 328PB in the Arduino IDE:

  • The Serial and Serial1 objects both work, providing access to USART0 and USART1, respectively.
  • There is no library support for accessing the ATmega328PB’s second I2C module (TWI1), or its second SPI module (SPI1). However, you can access the registers for those new modules and define ISRs for them.
  • pinMode, digitalRead, and digitalWrite should work on every I/O pin (including A6, A7, SDA1, and SCL1).
  • analogRead should work on every analog pin (A0 through A7).
  • analogWrite should work on every pin with PWM (including 0, 1, and 2).

The ATmega328PB has two new pins, PE0 and PE1, that have no equivalent on the ATmega328P. These pins do not yet have official pin numbers in the Arduino environment, so if you need to use their pin numbers in your code, we recommend using the constants SDA1 (for PE0) and SCL1 (for PE1) that are defined in our header files (instead of using the pin numbers 22 and 23 that we have provisionally assigned). For example:

digitalWrite(SDA1, HIGH);

“Upload Using Programmer”

The Arduino IDE provides the ability to upload a sketch to a board using AVR in-system programming (with a programmer connected to the 2×3 ISP header). This is done by selecting the Upload Using Programmer command in the Sketch menu.

If you want to program the A-Star 328PB with this method, you will not be able to use the default programmers listed under the Tools > Programmer menu, since the software toolchain used with these programmers does not recognize the ATmega328PB. However, our Arduino add-on inserts a new entry in the Programmer menu, STK500 for Pololu A-Star 328PB, which you can select when using the Pololu USB AVR Programmer v2.1 (or another STK500-compatible AVR ISP programmer) for in-system programming of the A-Star 328PB.

Related Products

A-Star 328PB Micro - 5V, 16MHz
A-Star 328PB Micro - 5V, 20MHz
A-Star 328PB Micro - 3.3V, 8MHz
A-Star 328PB Micro - 3.3V, 12MHz
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Menu
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors