Compiler errors with Artisan sketch when upgrading from Arduino Uno R3 to Arduino Uno Wifi Rev2

I recently upgraded from my Arduino Uno R3 to the Arduino Uno Wifi Rev2, since I need BLE. I love the new board however...

Compiling the Artisan Scope sketch fails, which works fine on R3. It looks like some registers are not getting found. I have the latest version of Arduino software, have selected the board, and also enabled emulation.

These are the errors I am getting. Can anyone help?

In file included from /Users/glennblock/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/io.h:99:0,
                 from /Users/glennblock/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/pgmspace.h:90,
                 from /Users/glennblock/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/api/String.h:31,
                 from /Users/glennblock/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/api/IPAddress.h:24,
                 from /Users/glennblock/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/api/ArduinoAPI.h:30,
                 from /Users/glennblock/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/Arduino.h:23,
                 from /private/var/folders/39/yvhx0xzs24q9zflq0gv3rg5m0000gn/T/arduino-sketch-07A73615FFD23AAAE8DE924AF542AE67/sketch/aArtisanQ_PID.ino.cpp:1:
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:156:25: error: 'COM2A1' was not declared in this scope
 #define IO3_FASTPWM _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20) // fast PWM
                         ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:31: note: in expansion of macro 'IO3_FASTPWM'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                               ^~~~~~~~~~~
In file included from /Users/glennblock/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/io.h:99:0,
                 from /Users/glennblock/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/pgmspace.h:90,
                 from /Users/glennblock/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/api/String.h:31,
                 from /Users/glennblock/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/api/IPAddress.h:24,
                 from /Users/glennblock/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/api/ArduinoAPI.h:30,
                 from /Users/glennblock/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/Arduino.h:23,
                 from /Users/glennblock/src/TC4-shield/applications/Artisan/aArtisan_PID/trunk/src/aArtisanQ_PID/cmndproc.h:56,
                 from /Users/glennblock/src/TC4-shield/applications/Artisan/aArtisan_PID/trunk/src/aArtisanQ_PID/cmndreader.h:43,
                 from /Users/glennblock/src/TC4-shield/applications/Artisan/aArtisan_PID/trunk/src/aArtisanQ_PID/cmndreader.cpp:40:
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:156:25: error: 'COM2A1' was not declared in this scope
 #define IO3_FASTPWM _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20) // fast PWM
                         ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:31: note: in expansion of macro 'IO3_FASTPWM'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                               ^~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:156:39: error: 'COM2B1' was not declared in this scope
 #define IO3_FASTPWM _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20) // fast PWM
                                       ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:31: note: in expansion of macro 'IO3_FASTPWM'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                               ^~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:156:39: error: 'COM2B1' was not declared in this scope
 #define IO3_FASTPWM _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20) // fast PWM
                                       ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:31: note: in expansion of macro 'IO3_FASTPWM'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                               ^~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:156:53: error: 'WGM21' was not declared in this scope
 #define IO3_FASTPWM _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20) // fast PWM
                                                     ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:31: note: in expansion of macro 'IO3_FASTPWM'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                               ^~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:156:53: error: 'WGM21' was not declared in this scope
 #define IO3_FASTPWM _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20) // fast PWM
                                                     ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:31: note: in expansion of macro 'IO3_FASTPWM'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                               ^~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:156:66: error: 'WGM20' was not declared in this scope
 #define IO3_FASTPWM _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20) // fast PWM
                                                                  ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:31: note: in expansion of macro 'IO3_FASTPWM'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                               ^~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:156:66: error: 'WGM20' was not declared in this scope
 #define IO3_FASTPWM _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20) // fast PWM
                                                                  ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:31: note: in expansion of macro 'IO3_FASTPWM'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                               ^~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:169:31: error: 'CS22' was not declared in this scope
 #define IO3_PRESCALE_1024 _BV(CS22) | _BV(CS21) | _BV(CS20) // 0x07, divide by 1024
                               ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:63: note: in expansion of macro 'IO3_PRESCALE_1024'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                                                               ^~~~~~~~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:169:31: error: 'CS22' was not declared in this scope
 #define IO3_PRESCALE_1024 _BV(CS22) | _BV(CS21) | _BV(CS20) // 0x07, divide by 1024
                               ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:63: note: in expansion of macro 'IO3_PRESCALE_1024'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                                                               ^~~~~~~~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:169:43: error: 'CS21' was not declared in this scope
 #define IO3_PRESCALE_1024 _BV(CS22) | _BV(CS21) | _BV(CS20) // 0x07, divide by 1024
                                           ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:63: note: in expansion of macro 'IO3_PRESCALE_1024'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                                                               ^~~~~~~~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:169:43: error: 'CS21' was not declared in this scope
 #define IO3_PRESCALE_1024 _BV(CS22) | _BV(CS21) | _BV(CS20) // 0x07, divide by 1024
                                           ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:63: note: in expansion of macro 'IO3_PRESCALE_1024'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                                                               ^~~~~~~~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:169:55: error: 'CS20' was not declared in this scope
 #define IO3_PRESCALE_1024 _BV(CS22) | _BV(CS21) | _BV(CS20) // 0x07, divide by 1024
                                                       ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:63: note: in expansion of macro 'IO3_PRESCALE_1024'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                                                               ^~~~~~~~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:169:55: error: 'CS20' was not declared in this scope
 #define IO3_PRESCALE_1024 _BV(CS22) | _BV(CS21) | _BV(CS20) // 0x07, divide by 1024
                                                       ^
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:173:63: note: in expansion of macro 'IO3_PRESCALE_1024'
     void Setup( uint8_t pwm = IO3_FASTPWM, uint8_t prescale = IO3_PRESCALE_1024 );
                                                               ^~~~~~~~~~~~~~~~~
