Hi!
Has anyone managed to get a rotary encoder to work with a Nano Every?
Up to now I have been successfully using a standard Nano with interrupts and the encoder A and B pins connected to Nano pins 2 and 3. The Every gives several errors similar to
error: 'PCICR' was not declared in this scope
PCICR |= (1 << PCIE2);
during compilation because of the PCICR and PCIE2 etc.
Any help would be greatly appreciated 
The relevant part of the code which works on the standard Nano is
// Include the rotary encoder library
#include <rotary.h>
// Arduino pins the encoder is attached to. Attach the center to ground.
#define ROTARY_PIN1 3
#define ROTARY_PIN2 2
// define to enable weak pullups.
#define ENABLE_PULLUPS
#define DIR_CCW 0x10
#define DIR_CW 0x20
Rotary r = Rotary(ROTARY_PIN1, ROTARY_PIN2);/* Call this once in setup(). */
void rotary_init() {
 pinMode(ROTARY_PIN1, INPUT);
 pinMode(ROTARY_PIN2, INPUT);
#ifdef ENABLE_PULLUPS
 digitalWrite(ROTARY_PIN1, HIGH);
 digitalWrite(ROTARY_PIN2, HIGH);
#endif
}
unsigned char rotary_iresult; // This is set by the interrupt routine to indicate the direction of rotation (DIR_CW or DIR_CCW) of the encoder (or 0 if not rotated)
// This is the interrupt service routine - must return as quickly as possible
ISR(PCINT2_vect) {
 unsigned char result = r.process();
 if (result) {
  // Serial.println(result == DIR_CW ? "Right" : "Left");
  rotary_iresult = result;
 }
}
// Set up for the rotary encoder interrupts
 PCICR |= (1 << PCIE2);
 PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
 sei();
 rotary_init();
The ATmega4809 microcontroller in the Every has a different pin change interrupt structure than the ATmega328P in the Uno/Nano. So the rotary encoder library you are using would have to be modified or rewritten for this. Basically, pins 2 and 3 are ports PA0 and PF5 on the microcontroller. Each port has a PINnCTRL register for each pin which has a field to set the edge to cause an interrupt. The port's INTFLAGS register has the interrupt flags that must be cleared in an interrupt. Each port has an interrupt vector such as PORTA_PORT_vect for port A. It isn't the easiest rewrite but it is straightforward if you understand the microcontrollers.
Thanks for the information. Sounds like I need to dig into the 554 page ATmega4809 datasheet a bit more
:o
Do you think that attachInterrupt (digitalPinToInterrupt (2), isr, CHANGE);
would work if I have an interrupt service routine (isr) that would read and interpret the encoder pins correctly?
I'd prefer to avoid messing around in the rotary library!
By the way, good luck with your new book
I'm starting to get to grips with the various ports and interrupts on the Nano Every (ATmega4809 chip) but it seems that the Every designers have made a few odd design decisions for a board that is supposed to be 'pin-compatible' with the original Nano (ATmega328 chip).
If I've done my research correctly, the D2 and D3 pins on the Nano Every are mapped to PA0 and PF5 so they are on different ports (PORTA and PORTF respectively), hence they will fire different interrupts when triggered by changes on the D2 and D3 pins: PORTA_PORT_vect in the case of a change on D2 and PORTF_PORT_vect for a change on D3.
I think this means a single ISR cannot be used, rather, I would need one ISR for each interrupt vector?
On the original Nano, pin D2 is PD2 and pin D3 is PD3 so both pins are on the same port, PORTD, so will fire the same interrupt PCINT2_vect. With my rotary encoder A and B pins connected to D2 and D3 a single ISR (PCINT2_vect) will catch either of the pins changing and my encoder is read quickly and correctly.
I chose D2 and D3 on the original Nano because, correct me if I'm wrong, they are the only two pins that support external interrupts?
I can probably change my hardware design for the Nano Every so it uses two pins on the same port (all digital pins on the Every are capable of external interrupts) but I would have preferred a drop-in solution to using the Nano Every instead of the regular Nano, because of the larger memory of the new board.
Ah well, back to work 
I now have my rotary encoder working on both the original Nano and the new Nano Every. For the Nano Every you do need two ISR functions if you want to use the 'normal' D2 and D3 pins. As I explained above, on the Every these pins are on different ports (PORTA and PORTF respectively) so will trigger different interrupts on vectors PORTA_PORT_vect and PORTF_PORT_vect, respectively.
Many thanks to Tom Almy @almytom for nudging me in the right direction. 
In this code snippet I detect the board type (ARDUINO_AVR_NANO_EVERY for the Nano Every) and conditionally compile the interrupt registers and ISR routines.
// Include the rotary encoder library
#include <rotary.h>
// Arduino pins the encoder is attached to. Attach the center to ground.
#define ROTARY_PIN1 3
#define ROTARY_PIN2 2
// define to enable weak pullups.
#define ENABLE_PULLUPS
#define DIR_CCW 0x10
#define DIR_CW 0x20
Rotary r = Rotary(ROTARY_PIN1, ROTARY_PIN2);
#define Nano 0
#define Every 1
#define Uno 2
#if defined(ARDUINO_AVR_NANO)
#define _BOARDTYPE Nano
#endif
#if defined(ARDUINO_AVR_NANO_EVERY)
#define _BOARDTYPE Every
#endif
#if defined (ARDUINO_AVR_UNO)
#define _BOARDTYPE Uno
#endif
volatile unsigned char rotary_iresult; // This is set by the interrupt routine to indicate the direction of rotation (DIR_CW or DIR_CCW) of the encoder (or 0 if not rotated)
// This is the interrupt service routine - must return as quickly as possible
#if _BOARDTYPE != Every
ISR(PCINT2_vect) {
 unsigned char result = r.process();
 if (result)
  rotary_iresult = result;
}
#else
#define PA0_INTERRUPT PORTA.INTFLAGS & PIN0_bm
#define PA0_CLEAR_INTERRUPT_FLAG PORTA.INTFLAGS &= PIN0_bm
#define PF5_INTERRUPT PORTF.INTFLAGS & PIN5_bm
#define PF5_CLEAR_INTERRUPT_FLAG PORTF.INTFLAGS &= PIN5_bm
ISR(PORTA_PORT_vect) {
 unsigned char result = r.process();
 if (PA0_INTERRUPT)
  PA0_CLEAR_INTERRUPT_FLAG;
 if (result)Â
  rotary_iresult = result;
}
ISR(PORTF_PORT_vect) {
 unsigned char result = r.process();
 if (PF5_INTERRUPT)
  PF5_CLEAR_INTERRUPT_FLAG;
 if (result)
  rotary_iresult = result;
}
#endif
 // Set up for the rotary encoder interrupts
#if _BOARDTYPE != Every
 PCICR |= (1 << PCIE2);
 PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
#endif
 sei();
#if _BOARDTYPE == Every
 PORTA.PIN0CTRL |= PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc;
 PORTF.PIN5CTRL |= PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc;
#endif
Glad you figured it out! It would be a much better product if they didn't try to force "compatibility" when it really isn't. The ATmega4809 is a superior microcontroller in most every way, and they decided to hold it back to make it "compatible". Since the design of the Wiring Library is to make the actual microcontroller pin assignment irrelevant to the user, they could take every liberty in laying out the board! As long as the got the PWM, SPI, and I2C pins in compatible places they were happy, I guess.