Analog Input Pins

A general description of the analog input pins on a Texas Instruments MCU chip found on LaunchPad.

A/D converter

The TI MCUs that come on LaunchPad will have an onboard analog-to-digital (A/D) converter. The converter will have different resolutions based on the chipset. While the main function of the analog pins for most Energia users is to read analog sensors, the analog pins also have all the functionality of general purpose input/output (GPIO) pins.

Consequently, if a user needs more general purpose input output pins, and all the analog pins are not in use, the analog pins may be used for GPIO.

Sparkfun has a great tutorial on Analog to Digital conversion if you want to know more about it.

Pin mapping

The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH:

pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);

Pullup resistors

The analog pins also have pullup resistors, which work identically to pullup resistors on the digital pins. They are enabled by issuing a command such as:

digitalWrite(A0, HIGH);  // set pullup on analog pin 0

while the pin is an input.

Be aware however that turning on a pullup will affect the values reported by analogRead().

Details and Caveats

The analogRead command will not work correctly if a pin has been previously set to an output, so if this is the case, set it back to an input before using analogRead. Similarly if the pin has been set to HIGH as an output, the pullup resistor will be set, when switched back to an input.

Be cautious about switching analog pins in close temporal proximity to making A/D readings (analogRead) on other analog pins. This can cause electrical noise and introduce jitter in the analog system. It may be desirable, after manipulating analog pins (in digital mode), to add a short delay before using analogRead() to read other analog pins.

Guide Home