Interrupts no information in official documents

I am trying to get a Rotary Encoder encoder to work on the Nano R4 processor. However, in all the official documents I can not see (or find with a search) any mention of interrupts.

However, when I download the User Manual Hardware direct from the Reneas Web site I find there are 132 pages that mention them.

I conclude that the official documentation from Arduino is totally inadequate, in this regard at least.

Comments please.

For interrupts take a look at the IRQManager

For encoder you might take a look at

Well at least a third of it is not in Chinese like the Nano 328P one!
(Perhaps someone needs to finish the translation?)

I think the "datasheet" on the Arduino site is a datasheet for the board, whereas the one on the Renesas site is the datasheet for the actual MCU. Likely the Arduino one tells you about the board itself, but if you want to dig deeper then you have to go find the MCU manufacturer datasheet for the specific MCU. One is probably meant to look at both in conjunction with each other. Hopefully someone will clarify.

FYI.
I used the library EncoderButton with a NANO, and it worked well. Although some comments in the code mention interrupts, I looked through the library code and do not see any use of interrupts. I have not tested with the NANO R4.

Can you use any information about interrupts that is available for the Uno R4 Minima board ?

Uno R4 boards are based on the Arm® Cortex®-M4 core (Armv7E-M architecture profile) try to check in side **Cortex™-M4 Devices Generic User Guide**

Unfortunately, Renesas put their own weird interrupt system (the ICU) on top of what is essentially a CM0-style NVIC (32 vectors worth.) The ICU arbitrarily multiplexes close to 200 possible "Events" onto the 32 NVIC vectors.

So "attaching" an interrupt to an event is more complicated than a basic M4 NVIC configuration - basically you have to find a free NVIC slot, and then set up the ICU to bind that slot to the desired event.

I believe that the Arduino void attachInterrupt(pin_size_t pinNumber, voidFuncPtr func, PinStatus mode) does all of this, for pins on which interrupts are permitted. Except that I'm not sure which pins those are, since it looks like the Renesas "core" was written by ... someone at Renesas? It's dramatically different than any of the other ARM cores (and ugly, IMO. With a lot of confusing indirection.)

I wrote this test sketch, which I think will tell you which pins can be used in attachInterrupt():

void setup() {
  Serial.begin(9600);
  while (!Serial)
    ;
  Serial.println("Check interrupt channels");
}

/*
 * function copied from cores/arduino/Interrupts.cpp
 */
static int pin2IrqChannel(int pin) {
  /* -------------------------------------------------------------------------- */
  /* verify index are good */
  if (pin < 0 || pin >= PINS_COUNT) {
    return -1;
  }
  /* getting configuration from table */
  auto cfg_irq = getPinCfgs(pin, PIN_CFG_REQ_INTERRUPT);

  /* verify configuration are good */
  if (cfg_irq[0] == 0) {
    return -1;
  }
  return GET_CHANNEL(cfg_irq[0]);
}

char buf[80];

void loop() {
  for (int i = 0; i < 20; i++) {
    sprintf(buf, "Pin %d channel %d\n", i, pin2IrqChannel(i));
    Serial.print(buf);
  }
  while (1) {
  }
}

On my R4 Nano, it shows:

Check interrupt channels
Pin 0 channel 6
Pin 1 channel 5
Pin 2 channel 0
Pin 3 channel 1
Pin 4 channel -1
Pin 5 channel -1
Pin 6 channel -1
Pin 7 channel -1
Pin 8 channel 9
Pin 9 channel -1
Pin 10 channel -1
Pin 11 channel -1
Pin 12 channel 3
Pin 13 channel 4
Pin 14 channel -1
Pin 15 channel 6
Pin 16 channel 7
Pin 17 channel 2
Pin 18 channel 1
Pin 19 channel 2

(the -1 lines are "not allowed")

