ELEGOO Tumbller encoder attach interrupt not working

I have the elegoo tumbller and I have downloaded the tutorial code and started from the first lesson. https://www.elegoo.com/blogs/arduino-projects/elegoo-tumbller-self-balancing-robot-car-tutorial

When I upload it as it is, nothing seems to happen and nothing is output in the serial monitor. However when I remove this line from Measuring_speed.cpp

#include "Motor.h"
#include "PinChangeInt.h"

void Motor::Encoder_init() {
  attachInterrupt(digitalPinToInterrupt(ENCODER_LEFT_A_PIN), EncoderCountLeftA, CHANGE);
  // attachPinChangeInterrupt(ENCODER_RIGHT_A_PIN, EncoderCountRightA, CHANGE); // <-- this line
}
...

Then stuff starts to happen, wheels turn and there is output in the serial monitor. However (as expected) there are no values for the encoder on the right motor.

My output:

Right:encoder_count_right_a:0
Right:encoder_count_left_a:36
Forward:encoder_count_right_a:0
Forward:encoder_count_left_a:1148
Back:encoder_count_right_a:0
Back:encoder_count_left_a:1128

Example output from elegoo

From a bit of digging I think it maybe something to do with the arduino nano only having interrupt on pin 2 and 3 so they had to use some library to deal with the right encoder on pin 4.

How can I get the encoder to work?

They are using the pinChange-Interrupt which can be used on more IO-pins than just 2 and 3
anyway If you have all parts from the kit and the demo-code does not work
send an email-request to elegoo with a detailed descriptionhow you setup everything and what results you get.

best regards Stefan

1 Like

If you don't configure the interrupt for the ENCODER_RIGHT_A_PIN it makes sense that you would get no action from the Right encoder.

If your sketch freezes when you enable the ENCODER_RIGHT_A_PIN interrupt, I would update or re-install the PinChangeInt library.

I have the same problem - even the Interrupt for Using the key on the board does not work. The PinChangeInt.h library seems to be very old. How to get a current version. Did you get the problem solved somehow? All in all I would be happy to get some information on programming the robot oneself - a little tutorial or other input.

Ich habe jetzt eine Lösung gefunden, in dem ich die PinChangeInt-Library durch eine neue Version ersetzt habe: GitHub - NicoHood/PinChangeInterrupt: A simple & compact PinChangeInterrupt library for Arduino (Diese kann man auch mit der Bibliotheksverwaltung der IDE installieren. Dann in Tumbller.ino folgendes ändern

//#include "PinChangeInt.h"
#include "PinChangeInterrupt.h"

und an allen Stellen an denen die Funktion attachPinChangeInterrupt auftaucht diese ersetzen:

  //attachPinChangeInterrupt(ENCODER_RIGHT_A_PIN, encoderCountRightA, CHANGE);
  // new Version with PinChangeInterrupt Library 1.2.9
  attachPCINT(digitalPinToPCINT(ENCODER_RIGHT_A_PIN), encoderCountRightA, CHANGE);

Ich hoffe, das hilft...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.