/Users/glennblock/src/TC4-shield/applications/Artisan/aArtisan_PID/trunk/src/aArtisanQ_PID/aArtisanQ_PID.ino: In function 'void setup()':
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:157:25: error: 'COM2A1' was not declared in this scope
 #define IO3_PCORPWM _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20) // phase correct PWM
                         ^
/Users/glennblock/src/TC4-shield/applications/Artisan/aArtisan_PID/trunk/src/aArtisanQ_PID/aArtisanQ_PID.ino:1558:17: note: in expansion of macro 'IO3_PCORPWM'
   pwmio3.Setup( IO3_PCORPWM, IO3_PRESCALE_8 ); // setup pmw frequency ion IO3
                 ^~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:157:39: error: 'COM2B1' was not declared in this scope
 #define IO3_PCORPWM _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20) // phase correct PWM
                                       ^
/Users/glennblock/src/TC4-shield/applications/Artisan/aArtisan_PID/trunk/src/aArtisanQ_PID/aArtisanQ_PID.ino:1558:17: note: in expansion of macro 'IO3_PCORPWM'
   pwmio3.Setup( IO3_PCORPWM, IO3_PRESCALE_8 ); // setup pmw frequency ion IO3
                 ^~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:157:53: error: 'WGM20' was not declared in this scope
 #define IO3_PCORPWM _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20) // phase correct PWM
                                                     ^
/Users/glennblock/src/TC4-shield/applications/Artisan/aArtisan_PID/trunk/src/aArtisanQ_PID/aArtisanQ_PID.ino:1558:17: note: in expansion of macro 'IO3_PCORPWM'
   pwmio3.Setup( IO3_PCORPWM, IO3_PRESCALE_8 ); // setup pmw frequency ion IO3
                 ^~~~~~~~~~~
/Users/glennblock/Documents/Arduino/libraries/PWM16/PWM16.h:164:28: error: 'CS21' was not declared in this scope
 #define IO3_PRESCALE_8 _BV(CS21) // 0x02, divide by 8
                            ^
/Users/glennblock/src/TC4-shield/applications/Artisan/aArtisan_PID/trunk/src/aArtisanQ_PID/aArtisanQ_PID.ino:1558:30: note: in expansion of macro 'IO3_PRESCALE_8'
   pwmio3.Setup( IO3_PCORPWM, IO3_PRESCALE_8 ); // setup pmw frequency ion IO3
                              ^~~~~~~~~~~~~~

exit status 1

Compilation error: exit status 1

The error indicates that the PWM16 library is not compatible with the Uno WiFi Rev2. Things like 'COM2A1' indicate that the library was written with another platform (AVR, not mega AVR) in mind. You can check if there is an updated version of that library.

On this page it says

Compatibility
This board has the Microchip ATmega4809 microcontroller, but thanks to the compatibility layer included in the core, you can run all the sketches made for the UNO's ATmega328P microconntroller on the ATmega4809. You can find more information about the usage of this mode in the Getting Started page of the Arduino UNO WiFi Rev.2.

Did you follow those instructions?

This page says

Actually the ATmega4809 we use on the Uno WiFi R2 and Nano Every is not directly compatible with ATmega328P; however, we’ve implemented a compatibility layer that translates low level register writes without any overhead so the result is that most libraries and sketches, even those accessing directly GPIO registers, will work out of the box.

I noticed it says "most libraries"...

Yes, this is what I meant by emulation is enabled. That uses the compat layer, but it did not work. The errors are with that enabled.

Thank you, yes I am aware that the code is not compatible as the registers have changed. I had hoped the emulation would fix it, but it did not. It's possible some registers are not supported in the layer / I am not sure. I don't know enough about the lower level details.

Is this something to do with roasting coffee beans? It might help if you could share the sketch.

The emulation creates PORTB, PORTC and PORTD as well as DDRB, DDRC and DDRD in a way that is compatible with the original Uno and that is all; it's only related to IO. I think register emulation is a big word for what it actually does.

Yep, it is based on the sketch here:
https://github.com/greencardigan/TC4-shield/tree/master/applications/Artisan/aArtisan_PID/trunk/src/aArtisanQ_PID

Mine has been modified but the same error will happen with this.

Thanks you!

Ahhh, thank you for clarifying. Any idea what my options are?

"big" is a very generous way to describe it. "false advertising" wouldn't be inaccurate! :wink:

It's a big, complex sketch. Fixing it for your board may not be easy...

Try changing

#ifdef PHASE_ANGLE_CONTROL
  // code for integral cycle control and phase angle control
  #include "phase_ctrl.h"
#endif

#include <PWM16.h> // for SSR output

to this

#ifdef PHASE_ANGLE_CONTROL
  // code for integral cycle control and phase angle control
  #include "phase_ctrl.h"
  #include <PWM16.h> // for SSR output
#endif

There's a slim chance it will work...

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