Oh! I see. This data is in ...variants/*/pinmux.inc ! My tools didn't see it since it doesn't have a usual source-file extension... (IDE 2 can't find it either.)

I am very disappointed that no Arduino Team member has not made a comment on this point. As I see this as a major fault with the documentation. When I try and run code on the Nano R4 board I get this

FQBN: arduino:renesas_uno:nanor4
Using board 'nanor4' from platform in folder: /Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1
Using core 'arduino' from platform in folder: /Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1

Detecting libraries used...
/Users/mikecook/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=48000000 -DARDUINO_NANO_R4 -DARDUINO_UNOR4_MINIMA -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="/Users/mikecook/Library/Caches/arduino/sketches/ABDA15FD3C58E87685BEA9EBF8C976BD/Basic.ino" -DARDUINO_nanor4 -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/defines.txt -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/tinyusb -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated-avr-comp -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4 -iprefix/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1 @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/includes.txt /Users/mikecook/Library/Caches/arduino/sketches/ABDA15FD3C58E87685BEA9EBF8C976BD/sketch/Basic.ino.cpp -o /dev/null
Alternatives for Encoder.h: [Encoder@1.4.4]
ResolveLibrary(Encoder.h)
  -> candidates: [Encoder@1.4.4]
/Users/mikecook/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=48000000 -DARDUINO_NANO_R4 -DARDUINO_UNOR4_MINIMA -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="/Users/mikecook/Library/Caches/arduino/sketches/ABDA15FD3C58E87685BEA9EBF8C976BD/Basic.ino" -DARDUINO_nanor4 -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/defines.txt -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/tinyusb -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated-avr-comp -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4 -I/Users/mikecook/Documents/Arduino/libraries/Encoder -iprefix/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1 @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/includes.txt /Users/mikecook/Library/Caches/arduino/sketches/ABDA15FD3C58E87685BEA9EBF8C976BD/sketch/Basic.ino.cpp -o /dev/null
Error while detecting libraries included by /Users/mikecook/Library/Caches/arduino/sketches/ABDA15FD3C58E87685BEA9EBF8C976BD/sketch/Basic.ino.cpp
/Users/mikecook/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=48000000 -DARDUINO_NANO_R4 -DARDUINO_UNOR4_MINIMA -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="/Users/mikecook/Library/Caches/arduino/sketches/ABDA15FD3C58E87685BEA9EBF8C976BD/Basic.ino" -DARDUINO_nanor4 -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/defines.txt -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/tinyusb -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated-avr-comp -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4 -I/Users/mikecook/Documents/Arduino/libraries/Encoder -I/Users/mikecook/Documents/Arduino/libraries/Encoder/utility -iprefix/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1 @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/includes.txt /Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.cpp -o /dev/null
Error while detecting libraries included by /Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.cpp
Generating function prototypes...
/Users/mikecook/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=48000000 -DARDUINO_NANO_R4 -DARDUINO_UNOR4_MINIMA -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="/Users/mikecook/Library/Caches/arduino/sketches/ABDA15FD3C58E87685BEA9EBF8C976BD/Basic.ino" -DARDUINO_nanor4 -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/defines.txt -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/tinyusb -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated-avr-comp -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4 -I/Users/mikecook/Documents/Arduino/libraries/Encoder -iprefix/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1 @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/includes.txt /Users/mikecook/Library/Caches/arduino/sketches/ABDA15FD3C58E87685BEA9EBF8C976BD/sketch/Basic.ino.cpp -o /private/var/folders/0r/5d65776n19q2wvp1wf4bjsxr0000gn/T/1381402581/sketch_merged.cpp
In file included from /Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:46:0,
                 from /Users/mikecook/Documents/Arduino/Nano  A4 software/Encoder/examples/Basic/Basic.ino:7:
/Users/mikecook/Documents/Arduino/libraries/Encoder/utility/interrupt_pins.h:390:2: error: #error "Interrupts are unknown for this board, please add to this code"
 #error "Interrupts are unknown for this board, please add to this code"
  ^~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/utility/interrupt_pins.h:393:2: error: #error "Encoder requires interrupt pins, but this board does not have any :("
 #error "Encoder requires interrupt pins, but this board does not have any :("
  ^~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/utility/interrupt_pins.h:394:2: error: #error "You could try defining ENCODER_DO_NOT_USE_INTERRUPTS as a kludge."
 #error "You could try defining ENCODER_DO_NOT_USE_INTERRUPTS as a kludge."
  ^~~~~
exit status 1

Compilation error: exit status 1

Can I remind all posters that this is a "Nano R4 board" I am talking about and not any other sort of of Uno R4 board.

I am setting up some new hardware to continue to test this out further.

More accurately, this is what you get when you try to use the 3rd party "Encoder" library. You will not get this error when compiling any code that does not use the Encoder library

The 3rd party Encoder library has architecture-specific code, so explicit support for each board architecture must be added to the library, rather than happening as a matter of course as occurs for libraries that only use the high level universal Arduino core API.

Support for the Renesas RA4M1-based UNO R4 Minima and UNO R4 WiFi boards has apparently already been added to the library:

So hopefully that indicates the addition of support to the library for the Nano R4 will be trivial.

Thanks for that. I will try it later. In the meantime I came across this in the documentation:-

This does not appear in any search I do. As you can see it defines pins 2 and 3 as external interrupts as Special Features. So how do I enable those special features?

AttachInterrupt() should do it, just like on any other Arduino...

yeah, Paul (of PJRC; author of the encoder library) writes nice, efficient, and clever code, but seems to be a bit careless about the idea of "easily portable/compatible to/with new platforms.") The interrupt code in the encoder library is ... really ugly.

I came across this in the documentation

Those are just the "normal" Arduino functions for those pins, aren't they? The Nano changes the form factor, but generally keeps most of the same functions on the same "Arduino pin numbers" as an Uno-like board...

Sorry but I cannot "see" this. It might be trivial but I am too much of a hardware guy to see this.

It shows up here:

(but that's the "live" trunk, not the most recently released library.)

From my previous test sketch, that probably means you can change it like so:

#elif defined(ARDUINO_UNOR4_MINIMA) || defined(ARDUINO_NANO_R4)
          //0, 1, 2, 3, 8, 12, 13, 15, 16, 17, 18 and 19.
            #define CORE_NUM_INTERRUPT	20
            #define CORE_INT0_PIN		0
            #define CORE_INT1_PIN		1
            #define CORE_INT2_PIN		2
            #define CORE_INT3_PIN		3
            #define CORE_INT8_PIN		8
            #define CORE_INT12_PIN	12
            #define CORE_INT13_PIN	13
            #define CORE_INT15_PIN	15
            #define CORE_INT16_PIN	16
            #define CORE_INT17_PIN	17
            #define CORE_INT18_PIN	18
            #define CORE_INT19_PIN	19

Is what library are we talking about here?

The “encoder” library.

So I got the latest version Encoder-1.4.4
I selected the No interrupts version and got the following error message:-

FQBN: arduino:renesas_uno:nanor4
Using board 'nanor4' from platform in folder: /Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1
Using core 'arduino' from platform in folder: /Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1

Detecting libraries used...
/Users/mikecook/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=48000000 -DARDUINO_NANO_R4 -DARDUINO_UNOR4_MINIMA -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="/Users/mikecook/Library/Caches/arduino/sketches/D1F7950AB046945C064EC94CC24E73FE/NoInterrupts.ino" -DARDUINO_nanor4 -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/defines.txt -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/tinyusb -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated-avr-comp -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4 -iprefix/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1 @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/includes.txt /Users/mikecook/Library/Caches/arduino/sketches/D1F7950AB046945C064EC94CC24E73FE/sketch/NoInterrupts.ino.cpp -o /dev/null
Alternatives for Encoder.h: [Encoder@1.4.4]
ResolveLibrary(Encoder.h)
  -> candidates: [Encoder@1.4.4]
/Users/mikecook/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=48000000 -DARDUINO_NANO_R4 -DARDUINO_UNOR4_MINIMA -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="/Users/mikecook/Library/Caches/arduino/sketches/D1F7950AB046945C064EC94CC24E73FE/NoInterrupts.ino" -DARDUINO_nanor4 -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/defines.txt -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/tinyusb -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated-avr-comp -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4 -I/Users/mikecook/Documents/Arduino/libraries/Encoder -iprefix/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1 @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/includes.txt /Users/mikecook/Library/Caches/arduino/sketches/D1F7950AB046945C064EC94CC24E73FE/sketch/NoInterrupts.ino.cpp -o /dev/null
/Users/mikecook/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=48000000 -DARDUINO_NANO_R4 -DARDUINO_UNOR4_MINIMA -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="/Users/mikecook/Library/Caches/arduino/sketches/D1F7950AB046945C064EC94CC24E73FE/NoInterrupts.ino" -DARDUINO_nanor4 -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/defines.txt -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/tinyusb -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated-avr-comp -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4 -I/Users/mikecook/Documents/Arduino/libraries/Encoder -I/Users/mikecook/Documents/Arduino/libraries/Encoder/utility -iprefix/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1 @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/includes.txt /Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.cpp -o /dev/null
Error while detecting libraries included by /Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.cpp
Generating function prototypes...
/Users/mikecook/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -w -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -nostdlib -DF_CPU=48000000 -DARDUINO_NANO_R4 -DARDUINO_UNOR4_MINIMA -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -w -x c++ -E -CC -DARDUINO=10607 -DPROJECT_NAME="/Users/mikecook/Library/Caches/arduino/sketches/D1F7950AB046945C064EC94CC24E73FE/NoInterrupts.ino" -DARDUINO_nanor4 -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/defines.txt -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/tinyusb -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated-avr-comp -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4 -I/Users/mikecook/Documents/Arduino/libraries/Encoder -iprefix/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1 @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/includes.txt /Users/mikecook/Library/Caches/arduino/sketches/D1F7950AB046945C064EC94CC24E73FE/sketch/NoInterrupts.ino.cpp -o /private/var/folders/0r/5d65776n19q2wvp1wf4bjsxr0000gn/T/1143218653/sketch_merged.cpp
/Users/mikecook/Library/Arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /private/var/folders/0r/5d65776n19q2wvp1wf4bjsxr0000gn/T/1143218653/sketch_merged.cpp

Compiling sketch...
/Users/mikecook/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -Wall -Wextra -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -MMD -nostdlib -DF_CPU=48000000 -DARDUINO_NANO_R4 -DARDUINO_UNOR4_MINIMA -MMD -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -DARDUINO=10607 "-DPROJECT_NAME=\"/Users/mikecook/Library/Caches/arduino/sketches/D1F7950AB046945C064EC94CC24E73FE/NoInterrupts.ino\"" -DARDUINO_nanor4 -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/defines.txt -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/tinyusb -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino/api/deprecated-avr-comp -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/cores/arduino -I/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4 -I/Users/mikecook/Documents/Arduino/libraries/Encoder -iprefix/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1 @/Users/mikecook/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.5.1/variants/NANOR4/includes.txt /Users/mikecook/Library/Caches/arduino/sketches/D1F7950AB046945C064EC94CC24E73FE/sketch/NoInterrupts.ino.cpp -o /Users/mikecook/Library/Caches/arduino/sketches/D1F7950AB046945C064EC94CC24E73FE/sketch/NoInterrupts.ino.cpp.o
In file included from /Users/mikecook/Desktop/Encoder-1.4.4/examples/NoInterrupts/NoInterrupts.ino:14:0:
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:68:11: error: 'IO_REG_TYPE' does not name a type
  volatile IO_REG_TYPE * pin1_register;
           ^~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:69:11: error: 'IO_REG_TYPE' does not name a type
  volatile IO_REG_TYPE * pin2_register;
           ^~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:70:2: error: 'IO_REG_TYPE' does not name a type
  IO_REG_TYPE            pin1_bitmask;
  ^~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:71:2: error: 'IO_REG_TYPE' does not name a type
  IO_REG_TYPE            pin2_bitmask;
  ^~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h: In constructor 'Encoder::Encoder(uint8_t, uint8_t)':
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:89:11: error: 'struct Encoder_internal_state_t' has no member named 'pin1_register'
   encoder.pin1_register = PIN_TO_BASEREG(pin1);
           ^~~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:89:27: error: 'PIN_TO_BASEREG' was not declared in this scope
   encoder.pin1_register = PIN_TO_BASEREG(pin1);
                           ^~~~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:89:27: note: suggested alternative: 'ITM_BASE'
   encoder.pin1_register = PIN_TO_BASEREG(pin1);
                           ^~~~~~~~~~~~~~
                           ITM_BASE
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:90:11: error: 'struct Encoder_internal_state_t' has no member named 'pin1_bitmask'
   encoder.pin1_bitmask = PIN_TO_BITMASK(pin1);
           ^~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:90:26: error: 'PIN_TO_BITMASK' was not declared in this scope
   encoder.pin1_bitmask = PIN_TO_BITMASK(pin1);
                          ^~~~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:90:26: note: suggested alternative: 'PIN_USE_MASK'
   encoder.pin1_bitmask = PIN_TO_BITMASK(pin1);
                          ^~~~~~~~~~~~~~
                          PIN_USE_MASK
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:91:11: error: 'struct Encoder_internal_state_t' has no member named 'pin2_register'
   encoder.pin2_register = PIN_TO_BASEREG(pin2);
           ^~~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:92:11: error: 'struct Encoder_internal_state_t' has no member named 'pin2_bitmask'
   encoder.pin2_bitmask = PIN_TO_BITMASK(pin2);
           ^~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:99:31: error: 'struct Encoder_internal_state_t' has no member named 'pin1_register'
   if (DIRECT_PIN_READ(encoder.pin1_register, encoder.pin1_bitmask)) s |= 1;
                               ^~~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:99:54: error: 'struct Encoder_internal_state_t' has no member named 'pin1_bitmask'
   if (DIRECT_PIN_READ(encoder.pin1_register, encoder.pin1_bitmask)) s |= 1;
                                                      ^~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:99:7: error: 'DIRECT_PIN_READ' was not declared in this scope
   if (DIRECT_PIN_READ(encoder.pin1_register, encoder.pin1_bitmask)) s |= 1;
       ^~~~~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:100:31: error: 'struct Encoder_internal_state_t' has no member named 'pin2_register'
   if (DIRECT_PIN_READ(encoder.pin2_register, encoder.pin2_bitmask)) s |= 2;
                               ^~~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:100:54: error: 'struct Encoder_internal_state_t' has no member named 'pin2_bitmask'
   if (DIRECT_PIN_READ(encoder.pin2_register, encoder.pin2_bitmask)) s |= 2;
                                                      ^~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:100:7: error: 'DIRECT_PIN_READ' was not declared in this scope
   if (DIRECT_PIN_READ(encoder.pin2_register, encoder.pin2_bitmask)) s |= 2;
       ^~~~~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h: In static member function 'static void Encoder::update(Encoder_internal_state_t*)':
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:303:40: error: 'struct Encoder_internal_state_t' has no member named 'pin1_register'
   uint8_t p1val = DIRECT_PIN_READ(arg->pin1_register, arg->pin1_bitmask);
                                        ^~~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:303:60: error: 'struct Encoder_internal_state_t' has no member named 'pin1_bitmask'
   uint8_t p1val = DIRECT_PIN_READ(arg->pin1_register, arg->pin1_bitmask);
                                                            ^~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:303:19: error: 'DIRECT_PIN_READ' was not declared in this scope
   uint8_t p1val = DIRECT_PIN_READ(arg->pin1_register, arg->pin1_bitmask);
                   ^~~~~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:304:40: error: 'struct Encoder_internal_state_t' has no member named 'pin2_register'
   uint8_t p2val = DIRECT_PIN_READ(arg->pin2_register, arg->pin2_bitmask);
                                        ^~~~~~~~~~~~~
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:304:60: error: 'struct Encoder_internal_state_t' has no member named 'pin2_bitmask'
   uint8_t p2val = DIRECT_PIN_READ(arg->pin2_register, arg->pin2_bitmask);
                                                            ^~~~~~~~~~~~
Using library Encoder at version 1.4.4 in folder: /Users/mikecook/Documents/Arduino/libraries/Encoder 
exit status 1

Compilation error: exit status 1

Any more suggestions?

OK I have made some progress. First I. updated my Mac Software ti the latest MacOS Sequola 15.6.1. Next I permitted access to Discourse to allow it to access my computer for updates, Finally I ran the NoInterrupts code again and got this error message when I tried to compile it.

Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:76:7: warning: type 'struct Encoder' violates the C++ One Definition Rule [-Wodr]
 class Encoder
       ^
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:76:7: note: a different type is defined in another translation unit
 class Encoder
       ^
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:157:10: note: the first difference of corresponding definitions is field 'interrupts_in_use'
  uint8_t interrupts_in_use;
          ^
/Users/mikecook/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /var/folders/0r/5d65776n19q2wvp1wf4bjsxr0000gn/T/arduino_build_486633/NoInterrupts.ino.elf /var/folders/0r/5d65776n19q2wvp1wf4bjsxr0000gn/T/arduino_build_486633/NoInterrupts.ino.eep
/Users/mikecook/Documents/Arduino/libraries/Encoder/Encoder.h:76:7: note: a type with different number of fields is defined in another translation unit
 class Encoder
       ^

Any other comments other than I told you his code was not very good and portable?

The version 1.4.4 of encoder.h available in the Arduino library manager does not appear to match the current version of encoder.h in github Encoder/Encoder.h at master · PaulStoffregen/Encoder · GitHub (as I now see @westfw has already pointed out). Changes were introduced on 13.03.2024 in the Github repository including several lines for the UNO R4 WIFI and Minima which are not present in the library manager version. Change details: pin register · PaulStoffregen/Encoder@063b390 · GitHub

EDIT
See issue report: Arduino UNO R4 MINIMA not supported · Issue #98 · PaulStoffregen/Encoder · GitHub

Hi @Grumpy_Mike these are the changes that I would expect to add compatibility for the Nano R4:

--- a/utility/direct_pin_read.h
+++ b/utility/direct_pin_read.h
@@ -110,7 +110,7 @@ IO_REG_TYPE directRead(volatile IO_REG_TYPE *base, IO_REG_TYPE pin)
 }
 #define DIRECT_PIN_READ(base, pin)      directRead(base, pin)
 
-#elif defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_UNOR4_MINIMA) /*Arduino UnoR4 */
+#elif defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_UNOR4_MINIMA) || defined(ARDUINO_NANO_R4) /*Arduino UnoR4 */
 
 #define IO_REG_TYPE                    uint32_t
 #define PIN_TO_BASEREG(pin)             (volatile uint32_t*)(portInputRegister(digitalPinToPort(pin)))
