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
- Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus to open the "Library Manager" view in the left side panel.
- Type
Encoderin the "Filter your search..." field. - Find the "Encoder" entry in the list of search results.
- Hover the mouse pointer over the "Encoder" entry.
- You will see a ●●● icon appear near the top right corner of the library entry. Click on that icon.
A context menu will open. - Select "Remove" from the menu.
An "Uninstall" dialog will open. - Click the "YES" button in the "Uninstall" dialog to confirm that you want to uninstall the library.
The dialog will close. - 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
- Click the following link to download the variant of the library that has the changes I described above:
Encoder.zip (18.4 KB) - Wait for the download to finish.
- 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. - Select the downloaded file from the dialog.
- Click the "Open" button.
The dialog will close. - 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
- 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); } } - If your encoder is connected to pins other than 5 and 6, adjust the arguments in the
begincall 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:
to this:myEnc.begin(5, 6);myEnc.begin(2, 3); - Upload the sketch to your Nano R4 board.
- Wait for the upload to finish successfully.
- Open Serial Monitor.
- 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.