User Tools

Site Tools


roborio_digital_io

This is an old revision of the document!


Table of Contents

On this page we'll describe the 10 “DIO” Digital I/O connections on the RoboRIO.

Introduction

By “digital” or “binary” we mean that each connector can convey a piece of information that is in one of two conditions. There are several ways of saying this:

  • on / off
  • one / zero
  • Positive voltage / zero volts

When acting as an input, the RoboRIO interprets any voltage between 0 and 0.8v

By “IO” we mean that the direction can be either:

  • Input: from an external switch or sensor to the RoboRIO
  • Output: from the RoboRIO to an external light or other device

The direction is controlled by the software that runs on the roborio (see below).

Each “DIO” consists of a header with 3 pins. Typically, we connect a 3-wire “PWM” cable to each header.

  • Ground (black)
  • +5v power (red)
  • Signal (white)

The interesting pin is the “signal” pin. When configured as an output, the signal pin is driven to 0 volts for a “zero”, and 3.3 volts for a “one”. More on outputs later.

When acting as an input, the RoboRIO interprets any voltage between 0 and 0.8v ad a “zero”, and a voltage between 2.0v and 5.5v as a “one.” A voltage in between those ranges results in either a zero or a one being delivered to the software program.

There is a “pullup” or “pulldown” resistor internal to the RoboRIO that helps ensure that the voltage on a disconnected DIO does not drift into that “unknown” region. For the ten basic DIOs on the RoboRIO, it is a pullup, so an unconnected DIO will be read by software as a “one”.

To cause a DIO to be read as “zero” by software, all we have to do is connect the signal pin to ground, for example with a switch.

[picture needed]

Software

Here's a Java code fragment:

 package edu.wpi.first.wpilib.templates;
 
 import edu.wpi.first.wpilib.DigitalInput;
 import edu.wpi.first.wpilib.SimpleRobot;
 import edu.wpi.first.wpilib.Timer;
 
 public class RobotTemplate extends SimpleRobot {
 
 	DigitalInput mySwitch;
 
 	public void robotInit() {
 		mySwitch = new DigitalInput(1);
 	}
 
 	public void operatorControl() {
 		// more code here	
 		switch_now = mySwitch.get();
 		if(switch_now) {
 			// do somthing if the switch is open ("one");
 		} else {
 			// do somthing else if the switch is closed ("zero");
 		}
 		// more code here	
 	}
 }

Notice somthing there that is true of most simple test programs: there's a whole lot more “java stuff” then there is specifics about what we're trying to do. There are really only two interesting lines. The first one is:

  mySwitch = new DigitalInput(1);

This creates an object which represents our DIO pin in software. The “1” in DigitalInput(1), means that its associtated with DIO number 1.

The other interesting line is:

  switch_now = mySwitch.get();

which reads the current state of the DIO and stores it in a boolean variable called switch_now. We can then use switch_now in an if() or other statements.

There's some more software discussion here: * https://wpilib.screenstepslive.com/s/3120/m/7912/l/599687-using-limit-switches-to-control-behavior

Conclusion

This discussion also applies to the 16 additional DIO pins located on the roborio expansion connector.

roborio_digital_io.1516911188.txt.gz · Last modified: 2018/01/25 15:13 by tell