diff --git a/utility/interrupt_pins.h b/utility/interrupt_pins.h
index 097b57b..09fef33 100644
--- a/utility/interrupt_pins.h
+++ b/utility/interrupt_pins.h
@@ -385,7 +385,7 @@
   // #define CORE_INT21_PIN    A7
 
 // Arduino Uno R4
-#elif defined(ARDUINO_UNOR4_MINIMA)
+#elif defined(ARDUINO_UNOR4_MINIMA) || defined(ARDUINO_NANO_R4)
 //0, 1, 2, 3, 8, 12, 13, 15, 16, 17, 18 and 19.
   #define CORE_NUM_INTERRUPT   20
   #define CORE_INT0_PIN                0

I'll provide you with a copy of the library that already has the necessary changes. Please do this:

A. Remove existing installation

  1. Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus to open the "Library Manager" view in the left side panel.
  2. Type Encoder in the "Filter your search..." field.
  3. Find the "Encoder" entry in the list of search results.
  4. Hover the mouse pointer over the "Encoder" entry.
  5. You will see a ●●● icon appear near the top right corner of the library entry. Click on that icon.
    A context menu will open.
  6. Select "Remove" from the menu.
    An "Uninstall" dialog will open.
  7. Click the "YES" button in the "Uninstall" dialog to confirm that you want to uninstall the library.
    The dialog will close.
  8. Wait for the uninstall process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    ⓘ Successfully uninstalled library ...

