Compilation Error in Encoder Library

I am trying to use a rotary encoder to adjust a number on a display. The rotary encoder I am using is a Bourns PEC11H-4220F-S0024 Quadrature Rotary Encoder, and the display is a TM1637 7-Segment 4-Digit Display.

When trying to compile any program using the Encoder library, (including examples provided with the library), I get the following errors.

In file included from C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202515-25908-1hzpyo3.3j73\sketch_feb5a\sketch_feb5a.ino:5:0:
c:\Users\user\Documents\libraries\Encoder/Encoder.h:68:11: error: 'IO_REG_TYPE' does not name a type
  volatile IO_REG_TYPE * pin1_register;
           ^~~~~~~~~~~
c:\Users\user\Documents\libraries\Encoder/Encoder.h:69:11: error: 'IO_REG_TYPE' does not name a type
  volatile IO_REG_TYPE * pin2_register;
           ^~~~~~~~~~~
c:\Users\user\Documents\libraries\Encoder/Encoder.h:70:2: error: 'IO_REG_TYPE' does not name a type
  IO_REG_TYPE            pin1_bitmask;
  ^~~~~~~~~~~
c:\Users\user\Documents\libraries\Encoder/Encoder.h:71:2: error: 'IO_REG_TYPE' does not name a type
  IO_REG_TYPE            pin2_bitmask;
  ^~~~~~~~~~~
c:\Users\user\Documents\libraries\Encoder/Encoder.h: In constructor 'Encoder::Encoder(uint8_t, uint8_t)':
c:\Users\user\Documents\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);
           ^~~~~~~~~~~~~
c:\Users\user\Documents\libraries\Encoder/Encoder.h:89:27: error: 'PIN_TO_BASEREG' was not declared in this scope
   encoder.pin1_register = PIN_TO_BASEREG(pin1);
                           ^~~~~~~~~~~~~~
c:\Users\user\Documents\libraries\Encoder/Encoder.h:89:27: note: suggested alternative: 'ITM_BASE'
   encoder.pin1_register = PIN_TO_BASEREG(pin1);
                           ^~~~~~~~~~~~~~
                           ITM_BASE
c:\Users\user\Documents\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);
           ^~~~~~~~~~~~
c:\Users\user\Documents\libraries\Encoder/Encoder.h:90:26: error: 'PIN_TO_BITMASK' was not declared in this scope
   encoder.pin1_bitmask = PIN_TO_BITMASK(pin1);
                          ^~~~~~~~~~~~~~
c:\Users\user\Documents\libraries\Encoder/Encoder.h:90:26: note: suggested alternative: 'PIN_USE_MASK'
   encoder.pin1_bitmask = PIN_TO_BITMASK(pin1);
                          ^~~~~~~~~~~~~~
                          PIN_USE_MASK
c:\Users\user\Documents\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);
           ^~~~~~~~~~~~~
c:\Users\user\Documents\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);
           ^~~~~~~~~~~~
c:\Users\user\Documents\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;
                               ^~~~~~~~~~~~~
c:\Users\user\Documents\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;
                                                      ^~~~~~~~~~~~
c:\Users\user\Documents\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;
       ^~~~~~~~~~~~~~~
c:\Users\user\Documents\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;
                               ^~~~~~~~~~~~~
c:\Users\user\Documents\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;
                                                      ^~~~~~~~~~~~
c:\Users\user\Documents\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;
       ^~~~~~~~~~~~~~~
c:\Users\user\Documents\libraries\Encoder/Encoder.h: In static member function 'static void Encoder::update(Encoder_internal_state_t*)':
c:\Users\user\Documents\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);
                                        ^~~~~~~~~~~~~
c:\Users\user\Documents\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);
                                                            ^~~~~~~~~~~~
c:\Users\user\Documents\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);
                   ^~~~~~~~~~~~~~~
c:\Users\user\Documents\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);
                                        ^~~~~~~~~~~~~
c:\Users\user\Documents\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);
                                                            ^~~~~~~~~~~~

exit status 1

Compilation error: exit status 1

The code I compiled to get these errors is the following:

#include <Arduino.h>
#include <TM1637Display.h>

#define ENCODER_DO_NOT_USE_INTERRUPTS
#include <Encoder.h>

int encodeA = 5;
int encodeB = 6;
int numLock = 4;
int lastStateCLK;
int currentStateCLK; 
int dispCLK = 3;
int dispDIO = 2;
int servoNum = 1;

TM1637Display display(dispCLK, dispDIO);

Encoder myEnc(5, 6);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(200);

  pinMode(encodeA, INPUT_PULLUP);
	pinMode(encodeB, INPUT_PULLUP);
  pinMode(numLock, INPUT_PULLUP);

  lastStateCLK = myEnc.read();

  Serial.println("Initial Encoder State Read");

  display.setBrightness(5); // Sets the brightness level to 5
  uint8_t data[] = {0xff, 0xff, 0xff, 0xff}; // Turns on the display

  Serial.println("Display On");
}

void loop() {
  // put your main code here, to run repeatedly:
  currentStateCLK = myEnc.read();
  if (currentStateCLK > lastStateCLK) {
    servoNum ++;
  }
  else if (currentStateCLK < lastStateCLK && currentStateCLK != 0) {
    servoNum --;
  }

  if (currentStateCLK != lastStateCLK) {
    lastStateCLK = currentStateCLK;
  }

  display.showNumberDec(servoNum, true);

  Serial.println(servoNum);
}

I am fairly amateur with Arduino and programming so any help is appreciated.

I see that some fairly crucial information has been omitted and that it's 20 questions time, so I'll start off:

What board are you compiling for?

Which Encoder library are you using?

2 Likes

Here your code complile.

Ask two straightforward questions, and... radio silence. I guess the OP didn't really want help after all.

@van_der_decken

Consider that people might post a question just before going to bed or work and will only check for replies the next day or after work.

Remember, netiquette states that one should let a question go around the world for 24 hours; the same applies to replies :wink:

I did consider that. I also watched as the OP composed a reply (helpful forum feature) that they never posted. I also noticed as the OP was present on the forum multiple times over the next few hours. Only then did I drop the mic.

1 Like