Can't initialize digital input

Anytime I try and initialize a digital input port I get the following error:

 Error at frc.robot.Robot.robotInit(Robot.java:117): Unhandled exception: edu.wpi.first.hal.util.UncleanStatusException:  Code: -1029. HAL: Resource already allocated ERROR  1  Unhandled exception: edu.wpi.first.hal.util.UncleanStatusException:  Code: -1029. HAL: Resource already allocated  frc.robot.Robot.robotInit(Robot.java:117)  CS: USB Camera 1: Connecting to USB camera on /dev/video1 

The initialization line is:
ArduinoRight = new DigitalInput(1);
The code works without this one line, but gives this error with it. Any help would be appreciated.

This error happens when you initialize a resource (DigitalInput, AnalogInput, SpeedController, etc) on the same port more than once. You must only have one instance of a resource on a given port (for example, a DigitalInput on port 1) in your code. Search in your project for all usages of DigitalInput, and you’ll likely find somewhere else where one is being made on the same port.

The other option is that the object this code resides in is being constructed more than once. You can try changing to a different DigitalInput port – or, indeed, any type of resource where this happens, examples are listed in the previous paragraph – and see if it still happens. If it happens no matter what you use, this is the case. If this only happens when you use a specific DigitalInput port, then you’re almost certainly allocating it somewhere else.

Post your full code (on GitHub or similar service) if you’re still having issues after attempting to debug this.

1 Like

This fixed the problem. thanks!