B. Install variant of library with Nano R4 support

  1. Click the following link to download the variant of the library that has the changes I described above:
    Encoder.zip (18.4 KB)
  2. Wait for the download to finish.
  3. Select Sketch > Include library > Add .ZIP Library from the Arduino IDE menus.
    The "Select the zip file containing the library you'd like to add" dialog will open.
  4. Select the downloaded file from the dialog.
  5. Click the "Open" button.
    The dialog will close.
  6. Wait for the installation process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    ⓘ Successfully installed library from ...

C. Perform test

  1. Create a sketch with the following code:
    #include <Encoder.h>
    
    Encoder myEnc;
    
    void setup() {
      Serial.begin(9600);
      Serial.println("Basic Encoder Test:");
      myEnc.begin(5, 6);
    }
    
    long oldPosition  = -999;
    
    void loop() {
      long newPosition = myEnc.read();
      if (newPosition != oldPosition) {
        oldPosition = newPosition;
        Serial.println(newPosition);
      }
    }
    
  2. If your encoder is connected to pins other than 5 and 6, adjust the arguments in the begin call on line 8 in the sketch accordingly. For example, if you encoder was connected to pins 2 and 3, you would change the code from:
    myEnc.begin(5, 6);
    
    to this:
    myEnc.begin(2, 3);
    
  3. Upload the sketch to your Nano R4 board.
  4. Wait for the upload to finish successfully.
  5. Open Serial Monitor.
  6. Rotate the encoder.

We would now expect to see numbers printed to Serial Monitor, incrementing or decrementing depending on which direction you turn the encoder.

I don't have access to a Nano R4, but it does work as expected for me with the similar UNO R4 Minima board.


Please let us know if you have any questions or problems while following those instructions, just let us know and we'll provide further assistance.