RedBot Sensor - Wheel Encoder
This Tutorial is Retired!
This tutorial covers concepts or technologies that are no longer current. It's still here for you to read and enjoy, but may not be as useful as our newest tutorials.
To help you make getting your robot moving as easy as possible, we've written an Arduino Library, which can be downloaded here. Here's a walk-through of the commands that the library provides. If you need a refresher on how to install an Arduino library, please see our library tutorial.
The Arduino library linked above includes example code.
The Encoder board is supported by the library to allow the program to tally encoder ticks in the background, without requiring the user's attention. Of course, the user must still check the count periodically to determine whether or not some action is required, but this requires less processor overhead than constantly monitoring for a pin state change.
RedBotEncoder(int lPin, int rPin);
The class constructor accepts two parameters: the pin numbers to be assigned to the left and right wheels. Most of the pins on the RedBot board may be used for this purpose; pins A6 and A7 cannot be, however, as they are analog-only inputs and this signal is inherently digital.
void clearEnc(WHEEL wheel);
clearEnc() clears the odometer of a given wheel. It accepts as a parameter either
BOTH, with the obvious meaning.
long getTicks(WHEEL wheel);
getTicks() returns the number of counts currently recorded for the given wheel. Note that, unlike for
BOTH is not a valid input, since only one value can be returned at a time.