Enocder Library Errors

Hello everyone,

First time poster on any forum so please bear with me if I omit anything important.

I have an Elegoo Uno R3. I have installed this Library through Sketch->Include Library->Add Zip: PaulStoffregen / Encoder. I am on the Arduino IDE 2.0 on Arch. This is the code I am trying to run:

/* Encoder Library - Basic Example
 * http://www.pjrc.com/teensy/td_libs_Encoder.html
 *
 * This example code is in the public domain.
 */

#include <Encoder.h>

// Change these two numbers to the pins connected to your encoder.
//   Best Performance: both pins have interrupt capability
//   Good Performance: only the first pin has interrupt capability
//   Low Performance:  neither pin has interrupt capability
Encoder myEnc(2, 3);
//   avoid using pins with LEDs attached

void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");
}

long oldPosition  = -999;

void loop() {
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
}

These are the errors I am getting when I try to compile:

In file included from /home/kurt/Arduino/Basic/Basic.ino:7:0:
/home/kurt/Arduino/libraries/Encoder/Encoder.h:66:11: error: 'IO_REG_TYPE' does not name a type
  volatile IO_REG_TYPE * pin1_register;
           ^~~~~~~~~~~
/home/kurt/Arduino/libraries/Encoder/Encoder.h:67:11: error: 'IO_REG_TYPE' does not name a type
  volatile IO_REG_TYPE * pin2_register;
           ^~~~~~~~~~~
/home/kurt/Arduino/libraries/Encoder/Encoder.h:68:2: error: 'IO_REG_TYPE' does not name a type
  IO_REG_TYPE            pin1_bitmask;
  ^~~~~~~~~~~
/home/kurt/Arduino/libraries/Encoder/Encoder.h:69:2: error: 'IO_REG_TYPE' does not name a type
  IO_REG_TYPE            pin2_bitmask;
  ^~~~~~~~~~~
/home/kurt/Arduino/libraries/Encoder/Encoder.h: In member function 'void Encoder::begin(uint8_t, uint8_t)':
/home/kurt/Arduino/libraries/Encoder/Encoder.h:92:11: error: 'struct Encoder_internal_state_t' has no member named 'pin1_register'
   encoder.pin1_register = PIN_TO_BASEREG(pin1);
           ^~~~~~~~~~~~~
/home/kurt/Arduino/libraries/Encoder/Encoder.h:93:11: error: 'struct Encoder_internal_state_t' has no member named 'pin1_bitmask'
   encoder.pin1_bitmask = PIN_TO_BITMASK(pin1);
           ^~~~~~~~~~~~
/home/kurt/Arduino/libraries/Encoder/Encoder.h:94:11: error: 'struct Encoder_internal_state_t' has no member named 'pin2_register'
   encoder.pin2_register = PIN_TO_BASEREG(pin2);
           ^~~~~~~~~~~~~
/home/kurt/Arduino/libraries/Encoder/Encoder.h:95:11: error: 'struct Encoder_internal_state_t' has no member named 'pin2_bitmask'
   encoder.pin2_bitmask = PIN_TO_BITMASK(pin2);
           ^~~~~~~~~~~~
In file included from /home/kurt/Arduino/libraries/Encoder/Encoder.h:41:0,
                 from /home/kurt/Arduino/Basic/Basic.ino:7:
/home/kurt/Arduino/libraries/Encoder/Encoder.h:102: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;
                               ^
/home/kurt/Arduino/libraries/Encoder/utility/direct_pin_read.h:8:46: note: in definition of macro 'DIRECT_PIN_READ'
 #define DIRECT_PIN_READ(base, mask)     (((*(base)) & (mask)) ? 1 : 0)
                                              ^~~~
/home/kurt/Arduino/libraries/Encoder/Encoder.h:102: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;
                                                      ^
/home/kurt/Arduino/libraries/Encoder/utility/direct_pin_read.h:8:56: note: in definition of macro 'DIRECT_PIN_READ'
 #define DIRECT_PIN_READ(base, mask)     (((*(base)) & (mask)) ? 1 : 0)
                                                        ^~~~
/home/kurt/Arduino/libraries/Encoder/Encoder.h:103: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;
                               ^
/home/kurt/Arduino/libraries/Encoder/utility/direct_pin_read.h:8:46: note: in definition of macro 'DIRECT_PIN_READ'
 #define DIRECT_PIN_READ(base, mask)     (((*(base)) & (mask)) ? 1 : 0)
                                              ^~~~
/home/kurt/Arduino/libraries/Encoder/Encoder.h:103: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;
                                                      ^
/home/kurt/Arduino/libraries/Encoder/utility/direct_pin_read.h:8:56: note: in definition of macro 'DIRECT_PIN_READ'
 #define DIRECT_PIN_READ(base, mask)     (((*(base)) & (mask)) ? 1 : 0)
                                                        ^~~~
exit status 1

Compilation error: exit status 1

The project I am currently working on is trying to figure out how a TT motor with an encoder works, trying to find out how to tell if a motor is going CW or CCW and also how to tell once a full rotation of the shaft has occurred.

Welcome to the forum

Which Arduino board are you using ?

Elegoo Uno R3

Is that one of the examples from the library that you installed ?

Yes it is an example from the library I installed.

What is the exact name of the example sketch and which version of the Encoder library is installed ?

I am very suspicious of the reference to a teensy in this URL in the example

 * http://www.pjrc.com/teensy/td_libs_Encoder.html

The name of the sketch is Basic.ino

Sorry the version of the encoder library I am unsure, whatever is available from the github is the one I installed.

OK. The code compiles for me

The Encoder library is available from the Arduino IDE Library manager which is an easier way to install it than downloading and installing the .zip

I suggest that you uninstall the library and install it again using the Library Manager

Which version of the IDE are you using ?

My Arduino version is 2.3.4. I will uninstall and try through the library.

And that was the solution! Thank you very much for your help!

I am glad that it worked. The installation from the .zip file seems to have gone wrong for some reason

I am sorry for asking what might have seemed to be very basic questions, but experience here has taught me that what a poster has not said is often more important than what they have said

Good luck going forward with your project

No worries you were absolutely correct to ask those questions, its often the little things at the start of a project that are the culprit.