Error using Encoder library with Pi Pico RP2040

Hey there,

I’m trying to include the Encoder library on a Pi Pico and am getting some errors. The latest version of the Encoder library supports the Arduino Nano RP2040 Connect, so I think it should work with the Pi Pico as well, however I’m seeing a series of errors.
First series of errors that I got was related to the definition of interrupts, as follows:

.pio\libdeps\picow\Encoder/utility/interrupt_pins.h:390:2: error: #error “Interrupts are unknown for this board, please add to this code”
390 | #error “Interrupts are unknown for this board, please add to this code”
| ^~~~~
.pio\libdeps\picow\Encoder/utility/interrupt_pins.h:393:2: error: #error “Encoder requires interrupt pins, but this board does not have any :(”
393 | #error “Encoder requires interrupt pins, but this board does not have any :(”

To fix this, I defined a build flag ARDUINO_NANO_RP2040_CONNECT for the Pico.

I thought that would work, however, I started getting a different error then,

C:\Users---------.platformio\packages\framework-arduinopico\cores\rp2040\SerialPIO.cpp:385:19: error: ‘SERIAL3_TX’ was not declared in this scope
Compiling .pio\build\picow\FrameworkArduino\api\Stream.cpp.o
385 | SerialPIO Serial3(SERIAL3_TX, SERIAL3_RX);
| ^~~~~~~~~~
C:\Users-----------.platformio\packages\framework-arduinopico\cores\rp2040\SerialPIO.cpp:385:31: error: ‘SERIAL3_RX’ was not declared in this scope
385 | SerialPIO Serial3(SERIAL3_TX, SERIAL3_RX);

I looked into the SerialPIO.cpp file, and sure enough there is a definition that relies on the same flag

#ifdef ARDUINO_NANO_RP2040_CONNECT

// NINA updates

SerialPIO Serial3(SERIAL3_TX, SERIAL3_RX);

#endif

I don’t really know what this is doing, but then I tried adding a new build flag replacing SERIAL3_TX and SERIAL3_RX with pin numbers as

-D SERIAL3_TX 16
-D SERIAL3_RX 17

and then I get an even weirder error

*** [.pio\build\picow\firmware.elf] Implicit dependency C:\Users\------------ \.platformio\platforms\raspberrypi@src-ff76a3915224135aafad379817f41edd\builder\16' not found, needed by target .pio\build\picow\firmware.elf’.

Has anyone ever seen this issue before? I’d appreciate any help

Thanks!

I also tried changing the flag while removing the definition for the serial pins

-D ARDUINO_NANO_RP2040_PICO

And also in the encoder, as

#elif defined(ARDUINO_NANO_RP2040_PICO)
#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_INT4_PIN 4
#define CORE_INT5_PIN 5
#define CORE_INT6_PIN 6
#define CORE_INT7_PIN 7
#define CORE_INT8_PIN 8
#define CORE_INT9_PIN 9
#define CORE_INT10_PIN 10
#define CORE_INT11_PIN 11
#define CORE_INT12_PIN 12
#define CORE_INT13_PIN 13
#define CORE_INT14_PIN 14
#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
// #define CORE_INT20_PIN A6
// #define CORE_INT21_PIN A7

But then I get this error

In file included from .pio\libdeps\picow\Encoder\Encoder.cpp:2:
.pio\libdeps\picow\Encoder\Encoder.h:68:11: error: ‘IO_REG_TYPE’ does not name a type; did you mean ‘IP_GET_TYPE’?
68 | volatile IO_REG_TYPE * pin1_register;
| ^~~~~~~~~~~
| IP_GET_TYPE
.pio\libdeps\picow\Encoder\Encoder.h:69:11: error: ‘IO_REG_TYPE’ does not name a type; did you mean ‘IP_GET_TYPE’?
69 | volatile IO_REG_TYPE * pin2_register;
| ^~~~~~~~~~~
| IP_GET_TYPE

The struct where the IO_REG_TYPE thingy is is here:

// All the data needed by interrupts is consolidated into this ugly struct
// to facilitate assembly language optimizing of the speed critical update.
// The assembly code uses auto-incrementing addressing modes, so the struct
// must remain in exactly this order.
typedef struct {
volatile IO_REG_TYPE * pin1_register;
volatile IO_REG_TYPE * pin2_register;
IO_REG_TYPE pin1_bitmask;
IO_REG_TYPE pin2_bitmask;
uint8_t state;
int32_t position;
} Encoder_internal_state_t;

The pin defs are only activated on

That worked, Thanks!