Connecting an encoder
|
Wiring
Because encoders are extremely useful in a variety of applications, we are going to attach them to the BoeBot as compactly as possible so they should never need to be removed.
You will need 2 10KΩ resistors and three wires. You will need to trim the resistors down, as seen in the image, so that they can fit properly.
First, we will connect the ground wires. They will be plugged directly into the ground (GND) ports.
Next, Plug in the signal wires. They will plugged into separate buses on the breadboard.
Now connect the 5V wires. They will plug directly into the +5 volt ports.
Now connect the resistors. They will go between the +5 volt ports and the same buses as the yellow signal wires.
Finally connect the jumper wires. They will connect the signal wire buses to the Arduino. The right encoder should be connected to Digital Pin 2 and the left encoder should be connected to Digital Pin 3.
ROBOTC Configuration
Not that the encoders are all wired up, we are ready to configure ROBOTC. In accordance with the diagrams, we are using digital pin 2 for the right encoder, and digital pin 3 for the left encoder. Therefore, we need to configure dgtl2 as Digital In and name it rightEncoder, and configure dgtl3 also as Digital in and name it leftEncoder.
- Parallax Boe Shield
- digital pin 2 as a Digital High Impedance named "rightEncoder"
- digital pin 3 as a Digital High Impedance named "leftEncoder"
- servo_10 as a Continuous Rotation Servo named "leftServo"
- servo_11 as a reversed Continuous Rotation Servo named "rightServo"
Your configuration code should look like this:
#pragma config(CircuitBoardType, typeCktBoardUNO) #pragma config(PluginCircuitBoard, typeShieldParallaxBoeBot) #pragma config(UART_Usage, UART0, uartSystemCommPort, baudRate200000, IOPins, dgtl1, dgtl0) #pragma config(Sensor, dgtl2, rightEncoder, sensorDigitalHighImpedance) #pragma config(Sensor, dgtl3, leftEncoder, sensorDigitalHighImpedance) #pragma config(Motor, servo_10, leftServo, tmotorServoContinuousRotation, openLoop, IOPins, dgtl10, None) #pragma config(Motor, servo_11, rightServo, tmotorServoContinuousRotation, openLoop, reversed, IOPins, dgtl11, None) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// |
We are configuring these as 'digital in' as there is no configuration option in ROBOTC for a non-quadrature encoder. This means we will have to add up the encoder ticks manually.