Connecting an encoder

Jump to: navigation, search


Diagram of encoder connections.

We are going to attach the encoders in the most compact way possible. This is because encoders are so useful, we might want to leave them attached while we are also using other sensors.

The parts you will need are 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.

Parts required.

First, we will connect the ground wires.

Virtual ground wires connected
Ground wires connected

Next, Plug in the signal wires.

Virtual signal wires connected
Signal wires connected

Now connect the 5V wires.

Virtual 5V wires connected
5V wires connected

Now connect the resistors.

Virtual resistors added
Resistors added

Finally connect the jumper wires.

Finished virtual breadboard
Finished breadboard

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"

Following that, 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, but we will go over that in the next lesson.