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:
Serial1objects 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.
digitalWriteshould work on every I/O pin (including A6, A7, SDA1, and SCL1).
analogReadshould work on every analog pin (A0 through A7).
analogWriteshould 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:
“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.