Connecting an encoder

From ROBOTC API Guide
< Tutorials‎ | Arduino Projects/Mobile Robotics/BoeBot
Revision as of 14:38, 17 October 2012 by Jwatson (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Wiring

Diagram of encoder connections.

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.

Parts required.

First, we will connect the ground wires. They will be plugged directly into the ground (GND) ports.

Virtual ground wires connected
Ground wires connected

Next, Plug in the signal wires. They will plugged into separate buses on the breadboard.

Virtual signal wires connected
Signal wires connected

Now connect the 5V wires. They will plug directly into the +5 volt ports.

Virtual 5V wires connected
5V wires connected

Now connect the resistors. They will go between the +5 volt ports and the same buses as the yellow signal wires.

Virtual resistors added
Resistors added

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.

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"

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.